2.0.2 • Published 1 year ago

@yeliex/snowflake v2.0.2

Weekly downloads
14
License
MIT
Repository
github
Last release
1 year ago

snowflake

a javascript implement of twitter-snowflake uniq-id generation arithmetic

https://npmjs.org/package/@yeliex/snowflake https://hub.docker.com/r/yeliex/snowflake/

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
}
2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago