seal-short-id v0.1.6
seal-short-id
Create a short human readable id of type string
.
This is done by concatenating two hash values. The first hash value is a static prefix build of the current data center name determined via seal-consul
module.
The second hash is build of a counter read from MongoDB by seal-counter-storage
module.
Installation
$ npm install seal-short-id
Quick start
First you need to integrate seal-short-id into your application.
const shortId = require('seal-short-id');
Get A Handler Object
Use the required function to get a short id handler.
The first parameter of shortId
is an options
object which has to contain
already connected seal-consul
and seal-counter-storage
objects as properties.
The second parameter is a callback with error and handler object as parameter.
shortId({
consul,
counterStorage
}, (err, shortIdHandler) => {
...
});
Get Id's
Call the handlers next
function for each id you want. Only parameter is
a callback function with error and the next id as parameter.
shortIdHandler.next((err, id) => {
...
});
Running the build
To build this module use roboter.
$ bot
8 years ago