(ch)
| 2 | // It is CJK-aware and surrogate-pair safe for simple emojis, but full terminal |
| 3 | // wcwidth compliance and ZWJ grapheme clusters are intentionally out of scope. |
| 4 | function visualWidth(ch) { |
| 5 | const cp = ch.codePointAt(0); |
| 6 | if (!cp) return 0; |
| 7 | if (cp >= 0x1100 && ( |
| 8 | cp <= 0x115F || // Hangul Jamo |
| 9 | (cp >= 0x2E80 && cp <= 0xA4CF) || // CJK Radicals, Kangxi, Ideographic Description, CJK Symbols, Hiragana, Katakana, Bopomofo, etc. |
| 10 | (cp >= 0xA960 && cp <= 0xA97C) || // Hangul Jamo Extended-A |
| 11 | (cp >= 0xAC00 && cp <= 0xD7AF) || // Hangul Syllables |
| 12 | (cp >= 0xF900 && cp <= 0xFAFF) || // CJK Compatibility Ideographs |
| 13 | (cp >= 0xFE10 && cp <= 0xFE19) || // Vertical Forms |
| 14 | (cp >= 0xFE30 && cp <= 0xFE6F) || // CJK Compatibility Forms |
| 15 | (cp >= 0xFF01 && cp <= 0xFF60) || // Fullwidth Forms |
| 16 | (cp >= 0xFFE0 && cp <= 0xFFE6) || // Fullwidth Signs |
| 17 | (cp >= 0x20000 && cp <= 0x2FFFF) || // CJK Unified Ideographs Extension B-F |
| 18 | (cp >= 0x30000 && cp <= 0x3FFFF) // CJK Unified Ideographs Extension G-H |
| 19 | )) return 2; |
| 20 | return 1; |
| 21 | } |
| 22 | |
| 23 | function visualLength(str) { |
| 24 | let len = 0; |
no outgoing calls
no test coverage detected