loaders.gl
Version:
Framework-independent loaders for 3D graphics formats
72 lines (57 loc) • 2.69 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
// The MIT License (MIT) Copyright (c) 2016 Till Affeldt
/* global window */
// allowed encoding strings for utf-8
export var utf8Encodings = ['utf8', 'utf-8', 'unicode-1-1-utf-8'];
var TextDecoderPolyfill =
/*#__PURE__*/
function () {
function TextDecoderPolyfill(encoding, options) {
_classCallCheck(this, TextDecoderPolyfill);
if (utf8Encodings.indexOf(encoding) < 0 && typeof encoding !== 'undefined' && encoding !== null) {
throw new RangeError('Invalid encoding type. Only utf-8 is supported');
} else {
this.encoding = 'utf-8';
this.ignoreBOM = false;
this.fatal = typeof options !== 'undefined' && 'fatal' in options ? options.fatal : false;
if (typeof this.fatal !== 'boolean') {
throw new TypeError('fatal flag must be boolean');
}
}
}
_createClass(TextDecoderPolyfill, [{
key: "decode",
value: function decode(view, options) {
if (typeof view === 'undefined') {
return '';
}
var stream = typeof options !== 'undefined' && 'stream' in options ? options.stream : false;
if (typeof stream !== 'boolean') {
throw new TypeError('stream option must be boolean');
}
if (view instanceof ArrayBuffer) {
view = new Uint8Array(view);
}
if (!ArrayBuffer.isView(view)) {
throw new TypeError('passed argument must be an array buffer view');
} else {
var arr = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
var charArr = new Array(arr.length);
arr.forEach(function (charcode, i) {
charArr[i] = String.fromCharCode(charcode);
});
var text = charArr.join('');
try {
return decodeURIComponent(escape(text));
} catch (error) {
return text;
}
}
}
}]);
return TextDecoderPolyfill;
}();
export default typeof window !== 'undefined' ? window.TextDecoder : TextDecoderPolyfill;
//# sourceMappingURL=text-decoder.js.map