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

order-id

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

order-id

Unique order id generator

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-0.38%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 12 Nov 2021

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