| 1 | "use strict"
|
|---|
| 2 |
|
|---|
| 3 | // Based on: https://github.com/lodash/lodash/blob/6018350ac10d5ce6a5b7db625140b82aeab804df/.internal/unicodeSize.js
|
|---|
| 4 |
|
|---|
| 5 | module.exports = () => {
|
|---|
| 6 | // Used to compose unicode character classes.
|
|---|
| 7 | const astralRange = "\\ud800-\\udfff"
|
|---|
| 8 | const comboMarksRange = "\\u0300-\\u036f"
|
|---|
| 9 | const comboHalfMarksRange = "\\ufe20-\\ufe2f"
|
|---|
| 10 | const comboSymbolsRange = "\\u20d0-\\u20ff"
|
|---|
| 11 | const comboMarksExtendedRange = "\\u1ab0-\\u1aff"
|
|---|
| 12 | const comboMarksSupplementRange = "\\u1dc0-\\u1dff"
|
|---|
| 13 | const comboRange = comboMarksRange + comboHalfMarksRange + comboSymbolsRange + comboMarksExtendedRange + comboMarksSupplementRange
|
|---|
| 14 | const varRange = "\\ufe0e\\ufe0f"
|
|---|
| 15 | const familyRange = "\\uD83D\\uDC69\\uD83C\\uDFFB\\u200D\\uD83C\\uDF93"
|
|---|
| 16 |
|
|---|
| 17 | // Used to compose unicode capture groups.
|
|---|
| 18 | const astral = `[${astralRange}]`
|
|---|
| 19 | const combo = `[${comboRange}]`
|
|---|
| 20 | const fitz = "\\ud83c[\\udffb-\\udfff]"
|
|---|
| 21 | const modifier = `(?:${combo}|${fitz})`
|
|---|
| 22 | const nonAstral = `[^${astralRange}]`
|
|---|
| 23 | const regional = "(?:\\uD83C[\\uDDE6-\\uDDFF]){2}"
|
|---|
| 24 | const surrogatePair = "[\\ud800-\\udbff][\\udc00-\\udfff]"
|
|---|
| 25 | const zwj = "\\u200d"
|
|---|
| 26 | const blackFlag = "(?:\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40(?:\\udc65|\\udc73|\\udc77)\\udb40(?:\\udc6e|\\udc63|\\udc6c)\\udb40(?:\\udc67|\\udc74|\\udc73)\\udb40\\udc7f)"
|
|---|
| 27 | const family = `[${familyRange}]`
|
|---|
| 28 |
|
|---|
| 29 | // Used to compose unicode regexes.
|
|---|
| 30 | const optModifier = `${modifier}?`
|
|---|
| 31 | const optVar = `[${varRange}]?`
|
|---|
| 32 | const optJoin = `(?:${zwj}(?:${[nonAstral, regional, surrogatePair].join("|")})${optVar + optModifier})*`
|
|---|
| 33 | const seq = optVar + optModifier + optJoin
|
|---|
| 34 | const nonAstralCombo = `${nonAstral}${combo}?`
|
|---|
| 35 | const symbol = `(?:${[nonAstralCombo, combo, regional, surrogatePair, astral, family].join("|")})`
|
|---|
| 36 |
|
|---|
| 37 | // Used to match [String symbols](https://mathiasbynens.be/notes/javascript-unicode).
|
|---|
| 38 | return new RegExp(`${blackFlag}|${fitz}(?=${fitz})|${symbol + seq}`, "g")
|
|---|
| 39 | }
|
|---|