MCPcopy Index your code
hub / github.com/nodejs/node / getEncoding

Function getEncoding

lib/internal/encoding/single-byte.js:86–100  ·  view source on GitHub ↗
(encoding)

Source from the content-addressed store, hash-verified

84const l256 = { __proto__: null, length: 256 };
85
86function getEncoding(encoding) {
87 if (encoding === 'x-user-defined') {
88 // https://encoding.spec.whatwg.org/#x-user-defined-decoder, 14.5.1. x-user-defined decoder
89 return TypedArrayFrom(Uint16Array, l256, (_, i) => (i >= 0x80 ? 0xf700 + i : i));
90 }
91
92 if (!ObjectPrototypeHasOwnProperty(encodings, encoding)) {
93 throw new ERR_ENCODING_NOT_SUPPORTED(encoding);
94 }
95
96 const map = TypedArrayFrom(Uint16Array, l256, (_, i) => i); // Unicode subset
97 let prev = 127;
98 map.set(TypedArrayFrom(Uint16Array, it(encodings[encoding]), (x) => (x === r ? x : (prev += x))), 128);
99 return map;
100}
101
102const supported = new SafeSet(it(ObjectKeys(encodings))).add('iso-8859-8-i').add('x-user-defined');
103const isSinglebyteEncoding = (enc) => supported.has(enc);

Callers 1

createSinglebyteDecoderFunction · 0.85

Calls 2

itFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…