diff --git a/text.js b/text.js index 5ba1053..28df59c 100644 --- a/text.js +++ b/text.js @@ -28,15 +28,15 @@ if (scope['TextEncoder'] && scope['TextDecoder']) { return false; } +// used for FastTextDecoder +const validUtfLabels = ['utf-8', 'utf8', 'unicode-1-1-utf-8']; + /** * @constructor - * @param {string=} utfLabel */ -function FastTextEncoder(utfLabel='utf-8') { - if (utfLabel !== 'utf-8' && utfLabel !== 'utf8') { - throw new RangeError( - `Failed to construct 'TextEncoder': The encoding label provided ('${utfLabel}') is invalid.`); - } +function FastTextEncoder() { + // This does not accept an encoding, and always uses UTF-8: + // https://www.w3.org/TR/encoding/#dom-textencoder } Object.defineProperty(FastTextEncoder.prototype, 'encoding', {value: 'utf-8'}); @@ -116,7 +116,7 @@ FastTextEncoder.prototype.encode = function(string, options={stream: false}) { * @param {{fatal: boolean}=} options */ function FastTextDecoder(utfLabel='utf-8', options={fatal: false}) { - if (utfLabel !== 'utf-8' && utfLabel !== 'utf8') { + if (validUtfLabels.indexOf(utfLabel.toLowerCase()) == -1) { throw new RangeError( `Failed to construct 'TextDecoder': The encoding label provided ('${utfLabel}') is invalid.`); }