Skip to content
Myr

Update IE polyfill to fix last improve with reduce (#362)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Vitaly Baev · committed by GitHub · parent fc5bd0d · Browse files · 3 files+48 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+48 added−5 removed

  • other:+48 added−5 removed

3 files+48 added−5 removed

modified:README.md+17 added-2 removed
325 unmodified lines
326327### IE328329If you support IE, you need to [transpile `node_modules`] by Babel330and add `crypto` alias:330and add `crypto` alias. Moreover, `UInt8Array` in IE actually331is not an array and to cope with it, you have to convert it to an array332manually:333334```js335// polyfills.js334if (!window.crypto) {336if (!window.crypto && window.msCrypto) {337 window.crypto = window.msCrypto338339 const getRandomValuesDef = window.crypto.getRandomValues340341 window.crypto.getRandomValues = function (array) {342 const values = getRandomValuesDef.call(window.crypto, array)343 const result = []344345 for (let i = 0; i < array.length; i++) {346 result[i] = values[i];347 }348349 return result350 };351}352```353354```js
200 unmodified lines
modified:README.ru.md+17 added-2 removed
333 unmodified lines
334335### IE336337Если вам нужна поддержка IE, потребуется включить [компиляцию `node_modules`]338с помощью Babel и вручную убрать вендорный префикс у `crypto`.338с помощью Babel и вручную убрать вендорный префикс у `crypto`. Кроме того,339из-за того, что `UInt8Array` в IE является массивом, необходимо преобразовать340метод `getRandomValues`, чтобы он возвращал массив:341342```js343// polyfills.js342if (!window.crypto) {344if (!window.crypto && window.msCrypto) {345 window.crypto = window.msCrypto346347 const getRandomValuesDef = window.crypto.getRandomValues348349 window.crypto.getRandomValues = function (array) {350 const values = getRandomValuesDef.call(window.crypto, array)351 const result = []352353 for (let i = 0; i < array.length; i++) {354 result[i] = values[i];355 }356357 return result358 };359}360```361362```js
177 unmodified lines
modified:README.zh-CN.md+14 added-1 removed
309 unmodified lines
310并添加 `crypto` 别名:311312```js313// polyfills.js314if (!window.crypto) {314if (!window.crypto && window.msCrypto) {315 window.crypto = window.msCrypto316317 const getRandomValuesDef = window.crypto.getRandomValues318319 window.crypto.getRandomValues = function (array) {320 const values = getRandomValuesDef.call(window.crypto, array)321 const result = []322323 for (let i = 0; i < array.length; i++) {324 result[i] = values[i];325 }326327 return result328 };329}330```331332```js
183 unmodified lines