(char: string)
| 207 | const MIN_SLUG_BYTES = 32; |
| 208 | |
| 209 | function codePointBytes(char: string) { |
| 210 | const codePoint = char.codePointAt(0) as number; |
| 211 | if (codePoint < 0x80) return 1; |
| 212 | if (codePoint < 0x800) return 2; |
| 213 | if (codePoint < 0x10000) return 3; |
| 214 | return 4; |
| 215 | } |
| 216 | |
| 217 | export function utf8ByteLength(str: string) { |
| 218 | return Array.from(str).reduce((total, char) => total + codePointBytes(char), 0); |
no outgoing calls
no test coverage detected