nanoid 1.2.0 → 1.2.1

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 1.2.1
5
+ * Fix old Node.js support.
6
+
4
7
  ## 1.2
5
8
  * Add `nanoid/async`.
6
9
  * Fix `nanoid/non-secure` JSDoc.
package/README.md CHANGED
@@ -121,7 +121,7 @@ nanoid(10) //=> "IRFa~VaY2b"
121
121
  Don’t forget to check safety of your ID length
122
122
  in our [ID collision probability] calculator.
123
123
 
124
- [ID collision probability]: https://alex7kom.github.io/nano-nanoid-cc/
124
+ [ID collision probability]: https://zelark.github.io/nano-id-cc/
125
125
 
126
126
 
127
127
  ### React Native and Web Workers
@@ -218,7 +218,7 @@ format(random, url, 10) //=> "93ce_Ltuub"
218
218
  * [`nanoid-good`] to be sure that your ID doesn't contain any obscene words.
219
219
 
220
220
  [`nanoid-dictionary`]: https://github.com/CyberAP/nanoid-dictionary
221
- [ID size calculator]: https://alex7kom.github.io/nano-nanoid-cc/
221
+ [ID size calculator]: https://zelark.github.io/nano-id-cc/
222
222
  [`nanoid-cli`]: https://github.com/twhitbeck/nanoid-cli
223
223
  [`nanoid-good`]: https://github.com/y-gagar1n/nanoid-good
224
224
 
package/async.js CHANGED
@@ -9,6 +9,7 @@ var url = require('./url')
9
9
  * to UUID v4.
10
10
  *
11
11
  * @param {number} [size=21] The number of symbols in ID.
12
+ * @param {function} callback for environments without `Promise`.
12
13
  *
13
14
  * @return {Promise} Promise with random string.
14
15
  *
@@ -21,19 +22,33 @@ var url = require('./url')
21
22
  * @name async
22
23
  * @function
23
24
  */
24
- module.exports = function (size) {
25
+ module.exports = function (size, callback) {
25
26
  size = size || 21
26
- return new Promise(function (resolve, reject) {
27
+ if (callback) {
27
28
  crypto.randomBytes(size, function (err, bytes) {
28
29
  if (err) {
29
- reject(err)
30
+ callback(err)
30
31
  } else {
31
32
  var id = ''
32
33
  while (0 < size--) {
33
34
  id += url[bytes[size] & 63]
34
35
  }
35
- resolve(id)
36
+ callback(null, id)
36
37
  }
37
38
  })
38
- })
39
+ } else {
40
+ return new Promise(function (resolve, reject) {
41
+ crypto.randomBytes(size, function (err, bytes) {
42
+ if (err) {
43
+ reject(err)
44
+ } else {
45
+ var id = ''
46
+ while (0 < size--) {
47
+ id += url[bytes[size] & 63]
48
+ }
49
+ resolve(id)
50
+ }
51
+ })
52
+ })
53
+ }
39
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A tiny (145 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",