You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// generate() throws on invalid config — use try/catch if you pass dynamic input
137
+
try {
138
+
generate({ total:1000 })
139
+
} catch (err) {
140
+
console.error('Invalid config:', err.message)
141
+
}
142
+
```
143
+
144
+
Stable deep import:
145
+
146
+
```js
147
+
importgeneratefrom'puid-js/generate'
148
+
```
149
+
70
150
**Entropy Source**
71
151
72
152
`puid-js` uses `crypto.randomBytes` as the default entropy source. Options can be used to configure a specific entropy source:
@@ -86,7 +166,7 @@ randId()
86
166
87
167
**ID Characters**
88
168
89
-
By default, `puid-js`use the [RFC 4648](https://tools.ietf.org/html/rfc4648#section-5) file system & URL safe characters. The `chars` option can by used to specify any of 16[pre-defined character sets](#Chars) or custom characters, including Unicode:
169
+
By default, `puid-js`uses the [RFC 4648](https://tools.ietf.org/html/rfc4648#section-5) file system & URL safe characters. The `chars` option can be used to specify any of 19[pre-defined character sets](#Chars) or custom characters, including Unicode:
90
170
91
171
```js
92
172
const { Chars, puid } =require('puid-js')
@@ -138,15 +218,37 @@ token()
138
218
yarn add puid-js
139
219
```
140
220
221
+
Requires Node.js >= 18.
222
+
141
223
#### NPM
142
224
143
225
```bash
144
226
npm install puid-js
145
227
```
146
228
229
+
### Browser (ESM)
230
+
231
+
Note: Many bundlers honor the "browser" export condition. Importing `puid-js` in a browser build will resolve to the web entry automatically. You can also import explicitly from `puid-js/web`.
`puid-js` exports a higher-order function (HOF), `puid`, used to create random ID generators. The `puid` HOF takes an optional `PuidConfig` object for configuration and returns an object of the form `{ generator: () => string, error: Error }` that either passes back the `puid` generating function or an `Error` indicating a problem with the specified configuration.
246
+
`puid-js` exports:
247
+
248
+
-`puid(config?) => { generator, error }` — higher-order function (HOF) to create generators
249
+
-`generate(config?) => string` — convenience wrapper returning a single ID (throws on invalid config)
250
+
251
+
The `puid` HOF takes an optional `PuidConfig` object for configuration and returns an object of the form `{ generator: () => string, error: Error }` that either passes back the `puid` generating function or an `Error` indicating a problem with the specified configuration.
150
252
151
253
#### PuidConfig
152
254
@@ -213,7 +315,7 @@ There are 19 pre-defined character sets:
0 commit comments