Skip to content

takiuddinahmed/unique-number-id

Repository files navigation

Unique Number ID

A scalable npm package that generates unique numbers. It ensures that the generated numbers are unique across different devices in a distributed system. The user can provide a device ID to generate a unique number based on that device ID.

Installation

npm install unique-number-id

or

yarn add unique-number-id

Usage

Import generate function from the package:

import { uniqueNumberId } from 'unique-number-id'
// or
const  { uniqueNumberId }  = require('unique-number-id');

Generating a Unique Number

To generate a unique number, simply call the function:

const uniqueNumber = uniqueNumberId();
console.log('Generated Unique Number:', uniqueNumber);

Generating a Unique Number with Device ID

f you want to generate a unique number based on a specific device ID, provide the deviceId parameter:

const uniqueNumber = uniqueNumberId({ deviceId: 3 });
console.log('Generated Unique Number for Device 3:', uniqueNumber);

Please ensure that the deviceId is a non-negative integer and is less than or equal to 99.

License

This project is licensed under the MIT License - see the LICENSE file for details.