A Changed Copy of Maylily a Distributable, Serverless, and Customizable Unique ID Generator

Deno MayLily

A changed copy of Maylily a distributable, serverless, and customizable unique ID generator based on Snowflake. Made compatible with deno.

Features

  • distributable / scalable
  • no external servers required
  • customizable
  • supports 2-36 radix
  • supports multiple precision integer

How to import

Import with nest.land:

import { maylily } from "https://x.nest.land/deno-maylily@2.0.1/mod.ts";

Or use deno.land:

import { maylily } from  "https://deno.land/x/deno_maylily@2.0.1/mod.ts";

How to use

No external servers needed. Just import and call maylily()!

import { maylily } from "https://x.nest.land/deno-maylily@2.0.1/mod.ts";

try {
  const id = await maylily();
  // do something...
} catch (err) {
  // err is instance of Error
}

How to customize

name description default
radix radix of generated ID (2-36) 10
timeBase base time in unixtime (millisec) 946684800000 (2000-01-01T00:00:00Z)
machineId identifier of machine; must be unique in service 0
machineBits required bits to represent machineId 3
generatorId identifier of generator; must be unique in machine process ID
generatorBits required bits to represent generatorId 10
sequenceBits required bits to represent sequence 8

Generated value is stringified multiple precision integer (in specified radix).

 000001011100000101111010101110101010111101 001 1101101010 00000110
|------------------------------------------|                         current time from timeBase in millisec
                                           |---|                     machineId (uses machineBits bits)
                                               |----------|          generatorId (uses generatorBits bits)
                                                          |--------| sequence number (uses sequenceBits bits)

example:

// keeps options until next change
maylily({
  timeBase: Date.parse("2017-01-01T00:00:00Z"),   // if your service starts in 2017, this is enough.
  machineBits: 1                                  // if required number machines are up to 2, this is enough.
});

Download Details:

Author: itohatweb

Source Code: https://github.com/itohatweb/deno-maylily

#deno #nodejs #node #javascript

A Changed Copy of Maylily a Distributable, Serverless, and Customizable Unique ID Generator
2.00 GEEK