char-regex
Advanced tools
Comparing version 1.0.2 to 2.0.0
/** | ||
* A regex to match any full character, considering weird character ranges. | ||
* @example | ||
* ``` | ||
* const charRegex = require("char-regex"); | ||
* | ||
* "❤️👊🏽".match(charRegex()); | ||
* //=> ["❤️", "👊🏽"] | ||
* ``` | ||
@returns A regex to match any full character, considering weird character ranges. | ||
@example | ||
``` | ||
import charRegex from "char-regex" | ||
"❤️👊🏽".match(charRegex()) | ||
//=> ["❤️", "👊🏽"] | ||
``` | ||
*/ | ||
declare function charRegex(): RegExp | ||
export = charRegex | ||
export default function charRegex(): RegExp |
20
index.js
@@ -1,6 +0,4 @@ | ||
"use strict" | ||
// Based on https://github.com/lodash/lodash/blob/6018350ac10d5ce6a5b7db625140b82aeab804df/.internal/unicodeSize.js | ||
// Based on: https://github.com/lodash/lodash/blob/6018350ac10d5ce6a5b7db625140b82aeab804df/.internal/unicodeSize.js | ||
module.exports = () => { | ||
export default function charRegex() { | ||
// Used to compose unicode character classes. | ||
@@ -15,3 +13,2 @@ const astralRange = "\\ud800-\\udfff" | ||
const varRange = "\\ufe0e\\ufe0f" | ||
const familyRange = "\\uD83D\\uDC69\\uD83C\\uDFFB\\u200D\\uD83C\\uDF93" | ||
@@ -24,7 +21,6 @@ // Used to compose unicode capture groups. | ||
const nonAstral = `[^${astralRange}]` | ||
const regional = "(?:\\uD83C[\\uDDE6-\\uDDFF]){2}" | ||
const regional = "(?:\\ud83c[\\udde6-\\uddff]){2}" | ||
const surrogatePair = "[\\ud800-\\udbff][\\udc00-\\udfff]" | ||
const zwj = "\\u200d" | ||
const zeroWidthJoiner = "\\u200d" | ||
const blackFlag = "(?:\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40(?:\\udc65|\\udc73|\\udc77)\\udb40(?:\\udc6e|\\udc63|\\udc6c)\\udb40(?:\\udc67|\\udc74|\\udc73)\\udb40\\udc7f)" | ||
const family = `[${familyRange}]` | ||
@@ -34,9 +30,9 @@ // Used to compose unicode regexes. | ||
const optVar = `[${varRange}]?` | ||
const optJoin = `(?:${zwj}(?:${[nonAstral, regional, surrogatePair].join("|")})${optVar + optModifier})*` | ||
const optJoin = `(?:${zeroWidthJoiner}(?:${[nonAstral, regional, surrogatePair].join("|")})${optVar + optModifier})*` | ||
const seq = optVar + optModifier + optJoin | ||
const nonAstralCombo = `${nonAstral}${combo}?` | ||
const symbol = `(?:${[nonAstralCombo, combo, regional, surrogatePair, astral, family].join("|")})` | ||
const symbol = `(?:${[blackFlag, nonAstralCombo, combo, regional, surrogatePair, astral].join("|")})` | ||
// Used to match [String symbols](https://mathiasbynens.be/notes/javascript-unicode). | ||
return new RegExp(`${blackFlag}|${fitz}(?=${fitz})|${symbol + seq}`, "g") | ||
// Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). | ||
return new RegExp(`${fitz}(?=${fitz})|${symbol + seq}`, "g") | ||
} |
{ | ||
"name": "char-regex", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"type": "module", | ||
"description": "A regex to match any full character, considering weird character ranges.", | ||
@@ -8,3 +9,3 @@ "repository": "https://github.com/Richienb/char-regex.git", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -15,7 +16,7 @@ "index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12.20" | ||
}, | ||
"scripts": { | ||
"lint": "xo", | ||
"test": "yarn lint && ava" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -31,17 +32,11 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.8.4", | ||
"@babel/plugin-proposal-unicode-property-regex": "^7.8.3", | ||
"array-uniq": "^2.1.0", | ||
"ava": "^3.0.0", | ||
"emoji.json": "^12.1.1", | ||
"eslint-config-richienb": "^0.3.0", | ||
"unicode-chars": "^1.0.1", | ||
"xo": "^0.25.3" | ||
"all-chars": "^1.0.0", | ||
"ava": "^3.15.0", | ||
"eslint-config-richienb": "^0.6.2", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.40.2" | ||
}, | ||
"resolutions": { | ||
"eslint": "^6.8.0" | ||
}, | ||
"xo": { | ||
"extends": "richienb/node" | ||
"extends": "richienb" | ||
} | ||
} |
5
32
Yes
4507
41