This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function utf16slice(str, start, end) { | |
| // UTF-16 code units - same as native | |
| return str.slice(start, end); | |
| } | |
| function utf8slice(str, start, end) { | |
| // UTF-8 bytes; slicing mid-codepoint yields U+FFFD | |
| const bytes = new TextEncoder().encode(str); | |
| return new TextDecoder().decode(bytes.slice(start, end)); | |
| } |
OlderNewer