* @param {string} encoding The encoding to decode into * @param {object} [options] Decoding options * @param {boolean=} options.fatal Whether to throw or substitute when invalid characters are encountered * @param {boolean=} options.ignoreBOM Whether to ignore the byte order for UTF-8
(encoding = 'utf-8', options = {})
| 36 | * @param {boolean=} options.ignoreBOM Whether to ignore the byte order for UTF-8 arrays |
| 37 | */ |
| 38 | constructor(encoding = 'utf-8', options = {}) { |
| 39 | const {fatal = false, ignoreBOM = false} = options; |
| 40 | |
| 41 | const encodingDefinition = getEncodingFromLabel(`${encoding}`); |
| 42 | |
| 43 | if (!encodingDefinition) |
| 44 | throw new RangeError(`Invalid encoding label: '${encoding}'`); |
| 45 | |
| 46 | if (encodingDefinition.label === 'replacement') { |
| 47 | throw new RangeError( |
| 48 | `Unsupported replacement encoding: '${encoding}'` |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | Object.defineProperty(this, '_internalEncoding', { |
| 53 | value: encodingDefinition.internalLabel, |
| 54 | enumerable: false, |
| 55 | writable: false, |
| 56 | configurable: false, |
| 57 | }); |
| 58 | |
| 59 | Object.defineProperty(this, 'encoding', { |
| 60 | value: encodingDefinition.label, |
| 61 | enumerable: true, |
| 62 | writable: false, |
| 63 | configurable: false, |
| 64 | }); |
| 65 | |
| 66 | Object.defineProperty(this, 'ignoreBOM', { |
| 67 | value: Boolean(ignoreBOM), |
| 68 | enumerable: true, |
| 69 | writable: false, |
| 70 | configurable: false, |
| 71 | }); |
| 72 | |
| 73 | Object.defineProperty(this, 'fatal', { |
| 74 | value: Boolean(fatal), |
| 75 | enumerable: true, |
| 76 | writable: false, |
| 77 | configurable: false, |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @param {unknown} bytes a typed array of bytes to decode |
nothing calls this directly
no test coverage detected