JSPM

ulid-uuid-converter

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5127
  • Score
    100M100P100Q137088F
  • License MIT

A tiny zero dependency library for ULID to UUID conversion and vice versa

Package Exports

  • ulid-uuid-converter
  • ulid-uuid-converter/dist/index.js
  • ulid-uuid-converter/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ulid-uuid-converter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ulid-uuid-converter

A tiny zero dependency library for ULID to UUID conversion and vice versa.

Installation

npm i ulid-uuid-converter

Usage

import { UUIDtoULID, ULIDtoUUID } from "ulid-uuid-converter";

const ulid = UUIDtoULID("0186675b-9439-536e-1c4c-561c280fa87b");
// outputs: 01GSKNQ51SADQ1RK2P3GM0ZA3V

const uuid = ULIDtoUUID("01GSKNQ51SADQ1RK2P3GM0ZA3V");
// outputs: 0186675b-9439-536e-1c4c-561c280fa87b

Options

You can pass an optional second argument with nullOnInvalidInput to both functions. With this option the function behavior changes: instead of throwing, it will return null if a bad input is passed as argument.

Option Type Default Description
nullOnInvalidInput boolean false Return null instead of throwing on bad input

Example

// these will throw!
const ulid = UUIDtoULID("bad string");
const uuid = ULIDtoUUID("another bad string");

// these will return null instead of throwing
const ulid = UUIDtoULID("bad string", { nullOnInvalidInput: true });
const uuid = ULIDtoUUID("another bad string", { nullOnInvalidInput: true });

Credits

Big thanks to devbanana for the Crockford's Base32 encoding and decoding functions.

License

This project is licensed under the MIT License.