@yeliex/snowflake
v2.0.2
Published
a javascript implement of twitter-snowflake uniq-id generation arithmetic
Downloads
4
Readme
snowflake
a javascript implement of twitter-snowflake uniq-id generation arithmetic
Installation
$ npm i @yeliex/snowflake -S
# OR
$ yarn add @yeliex/snowflake
Usage
const Snowflake = require('@yeliex/snowflake');
const snowflake = new Snowflake();
snowflake.next().then((id)=>{
console.log(id.toString('hex'));
})
Api
class Snowflake
constructor: (options: SnowFlakeOption)
public async next: () => Promise(Buffer)
async return flake id
public static await: (ms: number) => Promise
static readonly endpointId: string
endpoint id gen with hostname(docker only) or ip
static readonly MAX_SEQUENCE: number
static readonly MAX_ENDPOINT: number
static readonly MAX_WORKER: number
static readonly MAX_DATACENTER: number
readonly worker: number
readonly mark: SnowFlakeMark
readonly offset: number
SnowFlakeOption
type SnowFlakeMark = 0 | 1;
interface SnowFlake {
mark?: SnowFlakeMark
datacenter?: number
worker?: number
endpoint?: number // if set, datacenter and worker would be ignored
offset?: number // timestamp offset, default 0
}