npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maylily

v2.2.0

Published

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

Downloads

17

Readme

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

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

Changelog

See CHANGELOG.md.