Giter Site home page Giter Site logo

deno-maylily's Introduction

Deno MayLily

nest.land doc.deno.land RELEASE LICENSE

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/[email protected]/mod.ts";

Or use deno.land:

import { maylily } from  "https://deno.land/x/[email protected]/mod.ts";

How to use

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

import { maylily } from "https://x.nest.land/[email protected]/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.
});

Changelog

See CHANGELOG.md

deno-maylily's People

Contributors

itohatweb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.