Git Product home page Git Product logo

order-id's Introduction

order-id

Build status styled with prettier

(almost) unique order id generator

  • Generates order ids in the format xxxx-xxxxxx-xxxx, where x is a digit (0-9). Similar to the format Amazon is using for their order numbers.
  • Uses the current unix timestamp (13 digits) plus 1 random digit so it's unique down to the milisecond.
  • If your system generates 1,000,000 orders per day (evenly distributed), the probability of collision would be ~1%. The extra padding digit makes it even lower.
  • The timestamp is scrambled using a supplied key so the result doesn't appear as a timestamp and is not sequential.
  • Bonus: Since it's based on timestamp, we can get the time back from the order id (see api calls).

Usage

const orderid = require('order-id')('key');
const id = orderid.generate();
// 3016-734428-7759

orderid.getTime(id);
// 1479812667797

Api

  • generate(date) - Generates an order id. date is optional and can be anything that js Date constructor knows how to parse and it will use it as the time for the order id. Otherwise, current date will be used.
  • getTime(id) - Use this to get back the time of the order in unix timestamp format. You need to use the same key used to generate the order id.
  • key - (Optional) Any string used by the underlying cipher as a seed phrase. Needed if you want to get back the timestamp from an order id.

order-id's People

Contributors

mderazon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

order-id's Issues

Secret key

Hi, love this library, but wanted some more context on the secret. What exactly is this secret key used for? Is this just a string that is used to help hash out a unique order number? What characters are allowed in this string? All characters?

how order-id work for this example

i create three item with order-id and insert in db , then i went swap them .

for example

1 ( 100000000 )
2 ( 100200000 )
3 ( 100400000 )

i need set item 3 up to 1

how i can use this package to generate unique order-id lower than 100000000 ??

missing declaration Types for Typescript

May you write types for typescript developer? I really like this lib and I want to use it on my typescript project. Although I want to help, I am just beginner ๐Ÿ˜ฅ

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.