Skip to content

Commit

Permalink
Update IE polyfill to fix last improve with reduce (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybaev authored May 4, 2022
1 parent fc5bd0d commit 21728dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,27 @@ the same result.
### IE

If you support IE, you need to [transpile `node_modules`] by Babel
and add `crypto` alias:
and add `crypto` alias. Moreover, `UInt8Array` in IE actually
is not an array and to cope with it, you have to convert it to an array
manually:

```js
// polyfills.js
if (!window.crypto) {
if (!window.crypto && window.msCrypto) {
window.crypto = window.msCrypto

const getRandomValuesDef = window.crypto.getRandomValues

window.crypto.getRandomValues = function (array) {
const values = getRandomValuesDef.call(window.crypto, array)
const result = []

for (let i = 0; i < array.length; i++) {
result[i] = values[i];
}

return result
};
}
```

Expand Down
19 changes: 17 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,27 @@ const nanoid = customRandom(urlAlphabet, 10, random)
### IE

Если вам нужна поддержка IE, потребуется включить [компиляцию `node_modules`]
с помощью Babel и вручную убрать вендорный префикс у `crypto`.
с помощью Babel и вручную убрать вендорный префикс у `crypto`. Кроме того,
из-за того, что `UInt8Array` в IE является массивом, необходимо преобразовать
метод `getRandomValues`, чтобы он возвращал массив:

```js
// polyfills.js
if (!window.crypto) {
if (!window.crypto && window.msCrypto) {
window.crypto = window.msCrypto

const getRandomValuesDef = window.crypto.getRandomValues

window.crypto.getRandomValues = function (array) {
const values = getRandomValuesDef.call(window.crypto, array)
const result = []

for (let i = 0; i < array.length; i++) {
result[i] = values[i];
}

return result
};
}
```

Expand Down
15 changes: 14 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,21 @@ const nanoid = customRandom(urlAlphabet, 10, random)

```js
// polyfills.js
if (!window.crypto) {
if (!window.crypto && window.msCrypto) {
window.crypto = window.msCrypto

const getRandomValuesDef = window.crypto.getRandomValues

window.crypto.getRandomValues = function (array) {
const values = getRandomValuesDef.call(window.crypto, array)
const result = []

for (let i = 0; i < array.length; i++) {
result[i] = values[i];
}

return result
};
}
```

Expand Down

0 comments on commit 21728dc

Please sign in to comment.