MCPcopy Create free account
hub / github.com/decaporg/decap-cms / codePointBytes

Function codePointBytes

packages/decap-cms-core/src/lib/formatters.ts:209–215  ·  view source on GitHub ↗
(char: string)

Source from the content-addressed store, hash-verified

207const MIN_SLUG_BYTES = 32;
208
209function 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
217export function utf8ByteLength(str: string) {
218 return Array.from(str).reduce((total, char) => total + codePointBytes(char), 0);

Callers 2

utf8ByteLengthFunction · 0.85
truncateSlugFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected