Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A fast ULID (Universally unique Lexicographically sortable IDentifier) generator in its class with zero dependencies, no slow types are used, fully type-safe and supporting multiple runtimes. ULID is an alternative to UUID but lexicographically sortable, more efficient, monotonic sort order, URL safe, ideal for databases, logs, and more!

License

NotificationsYou must be signed in to change notification settings

fajarnugraha37/deno-ulid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSR ScopeJSRJSR Score

This package provides a fast, lightweight, zero dependencies, no slow types areused, fully type-safe and supporting multiple runtimes for generating ULIDs(Universally Unique Lexicographically Sortable Identifiers). ULIDs offer alexicographically sortable (combine timestamps with a series of randomcharacters in a lexicographically sortable manner), universally unique,efficient, monotonic sort order and URL safe alternative to UUIDs.

Import

Add Package:

$ deno add jsr:@fajar/deno-ulid

Import symbol:

import*asmodfrom"@fajar/deno-ulid";

OR Import directly with a jsr specifier

import*asmodfrom"jsr:@fajar/deno-ulid";

Usage

To generate a ULID, simply run the function:

import{ulid}from"jsr:@fajar/deno-ulid";ulid();

Monotonic ULIDs

To generate monotonically increasing ULIDs, create a monotonic counter:

import{monotonicFactory}from"jsr:@fajar/deno-ulid";constulid=monotonicFactory();ulid(100000);ulid(100000);ulid(100000);ulid(100000);ulid(100000);

Convert UUID to ULID

import{uuidToULID}from"jsr:@fajar/deno-ulid";uuidToULID(crypto.randomUUID());

Convert ULID to UUID

import{ulidToUUID}from"jsr:@fajar/deno-ulid";constuuid=crypto.randomUUID();ulidToUUID(uuid);

Performance

$ deno task benchmark
CPU| 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHzRuntime| Deno 2.0.0 (x86_64-pc-windows-msvc)file:///C:/Users/fajar.nugraha/Desktop/workspace/compose/deno-ulid/test/bench.tsbenchmark      time/iter (avg)        iter/s      (min … max)           p75      p99     p995-------------- ----------------------------- --------------------- --------------------------encodeTime            265.1 ns     3,772,000 (173.6 ns … 430.4 ns) 288.6 ns 390.9 ns 392.3 nsdecodeTime            657.6 ns     1,521,000 (513.6 ns … 993.4 ns) 730.2 ns 993.4 ns 993.4 nsencodeRandom            4.9 µs       205,900 (  4.0 µs …   6.0 µs)   5.2 µs   6.0 µs   6.0 µsgenerate                7.4 µs       136,000 (  6.3 µs …   8.3 µs)   7.7 µs   8.3 µs   8.3 µsulidToUUID              3.9 µs       257,900 (  3.5 µs …   4.6 µs)   4.0 µs   4.6 µs   4.6 µsuuidToULID              6.4 µs       157,000 (  5.9 µs …   8.0 µs)   6.5 µs   8.0 µs   8.0 µs

Test

$ denotest
running 1test from ./test/test.tsulid ...  prng ...    should produce a number ... ok (1ms)    should be between 0 and 1 ... ok (1ms)  prng ... ok (4ms)  incremenet base32 ...    increments correctly ... ok (0ms)    carries correctly ... ok (0ms)    double increments correctly ... ok (0ms)    throws when it cannot increment ... ok (0ms)  incremenet base32 ... ok (2ms)  randomChar ...    should neverreturn undefined ... ok (0ms)    should neverreturn an empty string ... ok (0ms)  randomChar ... ok (153ms)  encodeTime ...    shouldreturn expected encoded result ... ok (0ms)    should change length properly ... ok (0ms)    should truncatetimeif not enough length ... ok (0ms)    should throw an error ...iftime greater than (2 ^ 48) - 1 ... ok (0ms)iftime is not a number ... ok (0ms)iftime is infinity ... ok (0ms)iftime is negative ... ok (1ms)iftime is a float ... ok (0ms)    should throw an error ... ok (3ms)  encodeTime ... ok (8ms)  encodeRandom ...    shouldreturn correct length ... ok (0ms)  encodeRandom ... ok (0ms)  decodeTime ...    shouldreturn correct timestamp ... ok (0ms)    should accept the maximum allowed timestamp ... ok (0ms)    should reject ...      malformed strings of incorrect length ... ok (0ms)      strings with timestamps that are too high ... ok (0ms)      invalid character ... ok (0ms)    should reject ... ok (1ms)  decodeTime ... ok (1ms)  ulid ...    shouldreturn correct length ... ok (0ms)    shouldreturn expected encodedtime component result ... ok (0ms)  ulid ... ok (0ms)  monotonicity ...    without seedTime ...      first call ... ok (0ms)      second call ... ok (0ms)      third call ... ok (0ms)      fourth call ... ok (0ms)    without seedTime ... ok (1ms)    with seedTime ...      first call ... ok (0ms)      second call with the same ... ok (0ms)      third call with less than ... ok (0ms)      fourth call with even more less than ... ok (0ms)      fifth call with 1 greater than ... ok (0ms)    with seedTime ... ok (2ms)  monotonicity ... ok (5ms)ulid ... ok (181ms)ok| 1 passed (45 steps)| 0 failed (183ms)

About

A fast ULID (Universally unique Lexicographically sortable IDentifier) generator in its class with zero dependencies, no slow types are used, fully type-safe and supporting multiple runtimes. ULID is an alternative to UUID but lexicographically sortable, more efficient, monotonic sort order, URL safe, ideal for databases, logs, and more!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp