UNPKG

@mhysko/s-uuid

Version:

Translate standard UUID to Base68 format and back

38 lines (26 loc) 1.21 kB
# s-uuid s-uuid is a tiny wrapper on [`uuid`](https://github.com/uuidjs/uuid) that allows to translate standard UUIDs into shorter - or just _different_ - formats and back. This is a remake of [`short-uuid`](https://github.com/oculus42/short-uuid). ### Usage ```typescript 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 ```typescript 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' ```