@omnitron-dev/lumen 0.4.12 → 0.4.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.
- package/README.md +6 -0
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/define.js +1 -0
- package/dist/config/define.js.map +1 -1
- package/dist/config/schema.d.ts +2 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/corpus/routes.d.ts +1 -0
- package/dist/corpus/routes.d.ts.map +1 -1
- package/dist/corpus/routes.js +3 -0
- package/dist/corpus/routes.js.map +1 -1
- package/dist/search/index-builder.d.ts.map +1 -1
- package/dist/search/index-builder.js +8 -6
- package/dist/search/index-builder.js.map +1 -1
- package/dist/ssg/default-client.js +6 -2
- package/dist/ssg/default-client.js.map +1 -1
- package/dist/ssg/ssg-engine.d.ts.map +1 -1
- package/dist/ssg/ssg-engine.js +32 -16
- package/dist/ssg/ssg-engine.js.map +1 -1
- package/node_modules/fdir/LICENSE +7 -0
- package/node_modules/fdir/README.md +91 -0
- package/node_modules/fdir/dist/index.cjs +588 -0
- package/node_modules/fdir/dist/index.d.cts +155 -0
- package/node_modules/fdir/dist/index.d.mts +155 -0
- package/node_modules/fdir/dist/index.mjs +570 -0
- package/node_modules/fdir/package.json +103 -0
- package/node_modules/nanoid/LICENSE +20 -0
- package/node_modules/nanoid/README.md +39 -0
- package/node_modules/nanoid/async/index.browser.cjs +43 -0
- package/node_modules/nanoid/async/index.browser.js +43 -0
- package/node_modules/nanoid/async/index.cjs +47 -0
- package/node_modules/nanoid/async/index.d.cts +56 -0
- package/node_modules/nanoid/async/index.d.ts +56 -0
- package/node_modules/nanoid/async/index.js +47 -0
- package/node_modules/nanoid/async/index.native.js +38 -0
- package/node_modules/nanoid/async/package.json +12 -0
- package/node_modules/nanoid/bin/nanoid.cjs +55 -0
- package/node_modules/nanoid/index.browser.cjs +45 -0
- package/node_modules/nanoid/index.browser.js +45 -0
- package/node_modules/nanoid/index.cjs +63 -0
- package/node_modules/nanoid/index.d.cts +91 -0
- package/node_modules/nanoid/index.d.ts +91 -0
- package/node_modules/nanoid/index.js +63 -0
- package/node_modules/nanoid/nanoid.js +1 -0
- package/node_modules/nanoid/non-secure/index.cjs +24 -0
- package/node_modules/nanoid/non-secure/index.d.ts +33 -0
- package/node_modules/nanoid/non-secure/index.js +24 -0
- package/node_modules/nanoid/non-secure/package.json +6 -0
- package/node_modules/nanoid/package.json +89 -0
- package/node_modules/nanoid/url-alphabet/index.cjs +4 -0
- package/node_modules/nanoid/url-alphabet/index.js +4 -0
- package/node_modules/nanoid/url-alphabet/package.json +6 -0
- package/node_modules/picocolors/LICENSE +15 -0
- package/node_modules/picocolors/README.md +21 -0
- package/node_modules/picocolors/package.json +25 -0
- package/node_modules/picocolors/picocolors.browser.js +4 -0
- package/node_modules/picocolors/picocolors.d.ts +5 -0
- package/node_modules/picocolors/picocolors.js +75 -0
- package/node_modules/picocolors/types.d.ts +51 -0
- package/node_modules/picomatch/LICENSE +21 -0
- package/node_modules/picomatch/README.md +743 -0
- package/node_modules/picomatch/index.js +17 -0
- package/node_modules/picomatch/lib/constants.js +184 -0
- package/node_modules/picomatch/lib/parse.js +1439 -0
- package/node_modules/picomatch/lib/picomatch.js +361 -0
- package/node_modules/picomatch/lib/scan.js +403 -0
- package/node_modules/picomatch/lib/utils.js +72 -0
- package/node_modules/picomatch/package.json +83 -0
- package/node_modules/picomatch/posix.js +3 -0
- package/node_modules/postcss/LICENSE +20 -0
- package/node_modules/postcss/README.md +27 -0
- package/node_modules/postcss/lib/at-rule.d.ts +139 -0
- package/node_modules/postcss/lib/at-rule.js +25 -0
- package/node_modules/postcss/lib/comment.d.ts +67 -0
- package/node_modules/postcss/lib/comment.js +13 -0
- package/node_modules/postcss/lib/container.d.ts +474 -0
- package/node_modules/postcss/lib/container.js +494 -0
- package/node_modules/postcss/lib/css-syntax-error.d.ts +247 -0
- package/node_modules/postcss/lib/css-syntax-error.js +133 -0
- package/node_modules/postcss/lib/declaration.d.ts +150 -0
- package/node_modules/postcss/lib/declaration.js +24 -0
- package/node_modules/postcss/lib/document.d.ts +68 -0
- package/node_modules/postcss/lib/document.js +33 -0
- package/node_modules/postcss/lib/fromJSON.d.ts +9 -0
- package/node_modules/postcss/lib/fromJSON.js +107 -0
- package/node_modules/postcss/lib/input.d.ts +226 -0
- package/node_modules/postcss/lib/input.js +282 -0
- package/node_modules/postcss/lib/lazy-result.d.ts +189 -0
- package/node_modules/postcss/lib/lazy-result.js +626 -0
- package/node_modules/postcss/lib/list.d.ts +60 -0
- package/node_modules/postcss/lib/list.js +79 -0
- package/node_modules/postcss/lib/map-generator.js +383 -0
- package/node_modules/postcss/lib/no-work-result.d.ts +45 -0
- package/node_modules/postcss/lib/no-work-result.js +137 -0
- package/node_modules/postcss/lib/node.d.ts +555 -0
- package/node_modules/postcss/lib/node.js +494 -0
- package/node_modules/postcss/lib/parse.d.ts +9 -0
- package/node_modules/postcss/lib/parse.js +42 -0
- package/node_modules/postcss/lib/parser.js +626 -0
- package/node_modules/postcss/lib/postcss.d.mts +66 -0
- package/node_modules/postcss/lib/postcss.d.ts +464 -0
- package/node_modules/postcss/lib/postcss.js +101 -0
- package/node_modules/postcss/lib/postcss.mjs +30 -0
- package/node_modules/postcss/lib/previous-map.d.ts +80 -0
- package/node_modules/postcss/lib/previous-map.js +176 -0
- package/node_modules/postcss/lib/processor.d.ts +114 -0
- package/node_modules/postcss/lib/processor.js +67 -0
- package/node_modules/postcss/lib/result.d.ts +204 -0
- package/node_modules/postcss/lib/result.js +42 -0
- package/node_modules/postcss/lib/root.d.ts +86 -0
- package/node_modules/postcss/lib/root.js +76 -0
- package/node_modules/postcss/lib/rule.d.ts +126 -0
- package/node_modules/postcss/lib/rule.js +27 -0
- package/node_modules/postcss/lib/stringifier.d.ts +45 -0
- package/node_modules/postcss/lib/stringifier.js +457 -0
- package/node_modules/postcss/lib/stringify.d.ts +9 -0
- package/node_modules/postcss/lib/stringify.js +93 -0
- package/node_modules/postcss/lib/symbols.js +5 -0
- package/node_modules/postcss/lib/terminal-highlight.js +70 -0
- package/node_modules/postcss/lib/tokenize.js +270 -0
- package/node_modules/postcss/lib/warn-once.js +13 -0
- package/node_modules/postcss/lib/warning.d.ts +146 -0
- package/node_modules/postcss/lib/warning.js +48 -0
- package/node_modules/postcss/package.json +88 -0
- package/node_modules/source-map-js/LICENSE +28 -0
- package/node_modules/source-map-js/README.md +765 -0
- package/node_modules/source-map-js/lib/array-set.js +121 -0
- package/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/node_modules/source-map-js/lib/base64.js +67 -0
- package/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/node_modules/source-map-js/lib/quick-sort.js +141 -0
- package/node_modules/source-map-js/lib/source-map-consumer.d.ts +1 -0
- package/node_modules/source-map-js/lib/source-map-consumer.js +1236 -0
- package/node_modules/source-map-js/lib/source-map-generator.d.ts +1 -0
- package/node_modules/source-map-js/lib/source-map-generator.js +446 -0
- package/node_modules/source-map-js/lib/source-node.d.ts +1 -0
- package/node_modules/source-map-js/lib/source-node.js +420 -0
- package/node_modules/source-map-js/lib/util.js +594 -0
- package/node_modules/source-map-js/package.json +71 -0
- package/node_modules/source-map-js/source-map.d.ts +104 -0
- package/node_modules/source-map-js/source-map.js +8 -0
- package/{LICENSE → node_modules/tinyglobby/LICENSE} +1 -1
- package/node_modules/tinyglobby/README.md +25 -0
- package/node_modules/tinyglobby/dist/index.cjs +335 -0
- package/node_modules/tinyglobby/dist/index.d.cts +148 -0
- package/node_modules/tinyglobby/dist/index.d.mts +148 -0
- package/node_modules/tinyglobby/dist/index.mjs +307 -0
- package/node_modules/tinyglobby/package.json +70 -0
- package/node_modules/vite/LICENSE.md +2084 -0
- package/node_modules/vite/README.md +20 -0
- package/node_modules/vite/bin/openChrome.js +68 -0
- package/node_modules/vite/bin/vite.js +90 -0
- package/node_modules/vite/client.d.ts +285 -0
- package/node_modules/vite/dist/client/bundledDevClient.mjs +1642 -0
- package/node_modules/vite/dist/client/client.mjs +1331 -0
- package/node_modules/vite/dist/client/env.mjs +18 -0
- package/node_modules/vite/dist/node/chunks/build.js +5833 -0
- package/node_modules/vite/dist/node/chunks/dist.js +7029 -0
- package/node_modules/vite/dist/node/chunks/lib.js +371 -0
- package/node_modules/vite/dist/node/chunks/moduleRunnerTransport.d.ts +95 -0
- package/node_modules/vite/dist/node/chunks/node.js +38364 -0
- package/node_modules/vite/dist/node/chunks/postcss-import.js +465 -0
- package/node_modules/vite/dist/node/cli.js +849 -0
- package/node_modules/vite/dist/node/index.d.ts +4064 -0
- package/node_modules/vite/dist/node/index.js +1 -0
- package/node_modules/vite/dist/node/internal.d.ts +2 -0
- package/node_modules/vite/dist/node/internal.js +1 -0
- package/node_modules/vite/dist/node/module-runner.d.ts +314 -0
- package/node_modules/vite/dist/node/module-runner.js +1296 -0
- package/node_modules/vite/misc/false.js +1 -0
- package/node_modules/vite/misc/true.js +1 -0
- package/node_modules/vite/package.json +195 -0
- package/node_modules/vite/types/customEvent.d.ts +83 -0
- package/node_modules/vite/types/hmrPayload.d.ts +96 -0
- package/node_modules/vite/types/hot.d.ts +39 -0
- package/node_modules/vite/types/import-meta.d.ts +5 -0
- package/node_modules/vite/types/importGlob.d.ts +131 -0
- package/node_modules/vite/types/importMeta.d.ts +30 -0
- package/node_modules/vite/types/internal/cssPreprocessorOptions.d.ts +44 -0
- package/node_modules/vite/types/internal/devtoolsOptions.d.ts +9 -0
- package/node_modules/vite/types/internal/esbuildOptions.d.ts +28 -0
- package/node_modules/vite/types/internal/lightningcssOptions.d.ts +18 -0
- package/node_modules/vite/types/internal/rollupTypeCompat.d.ts +24 -0
- package/node_modules/vite/types/internal/terserOptions.d.ts +11 -0
- package/node_modules/vite/types/metadata.d.ts +47 -0
- package/package.json +15 -7
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Nano ID
|
|
2
|
+
|
|
3
|
+
<img src="https://ai.github.io/nanoid/logo.svg" align="right"
|
|
4
|
+
alt="Nano ID logo by Anton Lovchikov" width="180" height="94">
|
|
5
|
+
|
|
6
|
+
**English** | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md)
|
|
7
|
+
|
|
8
|
+
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
|
|
9
|
+
|
|
10
|
+
> “An amazing level of senseless perfectionism,
|
|
11
|
+
> which is simply impossible not to respect.”
|
|
12
|
+
|
|
13
|
+
* **Small.** 130 bytes (minified and gzipped). No dependencies.
|
|
14
|
+
[Size Limit] controls the size.
|
|
15
|
+
* **Fast.** It is 2 times faster than UUID.
|
|
16
|
+
* **Safe.** It uses hardware random generator. Can be used in clusters.
|
|
17
|
+
* **Short IDs.** It uses a larger alphabet than UUID (`A-Za-z0-9_-`).
|
|
18
|
+
So ID size was reduced from 36 to 21 symbols.
|
|
19
|
+
* **Portable.** Nano ID was ported
|
|
20
|
+
to [20 programming languages](#other-programming-languages).
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { nanoid } from 'nanoid'
|
|
24
|
+
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Supports modern browsers, IE [with Babel], Node.js and React Native.
|
|
28
|
+
|
|
29
|
+
[online tool]: https://gitpod.io/#https://github.com/ai/nanoid/
|
|
30
|
+
[with Babel]: https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/
|
|
31
|
+
[Size Limit]: https://github.com/ai/size-limit
|
|
32
|
+
|
|
33
|
+
<a href="https://evilmartians.com/?utm_source=nanoid">
|
|
34
|
+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
|
|
35
|
+
alt="Sponsored by Evil Martians" width="236" height="54">
|
|
36
|
+
</a>
|
|
37
|
+
|
|
38
|
+
## Docs
|
|
39
|
+
Read full docs **[here](https://github.com/ai/nanoid#readme)**.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
2
|
+
|
|
3
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
4
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
9
|
+
|
|
10
|
+
return async (size = defaultSize) => {
|
|
11
|
+
if (size <= 0) return ''
|
|
12
|
+
let id = ''
|
|
13
|
+
while (true) {
|
|
14
|
+
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
|
15
|
+
let i = step | 0
|
|
16
|
+
while (i--) {
|
|
17
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
18
|
+
if (id.length === size) return id
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let nanoid = async (size = 21) => {
|
|
25
|
+
let id = ''
|
|
26
|
+
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
|
27
|
+
|
|
28
|
+
while (size--) {
|
|
29
|
+
let byte = bytes[size] & 63
|
|
30
|
+
if (byte < 36) {
|
|
31
|
+
id += byte.toString(36)
|
|
32
|
+
} else if (byte < 62) {
|
|
33
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
34
|
+
} else if (byte < 63) {
|
|
35
|
+
id += '_'
|
|
36
|
+
} else {
|
|
37
|
+
id += '-'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return id
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
2
|
+
|
|
3
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
4
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
9
|
+
|
|
10
|
+
return async (size = defaultSize) => {
|
|
11
|
+
if (size <= 0) return ''
|
|
12
|
+
let id = ''
|
|
13
|
+
while (true) {
|
|
14
|
+
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
|
15
|
+
let i = step | 0
|
|
16
|
+
while (i--) {
|
|
17
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
18
|
+
if (id.length === size) return id
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let nanoid = async (size = 21) => {
|
|
25
|
+
let id = ''
|
|
26
|
+
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
|
27
|
+
|
|
28
|
+
while (size--) {
|
|
29
|
+
let byte = bytes[size] & 63
|
|
30
|
+
if (byte < 36) {
|
|
31
|
+
id += byte.toString(36)
|
|
32
|
+
} else if (byte < 62) {
|
|
33
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
34
|
+
} else if (byte < 63) {
|
|
35
|
+
id += '_'
|
|
36
|
+
} else {
|
|
37
|
+
id += '-'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return id
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let crypto = require('crypto')
|
|
2
|
+
|
|
3
|
+
let { urlAlphabet } = require('../url-alphabet/index.cjs')
|
|
4
|
+
|
|
5
|
+
let random = bytes =>
|
|
6
|
+
new Promise((resolve, reject) => {
|
|
7
|
+
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
reject(err)
|
|
10
|
+
} else {
|
|
11
|
+
resolve(buf)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
17
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
21
|
+
|
|
22
|
+
let tick = (id, size = defaultSize) =>
|
|
23
|
+
random(step).then(bytes => {
|
|
24
|
+
let i = step
|
|
25
|
+
while (i--) {
|
|
26
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
27
|
+
if (id.length >= size) return id
|
|
28
|
+
}
|
|
29
|
+
return tick(id, size)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return (size = defaultSize) => {
|
|
33
|
+
if (size <= 0) return Promise.resolve('')
|
|
34
|
+
return tick('', size)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let nanoid = (size = 21) =>
|
|
39
|
+
random((size |= 0)).then(bytes => {
|
|
40
|
+
let id = ''
|
|
41
|
+
while (size--) {
|
|
42
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
43
|
+
}
|
|
44
|
+
return id
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
module.exports = { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate secure URL-friendly unique ID. The non-blocking version.
|
|
3
|
+
*
|
|
4
|
+
* By default, the ID will have 21 symbols to have a collision probability
|
|
5
|
+
* similar to UUID v4.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { nanoid } from 'nanoid/async'
|
|
9
|
+
* nanoid().then(id => {
|
|
10
|
+
* model.id = id
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param size Size of the ID. The default size is 21.
|
|
15
|
+
* @returns A promise with a random string.
|
|
16
|
+
*/
|
|
17
|
+
export function nanoid(size?: number): Promise<string>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A low-level function.
|
|
21
|
+
* Generate secure unique ID with custom alphabet. The non-blocking version.
|
|
22
|
+
*
|
|
23
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
|
24
|
+
* will not be secure.
|
|
25
|
+
*
|
|
26
|
+
* @param alphabet Alphabet used to generate the ID.
|
|
27
|
+
* @param defaultSize Size of the ID. The default size is 21.
|
|
28
|
+
* @returns A function that returns a promise with a random string.
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* import { customAlphabet } from 'nanoid/async'
|
|
32
|
+
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
|
33
|
+
* nanoid().then(id => {
|
|
34
|
+
* model.id = id //=> "8ё56а"
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function customAlphabet(
|
|
39
|
+
alphabet: string,
|
|
40
|
+
defaultSize?: number
|
|
41
|
+
): (size?: number) => Promise<string>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate an array of random bytes collected from hardware noise.
|
|
45
|
+
*
|
|
46
|
+
* ```js
|
|
47
|
+
* import { random } from 'nanoid/async'
|
|
48
|
+
* random(5).then(bytes => {
|
|
49
|
+
* bytes //=> [10, 67, 212, 67, 89]
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param bytes Size of the array.
|
|
54
|
+
* @returns A promise with a random bytes array.
|
|
55
|
+
*/
|
|
56
|
+
export function random(bytes: number): Promise<Uint8Array>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate secure URL-friendly unique ID. The non-blocking version.
|
|
3
|
+
*
|
|
4
|
+
* By default, the ID will have 21 symbols to have a collision probability
|
|
5
|
+
* similar to UUID v4.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { nanoid } from 'nanoid/async'
|
|
9
|
+
* nanoid().then(id => {
|
|
10
|
+
* model.id = id
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param size Size of the ID. The default size is 21.
|
|
15
|
+
* @returns A promise with a random string.
|
|
16
|
+
*/
|
|
17
|
+
export function nanoid(size?: number): Promise<string>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A low-level function.
|
|
21
|
+
* Generate secure unique ID with custom alphabet. The non-blocking version.
|
|
22
|
+
*
|
|
23
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
|
24
|
+
* will not be secure.
|
|
25
|
+
*
|
|
26
|
+
* @param alphabet Alphabet used to generate the ID.
|
|
27
|
+
* @param defaultSize Size of the ID. The default size is 21.
|
|
28
|
+
* @returns A function that returns a promise with a random string.
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* import { customAlphabet } from 'nanoid/async'
|
|
32
|
+
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
|
33
|
+
* nanoid().then(id => {
|
|
34
|
+
* model.id = id //=> "8ё56а"
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function customAlphabet(
|
|
39
|
+
alphabet: string,
|
|
40
|
+
defaultSize?: number
|
|
41
|
+
): (size?: number) => Promise<string>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate an array of random bytes collected from hardware noise.
|
|
45
|
+
*
|
|
46
|
+
* ```js
|
|
47
|
+
* import { random } from 'nanoid/async'
|
|
48
|
+
* random(5).then(bytes => {
|
|
49
|
+
* bytes //=> [10, 67, 212, 67, 89]
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param bytes Size of the array.
|
|
54
|
+
* @returns A promise with a random bytes array.
|
|
55
|
+
*/
|
|
56
|
+
export function random(bytes: number): Promise<Uint8Array>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
import { urlAlphabet } from '../url-alphabet/index.js'
|
|
4
|
+
|
|
5
|
+
let random = bytes =>
|
|
6
|
+
new Promise((resolve, reject) => {
|
|
7
|
+
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
reject(err)
|
|
10
|
+
} else {
|
|
11
|
+
resolve(buf)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
17
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
21
|
+
|
|
22
|
+
let tick = (id, size = defaultSize) =>
|
|
23
|
+
random(step).then(bytes => {
|
|
24
|
+
let i = step
|
|
25
|
+
while (i--) {
|
|
26
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
27
|
+
if (id.length >= size) return id
|
|
28
|
+
}
|
|
29
|
+
return tick(id, size)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return (size = defaultSize) => {
|
|
33
|
+
if (size <= 0) return Promise.resolve('')
|
|
34
|
+
return tick('', size)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let nanoid = (size = 21) =>
|
|
39
|
+
random((size |= 0)).then(bytes => {
|
|
40
|
+
let id = ''
|
|
41
|
+
while (size--) {
|
|
42
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
43
|
+
}
|
|
44
|
+
return id
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getRandomBytesAsync } from 'expo-random'
|
|
2
|
+
|
|
3
|
+
import { urlAlphabet } from '../url-alphabet/index.js'
|
|
4
|
+
|
|
5
|
+
let random = getRandomBytesAsync
|
|
6
|
+
|
|
7
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
8
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
12
|
+
|
|
13
|
+
let tick = (id, size = defaultSize) =>
|
|
14
|
+
random(step).then(bytes => {
|
|
15
|
+
let i = step
|
|
16
|
+
while (i--) {
|
|
17
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
18
|
+
if (id.length >= size) return id
|
|
19
|
+
}
|
|
20
|
+
return tick(id, size)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return (size = defaultSize) => {
|
|
24
|
+
if (size <= 0) return Promise.resolve('')
|
|
25
|
+
return tick('', size)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let nanoid = (size = 21) =>
|
|
30
|
+
random((size |= 0)).then(bytes => {
|
|
31
|
+
let id = ''
|
|
32
|
+
while (size--) {
|
|
33
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
34
|
+
}
|
|
35
|
+
return id
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
let { nanoid, customAlphabet } = require('..')
|
|
4
|
+
|
|
5
|
+
function print(msg) {
|
|
6
|
+
process.stdout.write(msg + '\n')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function error(msg) {
|
|
10
|
+
process.stderr.write(msg + '\n')
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
15
|
+
print(`
|
|
16
|
+
Usage
|
|
17
|
+
$ nanoid [options]
|
|
18
|
+
|
|
19
|
+
Options
|
|
20
|
+
-s, --size Generated ID size
|
|
21
|
+
-a, --alphabet Alphabet to use
|
|
22
|
+
-h, --help Show this help
|
|
23
|
+
|
|
24
|
+
Examples
|
|
25
|
+
$ nanoid --s 15
|
|
26
|
+
S9sBF77U6sDB8Yg
|
|
27
|
+
|
|
28
|
+
$ nanoid --size 10 --alphabet abc
|
|
29
|
+
bcabababca`)
|
|
30
|
+
process.exit()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let alphabet, size
|
|
34
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
35
|
+
let arg = process.argv[i]
|
|
36
|
+
if (arg === '--size' || arg === '-s') {
|
|
37
|
+
size = Number(process.argv[i + 1])
|
|
38
|
+
i += 1
|
|
39
|
+
if (Number.isNaN(size) || size <= 0) {
|
|
40
|
+
error('Size must be positive integer')
|
|
41
|
+
}
|
|
42
|
+
} else if (arg === '--alphabet' || arg === '-a') {
|
|
43
|
+
alphabet = process.argv[i + 1]
|
|
44
|
+
i += 1
|
|
45
|
+
} else {
|
|
46
|
+
error('Unknown argument ' + arg)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (alphabet) {
|
|
51
|
+
let customNanoid = customAlphabet(alphabet, size)
|
|
52
|
+
print(customNanoid())
|
|
53
|
+
} else {
|
|
54
|
+
print(nanoid(size))
|
|
55
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
|
3
|
+
|
|
4
|
+
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
5
|
+
|
|
6
|
+
let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
7
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
12
|
+
|
|
13
|
+
return (size = defaultSize) => {
|
|
14
|
+
if (size <= 0) return ''
|
|
15
|
+
let id = ''
|
|
16
|
+
while (true) {
|
|
17
|
+
let bytes = getRandom(step)
|
|
18
|
+
let j = step | 0
|
|
19
|
+
while (j--) {
|
|
20
|
+
id += alphabet[bytes[j] & mask] || ''
|
|
21
|
+
if (id.length === size) return id
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let customAlphabet = (alphabet, size = 21) =>
|
|
28
|
+
customRandom(alphabet, size, random)
|
|
29
|
+
|
|
30
|
+
let nanoid = (size = 21) =>
|
|
31
|
+
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
32
|
+
byte &= 63
|
|
33
|
+
if (byte < 36) {
|
|
34
|
+
id += byte.toString(36)
|
|
35
|
+
} else if (byte < 62) {
|
|
36
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
37
|
+
} else if (byte > 62) {
|
|
38
|
+
id += '-'
|
|
39
|
+
} else {
|
|
40
|
+
id += '_'
|
|
41
|
+
}
|
|
42
|
+
return id
|
|
43
|
+
}, '')
|
|
44
|
+
|
|
45
|
+
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
import { urlAlphabet } from './url-alphabet/index.js'
|
|
3
|
+
|
|
4
|
+
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
5
|
+
|
|
6
|
+
let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
7
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
12
|
+
|
|
13
|
+
return (size = defaultSize) => {
|
|
14
|
+
if (size <= 0) return ''
|
|
15
|
+
let id = ''
|
|
16
|
+
while (true) {
|
|
17
|
+
let bytes = getRandom(step)
|
|
18
|
+
let j = step | 0
|
|
19
|
+
while (j--) {
|
|
20
|
+
id += alphabet[bytes[j] & mask] || ''
|
|
21
|
+
if (id.length === size) return id
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let customAlphabet = (alphabet, size = 21) =>
|
|
28
|
+
customRandom(alphabet, size, random)
|
|
29
|
+
|
|
30
|
+
let nanoid = (size = 21) =>
|
|
31
|
+
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
32
|
+
byte &= 63
|
|
33
|
+
if (byte < 36) {
|
|
34
|
+
id += byte.toString(36)
|
|
35
|
+
} else if (byte < 62) {
|
|
36
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
37
|
+
} else if (byte > 62) {
|
|
38
|
+
id += '-'
|
|
39
|
+
} else {
|
|
40
|
+
id += '_'
|
|
41
|
+
}
|
|
42
|
+
return id
|
|
43
|
+
}, '')
|
|
44
|
+
|
|
45
|
+
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
let crypto = require('crypto')
|
|
2
|
+
|
|
3
|
+
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
|
4
|
+
|
|
5
|
+
const POOL_SIZE_MULTIPLIER = 128
|
|
6
|
+
let pool, poolOffset
|
|
7
|
+
|
|
8
|
+
let fillPool = bytes => {
|
|
9
|
+
if (bytes < 0 || bytes > 1024) throw new RangeError('Wrong ID size')
|
|
10
|
+
try {
|
|
11
|
+
if (!pool || pool.length < bytes) {
|
|
12
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
|
|
13
|
+
crypto.randomFillSync(pool)
|
|
14
|
+
poolOffset = 0
|
|
15
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
16
|
+
crypto.randomFillSync(pool)
|
|
17
|
+
poolOffset = 0
|
|
18
|
+
}
|
|
19
|
+
} catch (e) {
|
|
20
|
+
pool = undefined
|
|
21
|
+
throw e
|
|
22
|
+
}
|
|
23
|
+
poolOffset += bytes
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let random = bytes => {
|
|
27
|
+
fillPool((bytes |= 0))
|
|
28
|
+
return pool.subarray(poolOffset - bytes, poolOffset)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
32
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
36
|
+
|
|
37
|
+
return (size = defaultSize) => {
|
|
38
|
+
if (size <= 0) return ''
|
|
39
|
+
let id = ''
|
|
40
|
+
while (true) {
|
|
41
|
+
let bytes = getRandom(step)
|
|
42
|
+
let i = step
|
|
43
|
+
while (i--) {
|
|
44
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
45
|
+
if (id.length === size) return id
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let customAlphabet = (alphabet, size = 21) =>
|
|
52
|
+
customRandom(alphabet, size, random)
|
|
53
|
+
|
|
54
|
+
let nanoid = (size = 21) => {
|
|
55
|
+
fillPool((size |= 0))
|
|
56
|
+
let id = ''
|
|
57
|
+
for (let i = poolOffset - size; i < poolOffset; i++) {
|
|
58
|
+
id += urlAlphabet[pool[i] & 63]
|
|
59
|
+
}
|
|
60
|
+
return id
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate secure URL-friendly unique ID.
|
|
3
|
+
*
|
|
4
|
+
* By default, the ID will have 21 symbols to have a collision probability
|
|
5
|
+
* similar to UUID v4.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { nanoid } from 'nanoid'
|
|
9
|
+
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param size Size of the ID. The default size is 21.
|
|
13
|
+
* @returns A random string.
|
|
14
|
+
*/
|
|
15
|
+
export function nanoid(size?: number): string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generate secure unique ID with custom alphabet.
|
|
19
|
+
*
|
|
20
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
|
21
|
+
* will not be secure.
|
|
22
|
+
*
|
|
23
|
+
* @param alphabet Alphabet used to generate the ID.
|
|
24
|
+
* @param defaultSize Size of the ID. The default size is 21.
|
|
25
|
+
* @returns A random string generator.
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* const { customAlphabet } = require('nanoid')
|
|
29
|
+
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
|
30
|
+
* nanoid() //=> "8ё56а"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function customAlphabet(
|
|
34
|
+
alphabet: string,
|
|
35
|
+
defaultSize?: number
|
|
36
|
+
): (size?: number) => string
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate unique ID with custom random generator and alphabet.
|
|
40
|
+
*
|
|
41
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
|
42
|
+
* will not be secure.
|
|
43
|
+
*
|
|
44
|
+
* ```js
|
|
45
|
+
* import { customRandom } from 'nanoid/format'
|
|
46
|
+
*
|
|
47
|
+
* const nanoid = customRandom('abcdef', 5, size => {
|
|
48
|
+
* const random = []
|
|
49
|
+
* for (let i = 0; i < size; i++) {
|
|
50
|
+
* random.push(randomByte())
|
|
51
|
+
* }
|
|
52
|
+
* return random
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* nanoid() //=> "fbaef"
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param alphabet Alphabet used to generate a random string.
|
|
59
|
+
* @param size Size of the random string.
|
|
60
|
+
* @param random A random bytes generator.
|
|
61
|
+
* @returns A random string generator.
|
|
62
|
+
*/
|
|
63
|
+
export function customRandom(
|
|
64
|
+
alphabet: string,
|
|
65
|
+
size: number,
|
|
66
|
+
random: (bytes: number) => Uint8Array
|
|
67
|
+
): () => string
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* URL safe symbols.
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* import { urlAlphabet } from 'nanoid'
|
|
74
|
+
* const nanoid = customAlphabet(urlAlphabet, 10)
|
|
75
|
+
* nanoid() //=> "Uakgb_J5m9"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const urlAlphabet: string
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Generate an array of random bytes collected from hardware noise.
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* import { customRandom, random } from 'nanoid'
|
|
85
|
+
* const nanoid = customRandom("abcdef", 5, random)
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param bytes Size of the array.
|
|
89
|
+
* @returns An array of random bytes.
|
|
90
|
+
*/
|
|
91
|
+
export function random(bytes: number): Uint8Array
|