A tiny (190B) and extremely fast utility to generate random IDs of fixed length
Installations
npm install hexoid
Contributors
Developer
lukeed
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
>=8
Typescript Support
Yes
Node Version
20.10.0
NPM Version
10.2.3
Statistics
195 Stars
25 Commits
6 Forks
3 Watching
1 Branches
2 Contributors
Updated on 06 Nov 2024
Bundle Size
427.00 B
Minified
293.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
616,908,334
Last day
-11.6%
1,374,930
Compared to previous day
Last week
1.9%
7,415,247
Compared to previous week
Last month
17.4%
31,090,307
Compared to previous month
Last year
37.7%
304,931,999
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
hexoid
A tiny (190B) and extremely fast utility to generate random IDs of fixed length
Hexadecimal object IDs. Available for Node.js and the browser.
Generate randomized output strings of fixed length using lowercased hexadecimal pairs.
Notice: Please note that this is not a cryptographically secure (CSPRNG) generator.
Additionally, this module is delivered as:
- CommonJS:
dist/index.js
- ES Module:
dist/index.mjs
Install
$ npm install --save hexoid
Usage
1import { hexoid } from 'hexoid'; 2 3const toID = hexoid(); 4// length = 16 (default) 5toID(); //=> '52032fedb951da00' 6toID(); //=> '52032fedb951da01' 7toID(); //=> '52032fedb951da02' 8 9// customize length 10hexoid(25)(); //=> '065359875047c63a037200e00' 11hexoid(32)(); //=> 'ca8e4aec7f139d94fcab9cab2eb89f00' 12hexoid(48)(); //=> 'c19a4deb5cdeca68534930e67bd0a2f4ed45988724d8d200'
API
hexoid(length?)
Returns: () => string
Creates the function that will generate strings.
length
Type: Number
Default: 16
Then length of the output string.
Important: Your risk of collisions decreases with longer strings!
Please be aware of the Birthday Problem! You may need more combinations than you'd expect.
The maximum combinations are known given the following formula:
1const combos = 256 ** (len/2);
Benchmarks
Running on Node.js v10.13.0
Validation (length = 16):
✔ hashids/fixed (example: "LkQWjnegYbwZ1p0G")
✔ nanoid/non-secure (example: "sLlVL5X3M5k2fo58")
✔ uid (example: "3d0ckwcnjiuu91hj")
✔ hexoid (example: "de96b62e663ef300")
Benchmark (length = 16):
hashids/fixed x 349,462 ops/sec ±0.28% (93 runs sampled)
nanoid/non-secure x 3,337,573 ops/sec ±0.28% (96 runs sampled)
uid x 3,553,482 ops/sec ±0.51% (90 runs sampled)
hexoid x 81,081,364 ops/sec ±0.18% (96 runs sampled)
Validation (length = 25):
✔ cuid (example: "ck7lj5hbf00000v7c9gox6yfh")
✔ hashids/fixed (example: "r9JOyLkQWjnegYbwZ1p0GDXNm")
✔ nanoid/non-secure (example: "hI202PVPJQRNrP6o6z4pXz4m0")
✔ uid (example: "9904e9w130buxaw7n8358mn2f")
✔ hexoid (example: "01dfab2c14e37768eb7605a00")
Benchmark (length = 25):
cuid x 161,636 ops/sec ±1.36% (89 runs sampled)
hashids/fixed x 335,439 ops/sec ±2.40% (94 runs sampled)
nanoid/non-secure x 2,254,073 ops/sec ±0.23% (96 runs sampled)
uid x 2,483,275 ops/sec ±0.38% (95 runs sampled)
hexoid x 75,715,843 ops/sec ±0.27% (95 runs sampled)
Validation (length = 36):
✔ uuid/v1 (example: "c3dc1ed0-629a-11ea-8bfb-8ffc49585f54")
✔ uuid/v4 (example: "8c89f0ca-f01e-4c84-bd71-e645bab84552")
✔ hashids/fixed (example: "EVq3Pr9JOyLkQWjnegYbwZ1p0GDXNmRBlAxg")
✔ @lukeed/uuid (example: "069ad676-48f9-4452-b11d-f20c3872dc1f")
✔ nanoid/non-secure (example: "jAZjrcDmHH6P1rT9EFdCdHUpF440SjAKwb2A")
✔ uid (example: "5mhi30lgy5d0glmuy81llelbzdko518ow1sx")
✔ hexoid (example: "615209331f0b4630acf69999ccfc95a23200")
Benchmark (length = 36):
uuid/v1 x 1,487,947 ops/sec ±0.18% (98 runs sampled)
uuid/v4 x 334,868 ops/sec ±1.08% (90 runs sampled)
@lukeed/uuid x 6,352,445 ops/sec ±0.27% (91 runs sampled)
hashids/fixed x 322,914 ops/sec ±0.27% (93 runs sampled)
nanoid/non-secure x 1,592,708 ops/sec ±0.25% (91 runs sampled)
uid x 1,789,492 ops/sec ±0.29% (92 runs sampled)
hexoid x 71,746,692 ops/sec ±0.29% (93 runs sampled)
Related
- uid - A smaller (134B) but slower variant of this module with a different API
- @lukeed/uuid - A tiny (230B), fast, and cryptographically secure UUID (V4) generator for Node and the browser
License
MIT © Luke Edwards
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
2 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 3
Reason
Found 1/25 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/hexoid/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/lukeed/hexoid/ci.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:20
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:28
- Warn: downloadThenRun not pinned by hash: .github/workflows/ci.yml:35
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
- Info: 0 out of 1 downloadThenRun dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Score
3.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More