Replace TextEncoder polyfill
This commit is contained in:
3 files changed
+24
-16
No files matched your search
@@ -4,16 +4,10 @@ import projectData from './project-data';
|
||||
import backdrop from '!raw-loader!./cd21514d0531fdffb22204e0ec5ed84a.svg';
|
||||
import costume1 from '!raw-loader!./14e46ec3e2ba471c2adfe8f119052307.svg';
|
||||
/* eslint-enable import/no-unresolved */
|
||||
import TextEncoder from '../tw-text-encoder';
|
||||
|
||||
const defaultProject = translator => {
|
||||
let _TextEncoder;
|
||||
if (typeof TextEncoder === 'undefined') {
|
||||
_TextEncoder = require('text-encoding').TextEncoder;
|
||||
} else {
|
||||
/* global TextEncoder */
|
||||
_TextEncoder = TextEncoder;
|
||||
}
|
||||
const encoder = new _TextEncoder();
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const projectJson = projectData(translator);
|
||||
return [{
|
||||
|
||||
@@ -3,18 +3,12 @@ import backdrop from '!raw-loader!./c17163c6954e9422ac2405de4c9d68c8.svg';
|
||||
/* eslint-enable import/no-unresolved */
|
||||
|
||||
import projectData from './project-data';
|
||||
import TextEncoder from '../tw-text-encoder';
|
||||
|
||||
export const MISSING_PROJECT_ID = '__missing__';
|
||||
|
||||
const missingProject = () => {
|
||||
let _TextEncoder;
|
||||
if (typeof TextEncoder === 'undefined') {
|
||||
_TextEncoder = require('text-encoding').TextEncoder;
|
||||
} else {
|
||||
/* global TextEncoder */
|
||||
_TextEncoder = TextEncoder;
|
||||
}
|
||||
const encoder = new _TextEncoder();
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const projectJson = projectData();
|
||||
return [{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
const _TextEncoder = typeof TextEncoder === 'function' ? TextEncoder : class TextEncoder {
|
||||
constructor (encoding) {
|
||||
if (typeof encoding !== 'undefined' && encoding !== null && encoding !== 'utf-8' && encoding !== 'utf8') {
|
||||
throw new Error('Encoding is not supported');
|
||||
}
|
||||
this.encoding = 'utf-8';
|
||||
}
|
||||
encode (str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new TypeError('Argument is not a string');
|
||||
}
|
||||
const arr = new Uint8Array(str.length);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
arr[i] = str.charCodeAt(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
|
||||
export default _TextEncoder;
|
||||
Reference in new issue
Block a user