fast-string-truncated-width
Advanced tools
+9
-9
@@ -6,3 +6,3 @@ /* IMPORT */ | ||
| const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y; | ||
| const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu; | ||
| const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}])/yu; | ||
| const TAB_RE = /\t{1,1000}/y; | ||
@@ -27,8 +27,8 @@ const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu; | ||
| const PARSE_BLOCKS = [ | ||
| [LATIN_RE, REGULAR_WIDTH], | ||
| [ANSI_RE, ANSI_WIDTH], | ||
| [CONTROL_RE, CONTROL_WIDTH], | ||
| [TAB_RE, TAB_WIDTH], | ||
| [EMOJI_RE, EMOJI_WIDTH], | ||
| [CJKT_WIDE_RE, WIDE_WIDTH] | ||
| [LATIN_RE, REGULAR_WIDTH, false], | ||
| [ANSI_RE, ANSI_WIDTH, false], | ||
| [CONTROL_RE, CONTROL_WIDTH, false], | ||
| [TAB_RE, TAB_WIDTH, false], | ||
| [EMOJI_RE, EMOJI_WIDTH, true], | ||
| [CJKT_WIDE_RE, WIDE_WIDTH, true] | ||
| ]; | ||
@@ -82,6 +82,6 @@ /* STATE */ | ||
| for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) { | ||
| const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i]; | ||
| const [BLOCK_RE, BLOCK_WIDTH, BLOCK_IS_SINGULAR] = PARSE_BLOCKS[i]; | ||
| BLOCK_RE.lastIndex = index; | ||
| if (BLOCK_RE.test(input)) { | ||
| lengthExtra = BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index; | ||
| lengthExtra = BLOCK_IS_SINGULAR ? 1 : BLOCK_RE.lastIndex - index; | ||
| widthExtra = lengthExtra * BLOCK_WIDTH; | ||
@@ -88,0 +88,0 @@ if ((width + widthExtra) > truncationLimit) { |
+1
-1
@@ -6,3 +6,3 @@ { | ||
| "license": "MIT", | ||
| "version": "3.0.1", | ||
| "version": "3.0.2", | ||
| "type": "module", | ||
@@ -9,0 +9,0 @@ "main": "dist/index.js", |
11615
0.41%