All Projects → mderazon → order-id

mderazon / order-id

Licence: MIT license
Unique order id generator

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to order-id

friendly-id
Java Friendly Id for UUID
Stars: ✭ 173 (+276.09%)
Mutual labels:  unique-id, unique-identifier
secrets.clj
A library designed to generate cryptographically strong random numbers.
Stars: ✭ 64 (+39.13%)
Mutual labels:  random, timestamp
Butterfly
分布式ID生成器框架:超高性能的发号器框架。通过引入多种新的方案,彻底解决雪花算法的时间回拨等问题,并将雪花算法原生QPS提高最少十几~二十倍
Stars: ✭ 111 (+141.3%)
Mutual labels:  unique-id, unique-identifier
format-preserving-encryption-java
Format-Preserving Encryption Implementation in Java
Stars: ✭ 78 (+69.57%)
Mutual labels:  fpe, format-preserving-encryption
awesome-randomizers
🎲 A curated list of awesome services for obtaining random results.
Stars: ✭ 36 (-21.74%)
Mutual labels:  random
WeightedRandomSelector
Very fast C# class for weighted random picking.
Stars: ✭ 117 (+154.35%)
Mutual labels:  random
MlkPwgen
Secure random password generator for .NET and PowerShell
Stars: ✭ 57 (+23.91%)
Mutual labels:  random
Random-Number-Generator
A clean, simple random number generator for Android. Downloaded 180,000+ times and rated 2,000+ times on Google Play with 4.7+ average rating.
Stars: ✭ 30 (-34.78%)
Mutual labels:  random
SDETools
Matlab Toolbox for the Numerical Solution of Stochastic Differential Equations
Stars: ✭ 80 (+73.91%)
Mutual labels:  random
vscode-insertdatestring
An extension for Visual Studio Code that provides a configurable command for inserting the current date and time
Stars: ✭ 58 (+26.09%)
Mutual labels:  timestamp
cpp-code-snippets
Some useful C++ code snippets
Stars: ✭ 35 (-23.91%)
Mutual labels:  random
jRand
A Java library to generate random data for all sorts of things. Java random data faker
Stars: ✭ 27 (-41.3%)
Mutual labels:  random
svelte-time
Format a timestamp using day.js
Stars: ✭ 70 (+52.17%)
Mutual labels:  timestamp
lrng
Linux Random Number Generator
Stars: ✭ 57 (+23.91%)
Mutual labels:  random
pysub-parser
Library for extracting text and timestamps from multiple subtitle files (.ass, .ssa, .srt, .sub, .txt).
Stars: ✭ 40 (-13.04%)
Mutual labels:  timestamp
sno
Compact, sortable and fast unique IDs with embedded metadata.
Stars: ✭ 77 (+67.39%)
Mutual labels:  unique-id
msp430-rng
Random (SLAA338) and pseudorandom (LCG) number generation.
Stars: ✭ 19 (-58.7%)
Mutual labels:  random
sfmt-erlang
sfmt-erlang: SIMD-oriented Fast Mersenne Twister (SFMT) for Erlang
Stars: ✭ 70 (+52.17%)
Mutual labels:  random
rango
Random. Django. Rango. An introduction to using Python and Django to build a website.
Stars: ✭ 53 (+15.22%)
Mutual labels:  random
alokmenghrajani.github.com
Alok Menghrajani's Blog
Stars: ✭ 64 (+39.13%)
Mutual labels:  random

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].