MCPcopy Create free account
hub / github.com/editablejs/editable / codePointAt

Function codePointAt

packages/breaker/src/index.ts:33–55  ·  view source on GitHub ↗
(str: string, idx: number)

Source from the content-addressed store, hash-verified

31const classTrie = new UnicodeTrie(data);
32
33const codePointAt = (str: string, idx: number) => {
34 // different from String#codePointAt with low surrogate
35 const code = str.charCodeAt(idx);
36 // High surrogate
37 if (0xd800 <= code && code <= 0xdbff) {
38 const hi = code;
39 const low = str.charCodeAt(idx + 1);
40 if (0xdc00 <= low && low <= 0xdfff) {
41 return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
42 }
43 return hi;
44 }
45 // Low surrogate
46 if (0xdc00 <= code && code <= 0xdfff) {
47 const hi = str.charCodeAt(idx - 1);
48 const low = code;
49 if (0xd800 <= hi && hi <= 0xdbff) {
50 return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
51 }
52 return low;
53 }
54 return code;
55};
56
57const isSurrogate = (str: string, pos: number) => {
58 let ref, ref1;

Callers 1

previousBreakFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…