Gathering detailed insights and metrics for hybrid-id-generator
Gathering detailed insights and metrics for hybrid-id-generator
The **Hybrid ID Generator** is a powerful TypeScript-based library designed to produce unique identifiers by seamlessly combining timestamps, machine identifiers, sequence numbers, and random bits
npm install hybrid-id-generator
Typescript
Module System
Node Version
NPM Version
87.7
Supply Chain
100
Quality
82.2
Maintenance
100
Vulnerability
100
License
TypeScript (99.53%)
JavaScript (0.47%)
Total Downloads
114,331
Last Day
1,502
Last Week
6,911
Last Month
25,908
Last Year
114,331
3 Stars
27 Commits
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.3
Package Id
hybrid-id-generator@3.0.3
Unpacked Size
123.82 kB
Size
27.05 kB
File Count
28
NPM Version
10.8.3
Node Version
22.9.0
Publised On
11 Oct 2024
Cumulative downloads
Total Downloads
Last day
75,000%
1,502
Compared to previous day
Last week
49,264.3%
6,911
Compared to previous week
Last month
-3%
25,908
Compared to previous month
Last year
0%
114,331
Compared to previous year
5
The Hybrid ID Generator is a powerful TypeScript-based library designed to produce unique identifiers by seamlessly combining timestamps, machine identifiers, sequence numbers, and random bits. This innovative approach ensures that each generated ID is unique and highly resilient against collisions, making it ideal for distributed systems.
This package is optimized for versatility and can be effortlessly utilized in both client-side and server-side environments, offering flexibility for a wide range of applications—from web development to microservices architecture.
Whether you are building a high-performance application that requires unique identifiers for database entries or need to track events in real-time, the Hybrid ID Generator provides a reliable solution that meets your needs.
You can install the package via npm:
1npm install hybrid-id-generator
Importing the Package You can use the package in both CommonJS and ES Module formats:
1import { HybridIDGenerator } from 'hybrid-id-generator'; 2 3const idGenerator = new HybridIDGenerator({ 4 machineId: 1, // Unique identifier for the machine 5 randomBits: 10, // Number of random bits 6}); 7 8// Generate a single ID 9const uniqueId = idGenerator.nextId(); 10console.log(`Generated ID: ${uniqueId}`); 11 12// Check if an ID is valid 13const isValid = idGenerator.isHybridID(uniqueId); 14console.log(`Is valid ID: ${isValid}`); 15 16// Decode an ID 17const decodedId = idGenerator.decode(uniqueId); 18console.log(`Decoded ID:`, decodedId);
Here’s a quick example of how to use the HybridIDGenerator:
Server-Side Example
1import { HybridIDGenerator } from 'hybrid-id-generator'; 2 3// Initialize the ID generator with a machine identifier and configuration options. 4const idGenerator = new HybridIDGenerator({ 5 sequenceBits: 12, 6 randomBits: 10, 7}); 8 9// Generate a new unique ID. 10const id: number = idGenerator.nextId(); 11console.log(`Generated ID: ${id}`);
Client-Side Example
1import HybridIDGenerator from 'hybrid-id-generator'; // Adjust the path as necessary
2
3// Initialize the ID generator with configuration options.
4const idGenerator = new HybridIDGenerator({
5 sequenceBits: 12,
6 randomBits: 10,
7 useCrypto: true, // Assuming this option is supported in your implementation
8});
9
10// Generate a new unique ID.
11const newId: number = idGenerator.nextId();
12console.log(`Generated ID: ${newId.toString()}`);
Options for configuring the HybridIDGenerator
.
Property | Type | Default | Description |
---|---|---|---|
sequenceBits | number | 12 | The number of bits for the sequence component. |
randomBits | number | 10 | The number of bits for the random component. |
entropyBits | number | 5 | The number of bits for the entropy component. |
useCrypto | boolean | false | Whether to use cryptographic functions for random generation. |
maskTimestamp | boolean | false | Whether to mask the timestamp during ID generation. |
enableEventEmission | boolean | false | Whether to enable event emission for ID generation. |
machineIdBits | number | 12 | The number of bits for the machine ID component. |
machineIdStrategy | `'env' | 'network' | 'random'` |
machineId | `number | string` | - |
Information about the generated Hybrid ID.
Property | Type | Description |
---|---|---|
timestamp | bigint | The timestamp portion of the Hybrid ID. |
machineId | number | The machine ID portion of the Hybrid ID. |
randomBits | number | The random bits portion of the Hybrid ID. |
sequence | number | The sequence number of the Hybrid ID. |
masked | boolean | Indicates whether the timestamp is masked. |
1constructor(options: HybridIDGeneratorOptions = {})
Initializes a new instance of HybridIDGenerator
with the specified options.
idGenerated
1idGenerator.on('idGenerated', (id) => { 2 console.log(`New ID generated: ${id}`); 3}); 4idGenerator.nextId();
Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.
No vulnerabilities found.
No security vulnerabilities found.