New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

maylily

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maylily

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

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

MayLily

Build Status (Windows) Build Status (macOS) Build Status (Linux) Code Coverage Release Node.js version License

NPM

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

Features

  • distributable / scalable
  • no external servers required
  • customizable
  • supports 2-36 radix
  • supports multiple precision integer
  • supports CommonJS, ES Modules, TypeScript

How to install

Install by npm.

npm install -S maylily

How to use

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

JavaScript

Traditional syntax. This code will run on most JavaScript engine.

var maylily = require("maylily");

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

ECMAScript 7

Modern syntax. Async/await syntax is easy to read

const maylily = require("maylily");

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

ES Modules / Babel / TypeScript (import, async/await)

VERY modern syntax!

import maylily from "maylily"; // import syntax

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

How to customize

namedescriptiondefault
radixradix of generated ID (2-36)10
timeBasebase time in unixtime(millisec)946684800000 (2000-01-01T00:00:00Z)
machineIdidentifier of machine; must be unique in service0
machineBitsrequired bits to represent machineId3
generatorIdidentifier of generator; must be unique in machineprocess ID
generatorBitsrequired bits to represent generatorId10
sequenceBitsrequired bits to represent sequence8

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.
});

Changelog

See CHANGELOG.md.

Keywords

FAQs

Package last updated on 21 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc