Skip to content

zlid-io/javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zlid-javascript

TypeScript reference library for ZLID.

What is included

  • ordered ZLIDs with the default and high-throughput profiles
  • ZLID-R random IDs
  • ZLID-A keyed reversible aliases for ordered ZLIDs
  • canonical and friendly Crockford Base32 parsing
  • NIL and MAX sentinels
  • unknown-tag round-tripping as opaque 16-byte payloads
  • the optional partition helper
  • the official v0.1 golden conformance dataset

Status

This is the initial TypeScript reference implementation for the v0.1 spec.

Install

Install the pre-release from here:

npm install @zlid-io/[email protected]

It will be available on npm shortly.

Quick start

import { ZLID } from 'zlid-ts';

const ordered = ZLID.next();
const random = ZLID.random();

const highThroughput = ZLID
  .generator({ profile: 'high-throughput' })
  .next({ partition: 7 });

const alias = ZLID.alias(ordered, {
  key: Uint8Array.from([0, 1, 2, 3]),
  tweak: 'users|prod',
});

console.log(ordered.text());
console.log(random.text());
console.log(highThroughput.inspect());
console.log(ZLID.unalias(alias, {
  key: Uint8Array.from([0, 1, 2, 3]),
  tweak: 'users|prod',
}).text());

Public API

ZLID.next(options?)
ZLID.generator(options?)
ZLID.random()

ZLID.alias(id, options)
ZLID.unalias(id, options)

ZLID.parse(text)
ZLID.fromBytes(bytes)

ZLID.text(id)
ZLID.bytes(id)

ZLID.inspect(id)
ZLID.compare(a, b)
ZLID.equals(a, b)
ZLID.partition(input, options?)

ZLID.next() always emits the ordered default profile. To emit high-throughput, create a generator with a fixed profile and keep that profile stable for the logical ordered stream.

Project layout

  • src/ — library source
  • test/ — TypeScript test suite
  • conformance/ — official v0.1 golden dataset and checksum

About

TypeScript reference library for ZLID

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors