mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-30 23:17:48 +00:00
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
/** Used to compose unicode character classes. */
|
|
const rsAstralRange = '\\ud800-\\udfff';
|
|
const rsComboMarksRange = '\\u0300-\\u036f';
|
|
const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
|
|
const rsComboSymbolsRange = '\\u20d0-\\u20ff';
|
|
const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
|
|
const rsVarRange = '\\ufe0e\\ufe0f';
|
|
|
|
/** Used to compose unicode capture groups. */
|
|
const rsAstral = `[${ rsAstralRange }]`;
|
|
const rsCombo = `[${ rsComboRange }]`;
|
|
const rsFitz = '\\ud83c[\\udffb-\\udfff]';
|
|
const rsModifier = `(?:${ rsCombo }|${ rsFitz })`;
|
|
const rsNonAstral = `[^${ rsAstralRange }]`;
|
|
const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
|
|
const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
|
|
const rsZWJ = '\\u200d';
|
|
|
|
/** Used to compose unicode regexes. */
|
|
const reOptMod = `${ rsModifier }?`;
|
|
const rsOptVar = `[${ rsVarRange }]?`;
|
|
const rsOptJoin = `(?:${ rsZWJ }(?:${ [rsNonAstral, rsRegional, rsSurrPair].join('|') })${ rsOptVar + reOptMod })*`;
|
|
const rsSeq = rsOptVar + reOptMod + rsOptJoin;
|
|
const rsSymbol = `(?:${ [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') })`;
|
|
|
|
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
|
const reUnicode = RegExp(`${ rsFitz }(?=${ rsFitz })|${ rsSymbol + rsSeq }`, 'g');
|
|
|
|
/**
|
|
* Gets the size of a Unicode `string`.
|
|
*
|
|
* @private
|
|
* @param {string} string The string inspect.
|
|
* @returns {number} Returns the string size.
|
|
*/
|
|
function unicodeSize(string) {
|
|
let result = reUnicode.lastIndex = 0;
|
|
while (reUnicode.test(string)) {
|
|
++result;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export default unicodeSize;
|