Unique order id generator
(almost) unique order id generator
xxxx-xxxxxx-xxxx
, where x
is a digit (0-9). Similar to the format Amazon is using for their order numbers.const orderid = require('order-id')('key');
const id = orderid.generate();
// 3016-734428-7759
orderid.getTime(id);
// 1479812667797
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.