JSPM

@mhysko/s-uuid

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q39279F
  • License MIT

Translate standard UUID to Base68 format and back

Package Exports

  • @mhysko/s-uuid
  • @mhysko/s-uuid/package.json

Readme

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'