@mhysko/s-uuid
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

s-uuid

s-uuid is a tiny wrapper on uuid that allows to translate standard UUIDs into shorter - or just different - formats and back.

This is a remake of short-uuid.

Usage

import { translate, generate, validate } from 's-uuid';

// Translate generated uuid V7 to Base58 format and back
translate('017f22e2-79b0-7cc3-98c4-dc0c0c07398f'); // 'BihbxwwQ4NZZpKRH9JDCz'
translate('BihbxwwQ4NZZpKRH9JDCz'); // '017f22e2-79b0-7cc3-98c4-dc0c0c07398f'

// Generate uuid V4 in Base58 format. By default generate func uses uuid V4
generate(); // '73WakrfVbNJBaAmhQtEeDv'

// validation
validate('017f22e2-79b0-7cc3-98c4-dc0c0c07398f'); // true
validate('BihbxwwQ4NZZpKRH9JDCz'); // true
validate(''); // false
validate(undefined); // false
validate('00000000-0000-0000-0000-000000000000'); // true

The default behavior can be changed

import { v7, Suuid } from 's-uuid';

const suuid = new Suuid(v7);

const suuid = suuid.generate(); // 'BihbxwwQ4NZZpKRH9JDCz'
const uuid = suuid.translate(suuid); // '017f22e2-79b0-7cc3-98c4-dc0c0c07398f'
suuid.translate(uuid); // 'BihbxwwQ4NZZpKRH9JDCz'

Package Sidebar

Install

npm i @mhysko/s-uuid

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

16.8 kB

Total Files

20

Last publish

Collaborators

  • mhysko