JSPM

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

distributable, serverless, and customizable unique ID number generator based on Snowflake

Package Exports

  • maylily

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 (maylily) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

MayLily

distributable, serverless, and customizable unique ID number generator based on Snowflake

How to use

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

JavaScript

var maylily = require("maylily");

// returns a Promise object
maylily()
    .then(function(id) {
        // do something...
    })
    .catch(function(err) {
        // err is instance of Error
    });

ECMAScript 7 (async/await)

import maylily from "maylily";
try {
    // returns a Promise object
    const id = await maylily();
    // do something...
}
catch(err) {
    // err is instance of Error
}

How to customize

name description default
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 2
generatorId identifier of generator; must be unique in machine process ID
generatorBits required bits to represent generatorId 7
sequenceBits required bits to represent sequence 5

Generated value is 53-bit integer.

 001011100000101111010101110101010111101 01 1101100 00010
                                                   |-----| sequence number (uses sequenceBits bits)
                                           |-------|       generatorId (uses generatorBits bits)
                                        |--|               machineId (uses machineBits bits)
|---------------------------------------|                  current time from timeBase in millisec (uses remaining bits)

example:

// holds the change 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 machines are up to 2, this is enough.
    generatorBits: 0                                // if running process is only 1, this is enough.
});

Release note

  • 2017-01-21 version 1.0.0
    • First release.