nanoid 5.1.5 → 5.1.7

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="https://ai.github.io/nanoid/logo.svg" align="right"
4
4
  alt="Nano ID logo by Anton Lovchikov" width="180" height="94">
5
5
 
6
- **English** | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md)
6
+ **English** | [日本語](./README.ja.md) | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md) | [한국어](./README.ko.md) | [العربية](./README.ar.md)
7
7
 
8
8
  A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
9
9
 
package/bin/nanoid.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs'
3
+ import { dirname, join } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
2
5
  import { customAlphabet, nanoid } from '../index.js'
3
6
  function print(msg) {
4
7
  process.stdout.write(msg + '\n')
@@ -7,12 +10,19 @@ function error(msg) {
7
10
  process.stderr.write(msg + '\n')
8
11
  process.exit(1)
9
12
  }
13
+ if (process.argv.includes('--version') || process.argv.includes('-v')) {
14
+ let root = dirname(fileURLToPath(import.meta.url))
15
+ let pkg = JSON.parse(readFileSync(join(root, '..', 'package.json'), 'utf8'))
16
+ print(pkg.version)
17
+ process.exit()
18
+ }
10
19
  if (process.argv.includes('--help') || process.argv.includes('-h')) {
11
20
  print(`Usage
12
21
  $ nanoid [options]
13
22
  Options
14
23
  -s, --size Generated ID size
15
24
  -a, --alphabet Alphabet to use
25
+ -v, --version Show version number
16
26
  -h, --help Show this help
17
27
  Examples
18
28
  $ nanoid -s 15
package/index.d.ts CHANGED
@@ -39,7 +39,7 @@ export function nanoid<Type extends string>(size?: number): Type
39
39
  * @returns A random string generator.
40
40
  *
41
41
  * ```js
42
- * const { customAlphabet } = require('nanoid')
42
+ * import { customAlphabet } from 'nanoid'
43
43
  * const nanoid = customAlphabet('0123456789абвгдеё', 5)
44
44
  * nanoid() //=> "8ё56а"
45
45
  * ```
@@ -56,7 +56,7 @@ export function customAlphabet<Type extends string>(
56
56
  * will not be secure.
57
57
  *
58
58
  * ```js
59
- * import { customRandom } from 'nanoid/format'
59
+ * import { customRandom } from 'nanoid'
60
60
  *
61
61
  * const nanoid = customRandom('abcdef', 5, size => {
62
62
  * const random = []
@@ -79,7 +79,7 @@ export function customRandom<Type extends string>(
79
79
  alphabet: string,
80
80
  size: number,
81
81
  random: (bytes: number) => Uint8Array
82
- ): () => Type
82
+ ): (size?: number) => Type
83
83
 
84
84
  /**
85
85
  * URL safe symbols.
package/index.js CHANGED
@@ -22,6 +22,7 @@ export function customRandom(alphabet, defaultSize, getRandom) {
22
22
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
23
23
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
24
24
  return (size = defaultSize) => {
25
+ if (!size) return ''
25
26
  let id = ''
26
27
  while (true) {
27
28
  let bytes = getRandom(step)
package/nanoid.js CHANGED
@@ -1 +1 @@
1
- let a="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";export let nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e));for(let n=0;n<e;n++)t+=a[63&r[n]];return t};
1
+ let a="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";export let nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=a[63&r[e]];return t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "5.1.5",
3
+ "version": "5.1.7",
4
4
  "description": "A tiny (118 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",
@@ -23,11 +23,15 @@
23
23
  "repository": "ai/nanoid",
24
24
  "exports": {
25
25
  ".": {
26
+ "types": "./index.d.ts",
26
27
  "browser": "./index.browser.js",
27
28
  "react-native": "./index.browser.js",
28
29
  "default": "./index.js"
29
30
  },
30
- "./non-secure": "./non-secure/index.js",
31
+ "./non-secure": {
32
+ "types": "./non-secure/index.d.ts",
33
+ "default": "./non-secure/index.js"
34
+ },
31
35
  "./package.json": "./package.json"
32
36
  },
33
37
  "browser": {
@@ -1,2 +1,2 @@
1
- export const urlAlphabet =
1
+ export let urlAlphabet =
2
2
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'