Urara-Blog/node_modules/.pnpm-store/v3/files/9a/cd307d9f81b95a4e5f541ab1d753d9de0c3807053ef2ff6987c4c9ac409b289e446fd0a52fc694ac932acbafe8acd3734b67fd14479525d1d65df8d96a7c28
2022-08-14 01:14:53 +08:00

20 lines
629 B
Text

// https://mathiasbynens.be/notes/javascript-encoding
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
export default function ucs2length(str: string): number {
const len = str.length
let length = 0
let pos = 0
let value: number
while (pos < len) {
length++
value = str.charCodeAt(pos++)
if (value >= 0xd800 && value <= 0xdbff && pos < len) {
// high surrogate, and there is a next character
value = str.charCodeAt(pos)
if ((value & 0xfc00) === 0xdc00) pos++ // low surrogate
}
}
return length
}
ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default'