create-microact-app 1.0.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.
Files changed (213) hide show
  1. package/index.js +95 -0
  2. package/package.json +21 -0
  3. package/templates/vanilla/.github/workflows/deploy.yml +38 -0
  4. package/templates/vanilla/index.html +13 -0
  5. package/templates/vanilla/node_modules/.package-lock.json +207 -0
  6. package/templates/vanilla/node_modules/@esbuild/darwin-x64/README.md +3 -0
  7. package/templates/vanilla/node_modules/@esbuild/darwin-x64/bin/esbuild +0 -0
  8. package/templates/vanilla/node_modules/@esbuild/darwin-x64/package.json +17 -0
  9. package/templates/vanilla/node_modules/@monygroupcorp/microact/README.md +154 -0
  10. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.cjs.js +1749 -0
  11. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.cjs.js.map +1 -0
  12. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.esm.js +1743 -0
  13. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.esm.js.map +1 -0
  14. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.umd.js +2 -0
  15. package/templates/vanilla/node_modules/@monygroupcorp/microact/dist/microact.umd.js.map +1 -0
  16. package/templates/vanilla/node_modules/@monygroupcorp/microact/example/index.html +13 -0
  17. package/templates/vanilla/node_modules/@monygroupcorp/microact/example/index.js +63 -0
  18. package/templates/vanilla/node_modules/@monygroupcorp/microact/package.json +38 -0
  19. package/templates/vanilla/node_modules/@monygroupcorp/microact/rollup.config.cjs +30 -0
  20. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/Component.js +831 -0
  21. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/DOMUpdater.js +320 -0
  22. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/EventBus.js +123 -0
  23. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/Router.js +253 -0
  24. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/UpdateScheduler.js +218 -0
  25. package/templates/vanilla/node_modules/@monygroupcorp/microact/src/index.js +6 -0
  26. package/templates/vanilla/node_modules/esbuild/LICENSE.md +21 -0
  27. package/templates/vanilla/node_modules/esbuild/README.md +3 -0
  28. package/templates/vanilla/node_modules/esbuild/bin/esbuild +0 -0
  29. package/templates/vanilla/node_modules/esbuild/install.js +287 -0
  30. package/templates/vanilla/node_modules/esbuild/lib/main.d.ts +660 -0
  31. package/templates/vanilla/node_modules/esbuild/lib/main.js +2393 -0
  32. package/templates/vanilla/node_modules/esbuild/package.json +42 -0
  33. package/templates/vanilla/node_modules/nanoid/LICENSE +20 -0
  34. package/templates/vanilla/node_modules/nanoid/README.md +39 -0
  35. package/templates/vanilla/node_modules/nanoid/async/index.browser.cjs +69 -0
  36. package/templates/vanilla/node_modules/nanoid/async/index.browser.js +34 -0
  37. package/templates/vanilla/node_modules/nanoid/async/index.cjs +71 -0
  38. package/templates/vanilla/node_modules/nanoid/async/index.d.ts +56 -0
  39. package/templates/vanilla/node_modules/nanoid/async/index.js +35 -0
  40. package/templates/vanilla/node_modules/nanoid/async/index.native.js +26 -0
  41. package/templates/vanilla/node_modules/nanoid/async/package.json +12 -0
  42. package/templates/vanilla/node_modules/nanoid/bin/nanoid.cjs +55 -0
  43. package/templates/vanilla/node_modules/nanoid/index.browser.cjs +72 -0
  44. package/templates/vanilla/node_modules/nanoid/index.browser.js +34 -0
  45. package/templates/vanilla/node_modules/nanoid/index.cjs +85 -0
  46. package/templates/vanilla/node_modules/nanoid/index.d.cts +91 -0
  47. package/templates/vanilla/node_modules/nanoid/index.d.ts +91 -0
  48. package/templates/vanilla/node_modules/nanoid/index.js +45 -0
  49. package/templates/vanilla/node_modules/nanoid/nanoid.js +1 -0
  50. package/templates/vanilla/node_modules/nanoid/non-secure/index.cjs +34 -0
  51. package/templates/vanilla/node_modules/nanoid/non-secure/index.d.ts +33 -0
  52. package/templates/vanilla/node_modules/nanoid/non-secure/index.js +21 -0
  53. package/templates/vanilla/node_modules/nanoid/non-secure/package.json +6 -0
  54. package/templates/vanilla/node_modules/nanoid/package.json +89 -0
  55. package/templates/vanilla/node_modules/nanoid/url-alphabet/index.cjs +7 -0
  56. package/templates/vanilla/node_modules/nanoid/url-alphabet/index.js +3 -0
  57. package/templates/vanilla/node_modules/nanoid/url-alphabet/package.json +6 -0
  58. package/templates/vanilla/node_modules/picocolors/LICENSE +15 -0
  59. package/templates/vanilla/node_modules/picocolors/README.md +21 -0
  60. package/templates/vanilla/node_modules/picocolors/package.json +25 -0
  61. package/templates/vanilla/node_modules/picocolors/picocolors.browser.js +4 -0
  62. package/templates/vanilla/node_modules/picocolors/picocolors.d.ts +5 -0
  63. package/templates/vanilla/node_modules/picocolors/picocolors.js +75 -0
  64. package/templates/vanilla/node_modules/picocolors/types.d.ts +51 -0
  65. package/templates/vanilla/node_modules/postcss/LICENSE +20 -0
  66. package/templates/vanilla/node_modules/postcss/README.md +29 -0
  67. package/templates/vanilla/node_modules/postcss/lib/at-rule.d.ts +140 -0
  68. package/templates/vanilla/node_modules/postcss/lib/at-rule.js +25 -0
  69. package/templates/vanilla/node_modules/postcss/lib/comment.d.ts +68 -0
  70. package/templates/vanilla/node_modules/postcss/lib/comment.js +13 -0
  71. package/templates/vanilla/node_modules/postcss/lib/container.d.ts +483 -0
  72. package/templates/vanilla/node_modules/postcss/lib/container.js +447 -0
  73. package/templates/vanilla/node_modules/postcss/lib/css-syntax-error.d.ts +248 -0
  74. package/templates/vanilla/node_modules/postcss/lib/css-syntax-error.js +133 -0
  75. package/templates/vanilla/node_modules/postcss/lib/declaration.d.ts +151 -0
  76. package/templates/vanilla/node_modules/postcss/lib/declaration.js +24 -0
  77. package/templates/vanilla/node_modules/postcss/lib/document.d.ts +69 -0
  78. package/templates/vanilla/node_modules/postcss/lib/document.js +33 -0
  79. package/templates/vanilla/node_modules/postcss/lib/fromJSON.d.ts +9 -0
  80. package/templates/vanilla/node_modules/postcss/lib/fromJSON.js +54 -0
  81. package/templates/vanilla/node_modules/postcss/lib/input.d.ts +227 -0
  82. package/templates/vanilla/node_modules/postcss/lib/input.js +265 -0
  83. package/templates/vanilla/node_modules/postcss/lib/lazy-result.d.ts +190 -0
  84. package/templates/vanilla/node_modules/postcss/lib/lazy-result.js +550 -0
  85. package/templates/vanilla/node_modules/postcss/lib/list.d.ts +60 -0
  86. package/templates/vanilla/node_modules/postcss/lib/list.js +58 -0
  87. package/templates/vanilla/node_modules/postcss/lib/map-generator.js +368 -0
  88. package/templates/vanilla/node_modules/postcss/lib/no-work-result.d.ts +46 -0
  89. package/templates/vanilla/node_modules/postcss/lib/no-work-result.js +138 -0
  90. package/templates/vanilla/node_modules/postcss/lib/node.d.ts +556 -0
  91. package/templates/vanilla/node_modules/postcss/lib/node.js +449 -0
  92. package/templates/vanilla/node_modules/postcss/lib/parse.d.ts +9 -0
  93. package/templates/vanilla/node_modules/postcss/lib/parse.js +42 -0
  94. package/templates/vanilla/node_modules/postcss/lib/parser.js +611 -0
  95. package/templates/vanilla/node_modules/postcss/lib/postcss.d.mts +69 -0
  96. package/templates/vanilla/node_modules/postcss/lib/postcss.d.ts +458 -0
  97. package/templates/vanilla/node_modules/postcss/lib/postcss.js +101 -0
  98. package/templates/vanilla/node_modules/postcss/lib/postcss.mjs +30 -0
  99. package/templates/vanilla/node_modules/postcss/lib/previous-map.d.ts +81 -0
  100. package/templates/vanilla/node_modules/postcss/lib/previous-map.js +144 -0
  101. package/templates/vanilla/node_modules/postcss/lib/processor.d.ts +115 -0
  102. package/templates/vanilla/node_modules/postcss/lib/processor.js +67 -0
  103. package/templates/vanilla/node_modules/postcss/lib/result.d.ts +205 -0
  104. package/templates/vanilla/node_modules/postcss/lib/result.js +42 -0
  105. package/templates/vanilla/node_modules/postcss/lib/root.d.ts +87 -0
  106. package/templates/vanilla/node_modules/postcss/lib/root.js +61 -0
  107. package/templates/vanilla/node_modules/postcss/lib/rule.d.ts +126 -0
  108. package/templates/vanilla/node_modules/postcss/lib/rule.js +27 -0
  109. package/templates/vanilla/node_modules/postcss/lib/stringifier.d.ts +46 -0
  110. package/templates/vanilla/node_modules/postcss/lib/stringifier.js +353 -0
  111. package/templates/vanilla/node_modules/postcss/lib/stringify.d.ts +9 -0
  112. package/templates/vanilla/node_modules/postcss/lib/stringify.js +11 -0
  113. package/templates/vanilla/node_modules/postcss/lib/symbols.js +5 -0
  114. package/templates/vanilla/node_modules/postcss/lib/terminal-highlight.js +70 -0
  115. package/templates/vanilla/node_modules/postcss/lib/tokenize.js +266 -0
  116. package/templates/vanilla/node_modules/postcss/lib/warn-once.js +13 -0
  117. package/templates/vanilla/node_modules/postcss/lib/warning.d.ts +147 -0
  118. package/templates/vanilla/node_modules/postcss/lib/warning.js +37 -0
  119. package/templates/vanilla/node_modules/postcss/package.json +88 -0
  120. package/templates/vanilla/node_modules/rollup/LICENSE.md +695 -0
  121. package/templates/vanilla/node_modules/rollup/README.md +125 -0
  122. package/templates/vanilla/node_modules/rollup/dist/bin/rollup +1715 -0
  123. package/templates/vanilla/node_modules/rollup/dist/es/getLogFilter.js +64 -0
  124. package/templates/vanilla/node_modules/rollup/dist/es/package.json +1 -0
  125. package/templates/vanilla/node_modules/rollup/dist/es/rollup.js +17 -0
  126. package/templates/vanilla/node_modules/rollup/dist/es/shared/node-entry.js +27273 -0
  127. package/templates/vanilla/node_modules/rollup/dist/es/shared/watch.js +4857 -0
  128. package/templates/vanilla/node_modules/rollup/dist/getLogFilter.d.ts +5 -0
  129. package/templates/vanilla/node_modules/rollup/dist/getLogFilter.js +69 -0
  130. package/templates/vanilla/node_modules/rollup/dist/loadConfigFile.d.ts +20 -0
  131. package/templates/vanilla/node_modules/rollup/dist/loadConfigFile.js +29 -0
  132. package/templates/vanilla/node_modules/rollup/dist/rollup.d.ts +1012 -0
  133. package/templates/vanilla/node_modules/rollup/dist/rollup.js +31 -0
  134. package/templates/vanilla/node_modules/rollup/dist/shared/fsevents-importer.js +37 -0
  135. package/templates/vanilla/node_modules/rollup/dist/shared/index.js +4571 -0
  136. package/templates/vanilla/node_modules/rollup/dist/shared/loadConfigFile.js +546 -0
  137. package/templates/vanilla/node_modules/rollup/dist/shared/rollup.js +27351 -0
  138. package/templates/vanilla/node_modules/rollup/dist/shared/watch-cli.js +561 -0
  139. package/templates/vanilla/node_modules/rollup/dist/shared/watch-proxy.js +87 -0
  140. package/templates/vanilla/node_modules/rollup/dist/shared/watch.js +316 -0
  141. package/templates/vanilla/node_modules/rollup/package.json +181 -0
  142. package/templates/vanilla/node_modules/source-map-js/LICENSE +28 -0
  143. package/templates/vanilla/node_modules/source-map-js/README.md +765 -0
  144. package/templates/vanilla/node_modules/source-map-js/lib/array-set.js +121 -0
  145. package/templates/vanilla/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  146. package/templates/vanilla/node_modules/source-map-js/lib/base64.js +67 -0
  147. package/templates/vanilla/node_modules/source-map-js/lib/binary-search.js +111 -0
  148. package/templates/vanilla/node_modules/source-map-js/lib/mapping-list.js +79 -0
  149. package/templates/vanilla/node_modules/source-map-js/lib/quick-sort.js +132 -0
  150. package/templates/vanilla/node_modules/source-map-js/lib/source-map-consumer.d.ts +1 -0
  151. package/templates/vanilla/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  152. package/templates/vanilla/node_modules/source-map-js/lib/source-map-generator.d.ts +1 -0
  153. package/templates/vanilla/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  154. package/templates/vanilla/node_modules/source-map-js/lib/source-node.d.ts +1 -0
  155. package/templates/vanilla/node_modules/source-map-js/lib/source-node.js +413 -0
  156. package/templates/vanilla/node_modules/source-map-js/lib/util.js +594 -0
  157. package/templates/vanilla/node_modules/source-map-js/package.json +71 -0
  158. package/templates/vanilla/node_modules/source-map-js/source-map.d.ts +104 -0
  159. package/templates/vanilla/node_modules/source-map-js/source-map.js +8 -0
  160. package/templates/vanilla/node_modules/vite/LICENSE.md +3396 -0
  161. package/templates/vanilla/node_modules/vite/README.md +20 -0
  162. package/templates/vanilla/node_modules/vite/bin/openChrome.applescript +95 -0
  163. package/templates/vanilla/node_modules/vite/bin/vite.js +61 -0
  164. package/templates/vanilla/node_modules/vite/client.d.ts +281 -0
  165. package/templates/vanilla/node_modules/vite/dist/client/client.mjs +725 -0
  166. package/templates/vanilla/node_modules/vite/dist/client/client.mjs.map +1 -0
  167. package/templates/vanilla/node_modules/vite/dist/client/env.mjs +30 -0
  168. package/templates/vanilla/node_modules/vite/dist/client/env.mjs.map +1 -0
  169. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-7ec6f216.js +914 -0
  170. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-827b23df.js +66713 -0
  171. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-c423598f.js +561 -0
  172. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-f0c7dae0.js +7930 -0
  173. package/templates/vanilla/node_modules/vite/dist/node/chunks/dep-f1e8587f.js +7646 -0
  174. package/templates/vanilla/node_modules/vite/dist/node/cli.js +929 -0
  175. package/templates/vanilla/node_modules/vite/dist/node/constants.js +130 -0
  176. package/templates/vanilla/node_modules/vite/dist/node/index.d.ts +3548 -0
  177. package/templates/vanilla/node_modules/vite/dist/node/index.js +158 -0
  178. package/templates/vanilla/node_modules/vite/dist/node-cjs/publicUtils.cjs +4555 -0
  179. package/templates/vanilla/node_modules/vite/index.cjs +34 -0
  180. package/templates/vanilla/node_modules/vite/package.json +173 -0
  181. package/templates/vanilla/node_modules/vite/types/customEvent.d.ts +35 -0
  182. package/templates/vanilla/node_modules/vite/types/hmrPayload.d.ts +61 -0
  183. package/templates/vanilla/node_modules/vite/types/hot.d.ts +32 -0
  184. package/templates/vanilla/node_modules/vite/types/importGlob.d.ts +97 -0
  185. package/templates/vanilla/node_modules/vite/types/importMeta.d.ts +26 -0
  186. package/templates/vanilla/node_modules/vite/types/metadata.d.ts +10 -0
  187. package/templates/vanilla/node_modules/vite/types/package.json +4 -0
  188. package/templates/vanilla/package-lock.json +589 -0
  189. package/templates/vanilla/package.json +17 -0
  190. package/templates/vanilla/src/components/App.js +60 -0
  191. package/templates/vanilla/src/components/Card.js +21 -0
  192. package/templates/vanilla/src/components/Hero.js +15 -0
  193. package/templates/vanilla/src/components/InteractiveDemo.js +59 -0
  194. package/templates/vanilla/src/main.js +9 -0
  195. package/templates/vanilla/src/style/main.css +172 -0
  196. package/templates/vanilla/vite.config.js +8 -0
  197. package/templates/web3/.env.example +15 -0
  198. package/templates/web3/.github/workflows/deploy.yml +38 -0
  199. package/templates/web3/README.md +33 -0
  200. package/templates/web3/contracts/foundry.toml +11 -0
  201. package/templates/web3/contracts/script/Deploy.s.sol +13 -0
  202. package/templates/web3/contracts/src/Counter.sol +21 -0
  203. package/templates/web3/index.html +13 -0
  204. package/templates/web3/package.json +25 -0
  205. package/templates/web3/scripts/chain-start.mjs +305 -0
  206. package/templates/web3/scripts/chain-stop.mjs +34 -0
  207. package/templates/web3/scripts/deploy.mjs +155 -0
  208. package/templates/web3/scripts/setup.mjs +42 -0
  209. package/templates/web3/src/components/App.js +49 -0
  210. package/templates/web3/src/components/CounterCard.js +111 -0
  211. package/templates/web3/src/main.js +54 -0
  212. package/templates/web3/src/style/main.css +345 -0
  213. package/templates/web3/vite.config.js +29 -0
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "esbuild",
3
+ "version": "0.18.20",
4
+ "description": "An extremely fast JavaScript and CSS bundler and minifier.",
5
+ "repository": "https://github.com/evanw/esbuild",
6
+ "scripts": {
7
+ "postinstall": "node install.js"
8
+ },
9
+ "main": "lib/main.js",
10
+ "types": "lib/main.d.ts",
11
+ "engines": {
12
+ "node": ">=12"
13
+ },
14
+ "bin": {
15
+ "esbuild": "bin/esbuild"
16
+ },
17
+ "optionalDependencies": {
18
+ "@esbuild/android-arm": "0.18.20",
19
+ "@esbuild/android-arm64": "0.18.20",
20
+ "@esbuild/android-x64": "0.18.20",
21
+ "@esbuild/darwin-arm64": "0.18.20",
22
+ "@esbuild/darwin-x64": "0.18.20",
23
+ "@esbuild/freebsd-arm64": "0.18.20",
24
+ "@esbuild/freebsd-x64": "0.18.20",
25
+ "@esbuild/linux-arm": "0.18.20",
26
+ "@esbuild/linux-arm64": "0.18.20",
27
+ "@esbuild/linux-ia32": "0.18.20",
28
+ "@esbuild/linux-loong64": "0.18.20",
29
+ "@esbuild/linux-mips64el": "0.18.20",
30
+ "@esbuild/linux-ppc64": "0.18.20",
31
+ "@esbuild/linux-riscv64": "0.18.20",
32
+ "@esbuild/linux-s390x": "0.18.20",
33
+ "@esbuild/linux-x64": "0.18.20",
34
+ "@esbuild/netbsd-x64": "0.18.20",
35
+ "@esbuild/openbsd-x64": "0.18.20",
36
+ "@esbuild/sunos-x64": "0.18.20",
37
+ "@esbuild/win32-arm64": "0.18.20",
38
+ "@esbuild/win32-ia32": "0.18.20",
39
+ "@esbuild/win32-x64": "0.18.20"
40
+ },
41
+ "license": "MIT"
42
+ }
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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,69 @@
1
+ let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
2
+
3
+ let customAlphabet = (alphabet, defaultSize = 21) => {
4
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
5
+ // values closer to the alphabet size. The bitmask calculates the closest
6
+ // `2^31 - 1` number, which exceeds the alphabet size.
7
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
8
+ // `Math.clz32` is not used, because it is not available in browsers.
9
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
10
+ // Though, the bitmask solution is not perfect since the bytes exceeding
11
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
12
+ // the random bytes redundancy has to be satisfied.
13
+
14
+ // Note: every hardware random generator call is performance expensive,
15
+ // because the system call for entropy collection takes a lot of time.
16
+ // So, to avoid additional system calls, extra bytes are requested in advance.
17
+
18
+ // Next, a step determines how many random bytes to generate.
19
+ // The number of random bytes gets decided upon the ID size, mask,
20
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
21
+ // according to benchmarks).
22
+
23
+ // `-~f => Math.ceil(f)` if f is a float
24
+ // `-~i => i + 1` if i is an integer
25
+ let step = -~((1.6 * mask * defaultSize) / alphabet.length)
26
+
27
+ return async (size = defaultSize) => {
28
+ let id = ''
29
+ while (true) {
30
+ let bytes = crypto.getRandomValues(new Uint8Array(step))
31
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
32
+ let i = step | 0
33
+ while (i--) {
34
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
35
+ id += alphabet[bytes[i] & mask] || ''
36
+ if (id.length === size) return id
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ let nanoid = async (size = 21) => {
43
+ let id = ''
44
+ let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
45
+
46
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
47
+ while (size--) {
48
+ // It is incorrect to use bytes exceeding the alphabet size.
49
+ // The following mask reduces the random byte in the 0-255 value
50
+ // range to the 0-63 value range. Therefore, adding hacks, such
51
+ // as empty string fallback or magic numbers, is unneccessary because
52
+ // the bitmask trims bytes down to the alphabet size.
53
+ let byte = bytes[size] & 63
54
+ if (byte < 36) {
55
+ // `0-9a-z`
56
+ id += byte.toString(36)
57
+ } else if (byte < 62) {
58
+ // `A-Z`
59
+ id += (byte - 26).toString(36).toUpperCase()
60
+ } else if (byte < 63) {
61
+ id += '_'
62
+ } else {
63
+ id += '-'
64
+ }
65
+ }
66
+ return id
67
+ }
68
+
69
+ module.exports = { nanoid, customAlphabet, random }
@@ -0,0 +1,34 @@
1
+ let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
2
+ let customAlphabet = (alphabet, defaultSize = 21) => {
3
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
4
+ let step = -~((1.6 * mask * defaultSize) / alphabet.length)
5
+ return async (size = defaultSize) => {
6
+ let id = ''
7
+ while (true) {
8
+ let bytes = crypto.getRandomValues(new Uint8Array(step))
9
+ let i = step | 0
10
+ while (i--) {
11
+ id += alphabet[bytes[i] & mask] || ''
12
+ if (id.length === size) return id
13
+ }
14
+ }
15
+ }
16
+ }
17
+ let nanoid = async (size = 21) => {
18
+ let id = ''
19
+ let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
20
+ while (size--) {
21
+ let byte = bytes[size] & 63
22
+ if (byte < 36) {
23
+ id += byte.toString(36)
24
+ } else if (byte < 62) {
25
+ id += (byte - 26).toString(36).toUpperCase()
26
+ } else if (byte < 63) {
27
+ id += '_'
28
+ } else {
29
+ id += '-'
30
+ }
31
+ }
32
+ return id
33
+ }
34
+ export { nanoid, customAlphabet, random }
@@ -0,0 +1,71 @@
1
+ let crypto = require('crypto')
2
+
3
+ let { urlAlphabet } = require('../url-alphabet/index.cjs')
4
+
5
+ // `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
6
+ // because it is possible to use in combination with `Buffer.allocUnsafe()`.
7
+ let random = bytes =>
8
+ new Promise((resolve, reject) => {
9
+ // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
10
+ // Memory flushing is unnecessary since the buffer allocation itself resets
11
+ // the memory with the new bytes.
12
+ crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
13
+ if (err) {
14
+ reject(err)
15
+ } else {
16
+ resolve(buf)
17
+ }
18
+ })
19
+ })
20
+
21
+ let customAlphabet = (alphabet, defaultSize = 21) => {
22
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
23
+ // values closer to the alphabet size. The bitmask calculates the closest
24
+ // `2^31 - 1` number, which exceeds the alphabet size.
25
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
26
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
27
+ // Though, the bitmask solution is not perfect since the bytes exceeding
28
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
29
+ // the random bytes redundancy has to be satisfied.
30
+
31
+ // Note: every hardware random generator call is performance expensive,
32
+ // because the system call for entropy collection takes a lot of time.
33
+ // So, to avoid additional system calls, extra bytes are requested in advance.
34
+
35
+ // Next, a step determines how many random bytes to generate.
36
+ // The number of random bytes gets decided upon the ID size, mask,
37
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
38
+ // according to benchmarks).
39
+ let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
40
+
41
+ let tick = (id, size = defaultSize) =>
42
+ random(step).then(bytes => {
43
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
44
+ let i = step
45
+ while (i--) {
46
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
47
+ id += alphabet[bytes[i] & mask] || ''
48
+ if (id.length >= size) return id
49
+ }
50
+ return tick(id, size)
51
+ })
52
+
53
+ return size => tick('', size)
54
+ }
55
+
56
+ let nanoid = (size = 21) =>
57
+ random((size |= 0)).then(bytes => {
58
+ let id = ''
59
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
60
+ while (size--) {
61
+ // It is incorrect to use bytes exceeding the alphabet size.
62
+ // The following mask reduces the random byte in the 0-255 value
63
+ // range to the 0-63 value range. Therefore, adding hacks, such
64
+ // as empty string fallback or magic numbers, is unneccessary because
65
+ // the bitmask trims bytes down to the alphabet size.
66
+ id += urlAlphabet[bytes[size] & 63]
67
+ }
68
+ return id
69
+ })
70
+
71
+ 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,35 @@
1
+ import crypto from 'crypto'
2
+ import { urlAlphabet } from '../url-alphabet/index.js'
3
+ let random = bytes =>
4
+ new Promise((resolve, reject) => {
5
+ crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
6
+ if (err) {
7
+ reject(err)
8
+ } else {
9
+ resolve(buf)
10
+ }
11
+ })
12
+ })
13
+ let customAlphabet = (alphabet, defaultSize = 21) => {
14
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
15
+ let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
16
+ let tick = (id, size = defaultSize) =>
17
+ random(step).then(bytes => {
18
+ let i = step
19
+ while (i--) {
20
+ id += alphabet[bytes[i] & mask] || ''
21
+ if (id.length >= size) return id
22
+ }
23
+ return tick(id, size)
24
+ })
25
+ return size => tick('', size)
26
+ }
27
+ let nanoid = (size = 21) =>
28
+ random((size |= 0)).then(bytes => {
29
+ let id = ''
30
+ while (size--) {
31
+ id += urlAlphabet[bytes[size] & 63]
32
+ }
33
+ return id
34
+ })
35
+ export { nanoid, customAlphabet, random }
@@ -0,0 +1,26 @@
1
+ import { getRandomBytesAsync } from 'expo-random'
2
+ import { urlAlphabet } from '../url-alphabet/index.js'
3
+ let random = getRandomBytesAsync
4
+ let customAlphabet = (alphabet, defaultSize = 21) => {
5
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
6
+ let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
7
+ let tick = (id, size = defaultSize) =>
8
+ random(step).then(bytes => {
9
+ let i = step
10
+ while (i--) {
11
+ id += alphabet[bytes[i] & mask] || ''
12
+ if (id.length >= size) return id
13
+ }
14
+ return tick(id, size)
15
+ })
16
+ return size => tick('', size)
17
+ }
18
+ let nanoid = (size = 21) =>
19
+ random((size |= 0)).then(bytes => {
20
+ let id = ''
21
+ while (size--) {
22
+ id += urlAlphabet[bytes[size] & 63]
23
+ }
24
+ return id
25
+ })
26
+ export { nanoid, customAlphabet, random }
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "module",
3
+ "main": "index.cjs",
4
+ "module": "index.js",
5
+ "react-native": {
6
+ "./index.js": "./index.native.js"
7
+ },
8
+ "browser": {
9
+ "./index.js": "./index.browser.js",
10
+ "./index.cjs": "./index.browser.cjs"
11
+ }
12
+ }
@@ -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,72 @@
1
+ // This file replaces `index.js` in bundlers like webpack or Rollup,
2
+ // according to `browser` config in `package.json`.
3
+
4
+ let { urlAlphabet } = require('./url-alphabet/index.cjs')
5
+
6
+ let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
7
+
8
+ let customRandom = (alphabet, defaultSize, getRandom) => {
9
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
10
+ // values closer to the alphabet size. The bitmask calculates the closest
11
+ // `2^31 - 1` number, which exceeds the alphabet size.
12
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
13
+ // `Math.clz32` is not used, because it is not available in browsers.
14
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
15
+ // Though, the bitmask solution is not perfect since the bytes exceeding
16
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
17
+ // the random bytes redundancy has to be satisfied.
18
+
19
+ // Note: every hardware random generator call is performance expensive,
20
+ // because the system call for entropy collection takes a lot of time.
21
+ // So, to avoid additional system calls, extra bytes are requested in advance.
22
+
23
+ // Next, a step determines how many random bytes to generate.
24
+ // The number of random bytes gets decided upon the ID size, mask,
25
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
26
+ // according to benchmarks).
27
+
28
+ // `-~f => Math.ceil(f)` if f is a float
29
+ // `-~i => i + 1` if i is an integer
30
+ let step = -~((1.6 * mask * defaultSize) / alphabet.length)
31
+
32
+ return (size = defaultSize) => {
33
+ let id = ''
34
+ while (true) {
35
+ let bytes = getRandom(step)
36
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
37
+ let j = step | 0
38
+ while (j--) {
39
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
40
+ id += alphabet[bytes[j] & mask] || ''
41
+ if (id.length === size) return id
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ let customAlphabet = (alphabet, size = 21) =>
48
+ customRandom(alphabet, size, random)
49
+
50
+ let nanoid = (size = 21) =>
51
+ crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
52
+ // It is incorrect to use bytes exceeding the alphabet size.
53
+ // The following mask reduces the random byte in the 0-255 value
54
+ // range to the 0-63 value range. Therefore, adding hacks, such
55
+ // as empty string fallback or magic numbers, is unneccessary because
56
+ // the bitmask trims bytes down to the alphabet size.
57
+ byte &= 63
58
+ if (byte < 36) {
59
+ // `0-9a-z`
60
+ id += byte.toString(36)
61
+ } else if (byte < 62) {
62
+ // `A-Z`
63
+ id += (byte - 26).toString(36).toUpperCase()
64
+ } else if (byte > 62) {
65
+ id += '-'
66
+ } else {
67
+ id += '_'
68
+ }
69
+ return id
70
+ }, '')
71
+
72
+ module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -0,0 +1,34 @@
1
+ import { urlAlphabet } from './url-alphabet/index.js'
2
+ let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
3
+ let customRandom = (alphabet, defaultSize, getRandom) => {
4
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
5
+ let step = -~((1.6 * mask * defaultSize) / alphabet.length)
6
+ return (size = defaultSize) => {
7
+ let id = ''
8
+ while (true) {
9
+ let bytes = getRandom(step)
10
+ let j = step | 0
11
+ while (j--) {
12
+ id += alphabet[bytes[j] & mask] || ''
13
+ if (id.length === size) return id
14
+ }
15
+ }
16
+ }
17
+ }
18
+ let customAlphabet = (alphabet, size = 21) =>
19
+ customRandom(alphabet, size, random)
20
+ let nanoid = (size = 21) =>
21
+ crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
22
+ byte &= 63
23
+ if (byte < 36) {
24
+ id += byte.toString(36)
25
+ } else if (byte < 62) {
26
+ id += (byte - 26).toString(36).toUpperCase()
27
+ } else if (byte > 62) {
28
+ id += '-'
29
+ } else {
30
+ id += '_'
31
+ }
32
+ return id
33
+ }, '')
34
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -0,0 +1,85 @@
1
+ let crypto = require('crypto')
2
+
3
+ let { urlAlphabet } = require('./url-alphabet/index.cjs')
4
+
5
+ // It is best to make fewer, larger requests to the crypto module to
6
+ // avoid system call overhead. So, random numbers are generated in a
7
+ // pool. The pool is a Buffer that is larger than the initial random
8
+ // request size by this multiplier. The pool is enlarged if subsequent
9
+ // requests exceed the maximum buffer size.
10
+ const POOL_SIZE_MULTIPLIER = 128
11
+ let pool, poolOffset
12
+
13
+ let fillPool = bytes => {
14
+ if (!pool || pool.length < bytes) {
15
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
16
+ crypto.randomFillSync(pool)
17
+ poolOffset = 0
18
+ } else if (poolOffset + bytes > pool.length) {
19
+ crypto.randomFillSync(pool)
20
+ poolOffset = 0
21
+ }
22
+ poolOffset += bytes
23
+ }
24
+
25
+ let random = bytes => {
26
+ // `|=` convert `bytes` to number to prevent `valueOf` abusing and pool pollution
27
+ fillPool((bytes |= 0))
28
+ return pool.subarray(poolOffset - bytes, poolOffset)
29
+ }
30
+
31
+ let customRandom = (alphabet, defaultSize, getRandom) => {
32
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
33
+ // values closer to the alphabet size. The bitmask calculates the closest
34
+ // `2^31 - 1` number, which exceeds the alphabet size.
35
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
36
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
37
+ // Though, the bitmask solution is not perfect since the bytes exceeding
38
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
39
+ // the random bytes redundancy has to be satisfied.
40
+
41
+ // Note: every hardware random generator call is performance expensive,
42
+ // because the system call for entropy collection takes a lot of time.
43
+ // So, to avoid additional system calls, extra bytes are requested in advance.
44
+
45
+ // Next, a step determines how many random bytes to generate.
46
+ // The number of random bytes gets decided upon the ID size, mask,
47
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
48
+ // according to benchmarks).
49
+ let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
50
+
51
+ return (size = defaultSize) => {
52
+ let id = ''
53
+ while (true) {
54
+ let bytes = getRandom(step)
55
+ // A compact alternative for `for (let i = 0; i < step; i++)`.
56
+ let i = step
57
+ while (i--) {
58
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
59
+ id += alphabet[bytes[i] & mask] || ''
60
+ if (id.length === size) return id
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ let customAlphabet = (alphabet, size = 21) =>
67
+ customRandom(alphabet, size, random)
68
+
69
+ let nanoid = (size = 21) => {
70
+ // `|=` convert `size` to number to prevent `valueOf` abusing and pool pollution
71
+ fillPool((size |= 0))
72
+ let id = ''
73
+ // We are reading directly from the random pool to avoid creating new array
74
+ for (let i = poolOffset - size; i < poolOffset; i++) {
75
+ // It is incorrect to use bytes exceeding the alphabet size.
76
+ // The following mask reduces the random byte in the 0-255 value
77
+ // range to the 0-63 value range. Therefore, adding hacks, such
78
+ // as empty string fallback or magic numbers, is unneccessary because
79
+ // the bitmask trims bytes down to the alphabet size.
80
+ id += urlAlphabet[pool[i] & 63]
81
+ }
82
+ return id
83
+ }
84
+
85
+ module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }