@neuledge/id
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Id

Globally unique identifier based on the upcoming UUIDv7 standard (using TypeID).

Install

Install the package:

yarn add @neuledge/id

Usage

import { Id, IdType } from '@neuledge/id';

const UserId = new Id('user');
type UserId = typeof UserId.type;

// Generate a new id
const userId = UserId.generate(); // user_2x4y6z8a0b1c2d3e4f5g6h7j8k

// using the id type
const id: UserId = userId;

// Validate an id
const isValid = UserId.is(userId); // true

// Get the prefix and suffix of an id
const prefix = UserId.prefix; // user
const suffix = UserId.getSuffix(userId); // 2x4y6z8a0b1c2d3e4f5g6h7j8k

// Get the id from a suffix
const id = UserId.fromSuffix(suffix); // user_2x4y6z8a0b1c2d3e4f5g6h7j8k

Package Sidebar

Install

npm i @neuledge/id

Weekly Downloads

30

Version

1.2.0

License

MIT

Unpacked Size

13.5 kB

Total Files

12

Last publish

Collaborators

  • moshe