nanoid 3.1.9 → 3.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nanoid might be problematic. Click here for more details.

package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 3.1.13
5
+ * Remove Node.js 15.0.0 with `randomFillSync` regression from `engines.node`.
6
+
7
+ ## 3.1.12
8
+ * Improve IE 11 docs.
9
+
10
+ ## 3.1.11
11
+ * Fixed asynchronous `customAlphabet` in browser (by @LoneRifle).
12
+
13
+ ## 3.1.10
14
+ * Fix ES modules support.
15
+
4
16
  ## 3.1.9
5
17
  * Try to fix React Native Expo support.
6
18
 
package/README.md CHANGED
@@ -46,6 +46,7 @@ Supports modern browsers, IE [with Babel], Node.js and React Native.
46
46
  * [React](#react)
47
47
  * [Create React App](#create-react-app)
48
48
  * [React Native](#react-native)
49
+ * [Rollup](#rollup)
49
50
  * [Expo](#expo)
50
51
  * [PouchDB and CouchDB](#pouchdb-and-couchdb)
51
52
  * [Mongoose](#mongoose)
@@ -138,7 +139,7 @@ Test configuration: Dell XPS 2-in-a 7390, Fedora 32, Node.js 13.11.
138
139
  Tidelift will coordinate the fix and disclosure.
139
140
 
140
141
  [Secure random values (in Node.js)]: https://gist.github.com/joepie91/7105003c3b26e65efcea63f3db82dfba
141
- [better algorithm]: https://github.com/ai/nanoid/blob/master/format.js
142
+ [better algorithm]: https://github.com/ai/nanoid/blob/master/index.js
142
143
 
143
144
 
144
145
  ## Usage
@@ -175,10 +176,14 @@ If you support IE, you need to [transpile `node_modules`] by Babel
175
176
  and add `crypto` alias:
176
177
 
177
178
  ```js
179
+ // polyfills.js
178
180
  if (!window.crypto) {
179
181
  window.crypto = window.msCrypto
180
182
  }
183
+ ```
181
184
 
185
+ ```js
186
+ import './polyfills.js'
182
187
  import { nanoid } from 'nanoid'
183
188
  ```
184
189
 
@@ -222,12 +227,10 @@ with ES modules packages.
222
227
  TypeError: (0 , _nanoid.nanoid) is not a function
223
228
  ```
224
229
 
225
- If you have an error above, here is temporary fix:
230
+ [Pull request](https://github.com/facebook/create-react-app/pull/8768) was sent,
231
+ but it was still not released.
226
232
 
227
- 1. Use Nano ID 2 instead of 3: `npm i nanoid@^2.0.0`.
228
- 2. Vote for
229
- [pull request](https://github.com/facebook/create-react-app/pull/8768),
230
- that fix dual packages support.
233
+ Use Nano ID 2 `npm i nanoid@^2.0.0` until Create React App 4.0 release.
231
234
 
232
235
 
233
236
  ### React Native
@@ -247,15 +250,32 @@ For Expo framework see the next section.
247
250
  [`react-native-get-random-values`]: https://github.com/LinusU/react-native-get-random-values
248
251
 
249
252
 
253
+ ### Rollup
254
+
255
+ For Rollup you will need [`@rollup/plugin-replace`] to replace
256
+ `process.env.NODE_ENV`:
257
+
258
+ ```js
259
+ plugins: [
260
+ replace({
261
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE)
262
+ })
263
+ ]
264
+ ```
265
+
266
+ [`@rollup/plugin-replace`]: https://github.com/rollup/plugins/tree/master/packages/replace
267
+
268
+
250
269
  ### Expo
251
270
 
252
271
  If you use Expo in React Native, you need a different workaround.
253
272
 
254
273
  1. Install [`expo-random`](https://www.npmjs.com/package/expo-random).
255
274
  2. Use `nanoid/async` instead of `nanoid`.
275
+ 3. Import `index.native.js` file directly.
256
276
 
257
277
  ```js
258
- import { nanoid } from 'nanoid/async'
278
+ import { nanoid } from 'nanoid/async/index.native'
259
279
 
260
280
  async function createUser () {
261
281
  user.id = await nanoid()
@@ -352,12 +372,15 @@ Nano ID was ported to many languages. You can use these ports to have
352
372
  the same ID generator on the client and server side.
353
373
 
354
374
  * [C#](https://github.com/codeyu/nanoid-net)
375
+ * [C++](https://github.com/mcmikecreations/nanoid_cpp)
355
376
  * [Clojure and ClojureScript](https://github.com/zelark/nano-id)
356
377
  * [Crystal](https://github.com/mamantoha/nanoid.cr)
357
378
  * [Dart](https://github.com/pd4d10/nanoid-dart)
379
+ * [Deno](https://github.com/ianfabs/nanoid)
358
380
  * [Go](https://github.com/matoous/go-nanoid)
359
381
  * [Elixir](https://github.com/railsmechanic/nanoid)
360
382
  * [Haskell](https://github.com/4e6/nanoid-hs)
383
+ * [Janet](https://sr.ht/~statianzo/janet-nanoid/)
361
384
  * [Java](https://github.com/aventrix/jnanoid)
362
385
  * [Nim](https://github.com/icyphox/nanoid.nim)
363
386
  * [PHP](https://github.com/hidehalo/nanoid-php)
@@ -392,7 +415,7 @@ async function createUser () {
392
415
  ```
393
416
 
394
417
  Unfortunately, you will lose Web Crypto API advantages in a browser
395
- if you the asynchronous API. So, currently, in the browser, you are limited
418
+ if you use the asynchronous API. So, currently, in the browser, you are limited
396
419
  with either security or asynchronous behavior.
397
420
 
398
421
 
@@ -35,7 +35,7 @@ let customAlphabet = (alphabet, size) => {
35
35
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
36
36
  id += alphabet[bytes[i] & mask] || ''
37
37
  // `id.length + 1 === size` is a more compact option.
38
- if (id.length === +size) return id
38
+ if (id.length === +size) return Promise.resolve(id)
39
39
  }
40
40
  }
41
41
  }
package/index.browser.js CHANGED
@@ -20,8 +20,8 @@ if (process.env.NODE_ENV !== 'production') {
20
20
  }
21
21
  if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
22
22
  throw new Error(
23
- 'Add `if (!window.crypto) window.crypto = window.msCrypto` ' +
24
- 'before Nano ID to fix IE 11 support'
23
+ 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
24
+ ' before importing Nano ID to fix IE 11 support'
25
25
  )
26
26
  }
27
27
  if (typeof crypto === 'undefined') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "3.1.9",
3
+ "version": "3.1.13",
4
4
  "description": "A tiny (108 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",
@@ -9,7 +9,7 @@
9
9
  "url"
10
10
  ],
11
11
  "engines": {
12
- "node": "^10 || ^12 || >=13.7"
12
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
13
13
  },
14
14
  "author": "Andrey Sitnik <andrey@sitnik.ru>",
15
15
  "license": "MIT",
@@ -24,17 +24,17 @@
24
24
  "main": "index.cjs",
25
25
  "module": "index.js",
26
26
  "exports": {
27
- "./package.json": "./package.json",
28
27
  ".": {
28
+ "browser": "./index.browser.js",
29
29
  "require": "./index.cjs",
30
- "import": "./index.js",
31
- "browser": "./index.browser.js"
30
+ "import": "./index.js"
32
31
  },
32
+ "./package.json": "./package.json",
33
33
  "./async/package.json": "./async/package.json",
34
34
  "./async": {
35
+ "browser": "./async/index.browser.js",
35
36
  "require": "./async/index.cjs",
36
- "import": "./async/index.js",
37
- "browser": "./async/index.browser.js"
37
+ "import": "./async/index.js"
38
38
  },
39
39
  "./non-secure/package.json": "./non-secure/package.json",
40
40
  "./non-secure": {