Add TextDecoder polyfill
This commit is contained in:
parent
ad92ac7c3a
commit
0cabf72682
|
@ -69,6 +69,7 @@
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"mocha": "^5.0.0",
|
"mocha": "^5.0.0",
|
||||||
"sinon": "^4.3.0",
|
"sinon": "^4.3.0",
|
||||||
|
"text-encoder-lite": "^1.0.1",
|
||||||
"whatwg-fetch": "^2.0.3"
|
"whatwg-fetch": "^2.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -44,15 +44,11 @@ import { CleartextMessage } from './cleartext';
|
||||||
import { generate, reformat } from './key';
|
import { generate, reformat } from './key';
|
||||||
import config from './config/config';
|
import config from './config/config';
|
||||||
import enums from './enums';
|
import enums from './enums';
|
||||||
|
import './polyfills';
|
||||||
import stream from './stream';
|
import stream from './stream';
|
||||||
import util from './util';
|
import util from './util';
|
||||||
import AsyncProxy from './worker/async_proxy';
|
import AsyncProxy from './worker/async_proxy';
|
||||||
|
|
||||||
// Old browser polyfills
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
require('./polyfills');
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// //
|
// //
|
||||||
// Web Worker setup //
|
// Web Worker setup //
|
||||||
|
|
|
@ -1,33 +1,52 @@
|
||||||
|
/**
|
||||||
|
* @fileoverview Old browser polyfills
|
||||||
|
* All are listed as dev dependencies because Node does not need them
|
||||||
|
* and for browser babel will take care of it
|
||||||
|
* @requires util
|
||||||
|
* @module polyfills
|
||||||
|
*/
|
||||||
|
|
||||||
|
import util from './util';
|
||||||
|
|
||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
// Old browser polyfills
|
|
||||||
// All are listed as dev dependencies because Node does not need them
|
|
||||||
// and for browser babel will take care of it
|
|
||||||
|
|
||||||
if (typeof window.fetch === 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
require('whatwg-fetch');
|
if (typeof window.fetch === 'undefined') {
|
||||||
}
|
require('whatwg-fetch');
|
||||||
if (typeof Array.prototype.fill === 'undefined') {
|
}
|
||||||
require('core-js/fn/array/fill');
|
if (typeof Array.prototype.fill === 'undefined') {
|
||||||
}
|
require('core-js/fn/array/fill');
|
||||||
if (typeof Array.prototype.find === 'undefined') {
|
}
|
||||||
require('core-js/fn/array/find');
|
if (typeof Array.prototype.find === 'undefined') {
|
||||||
}
|
require('core-js/fn/array/find');
|
||||||
if (typeof Array.from === 'undefined') {
|
}
|
||||||
require('core-js/fn/array/from');
|
if (typeof Array.from === 'undefined') {
|
||||||
|
require('core-js/fn/array/from');
|
||||||
|
}
|
||||||
|
|
||||||
|
// No if-statement on Promise because of IE11. Otherwise Promise is undefined in the service worker.
|
||||||
|
require('core-js/fn/promise');
|
||||||
|
|
||||||
|
if (typeof Uint8Array.from === 'undefined') {
|
||||||
|
require('core-js/fn/typed/uint8-array');
|
||||||
|
}
|
||||||
|
if (typeof String.prototype.repeat === 'undefined') {
|
||||||
|
require('core-js/fn/string/repeat');
|
||||||
|
}
|
||||||
|
if (typeof Symbol === 'undefined') {
|
||||||
|
require('core-js/fn/symbol');
|
||||||
|
}
|
||||||
|
if (typeof Object.assign === 'undefined') {
|
||||||
|
require('core-js/fn/object/assign');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No if-statement on Promise because of IE11. Otherwise Promise is undefined in the service worker.
|
if (typeof TransformStream === 'undefined') {
|
||||||
require('core-js/fn/promise');
|
require('@mattiasbuelens/web-streams-polyfill');
|
||||||
|
|
||||||
if (typeof Uint8Array.from === 'undefined') {
|
|
||||||
require('core-js/fn/typed/uint8-array');
|
|
||||||
}
|
}
|
||||||
if (typeof String.prototype.repeat === 'undefined') {
|
if (typeof TextDecoder === 'undefined') {
|
||||||
require('core-js/fn/string/repeat');
|
global.TextDecoder = util.getNodeTextDecoder();
|
||||||
}
|
}
|
||||||
if (typeof Symbol === 'undefined') {
|
if (typeof TextDecoder === 'undefined') {
|
||||||
require('core-js/fn/symbol');
|
global.TextDecoder = require('text-encoder-lite');
|
||||||
}
|
|
||||||
if (typeof Object.assign === 'undefined') {
|
|
||||||
require('core-js/fn/object/assign');
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import util from './util';
|
import util from './util';
|
||||||
|
|
||||||
if (typeof TransformStream === 'undefined') {
|
|
||||||
require('@mattiasbuelens/web-streams-polyfill');
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeStream = util.getNodeStream();
|
const nodeStream = util.getNodeStream();
|
||||||
|
|
||||||
function toStream(input) {
|
function toStream(input) {
|
||||||
|
|
11
src/util.js
11
src/util.js
|
@ -664,12 +664,19 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This "hack" allows us to access the native node buffer module.
|
|
||||||
// otherwise, it gets replaced with the browserified version
|
|
||||||
// eslint-disable-next-line no-useless-concat, import/no-dynamic-require
|
// eslint-disable-next-line no-useless-concat, import/no-dynamic-require
|
||||||
return require('stream'+'');
|
return require('stream'+'');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getNodeTextDecoder: function() {
|
||||||
|
if (!util.detectNode()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-useless-concat, import/no-dynamic-require
|
||||||
|
return require('util'+'').TextDecoder;
|
||||||
|
},
|
||||||
|
|
||||||
isEmailAddress: function(data) {
|
isEmailAddress: function(data) {
|
||||||
if (!util.isString(data)) {
|
if (!util.isString(data)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user