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");
maylily()
.then(function(id) {
})
.catch(function(err) {
});
ECMAScript 7 (async/await)
import maylily from "maylily";
try {
const id = await maylily();
}
catch(err) {
}
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:
maylily({
timeBase: Date.parse("2017-01-01T00:00:00Z"),
machineBits: 1,
generatorBits: 0
});
Release note