mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 11:02:11 +08:00
Added definitions for flake-idgen
This commit is contained in:
27
flake-idgen/flake-idgen-tests.ts
Normal file
27
flake-idgen/flake-idgen-tests.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/// <reference path="flake-idgen.d.ts"/>
|
||||
|
||||
// require flake-idgen
|
||||
import FlakeId = require('flake-idgen');
|
||||
let flakeIdGen1 = new FlakeId({datacenter: 9, worker: 7});
|
||||
|
||||
// create flake IDs
|
||||
console.log(flakeIdGen1.next());
|
||||
console.log(flakeIdGen1.next());
|
||||
console.log(flakeIdGen1.next());
|
||||
|
||||
// create flake IDs using a callback
|
||||
flakeIdGen1.next((err, id) => {
|
||||
console.info(id);
|
||||
});
|
||||
|
||||
flakeIdGen1.next((err, id) => {
|
||||
console.info(id);
|
||||
});
|
||||
|
||||
let flakeIdGen2 = new FlakeId();
|
||||
let flakeIdGen3 = new FlakeId({datacenter: 9, worker: 7});
|
||||
let flakeIdGen4 = new FlakeId({epoch: 1300000000000})
|
||||
console.info(flakeIdGen2.next());
|
||||
console.info(flakeIdGen3.next());
|
||||
console.info(flakeIdGen4.next());
|
||||
|
||||
22
flake-idgen/flake-idgen.d.ts
vendored
Normal file
22
flake-idgen/flake-idgen.d.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Type definitions for flakge-idgen 0.1.4
|
||||
// Project: https://github.com/T-PWK/flake-idgen
|
||||
// Definitions by: Yuce Tekol <http://yuce.me/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module 'flake-idgen' {
|
||||
interface ConstructorOptions {
|
||||
datacenter?: number;
|
||||
worker?: number;
|
||||
id?: number;
|
||||
epoch?: number;
|
||||
seqMask?: number;
|
||||
}
|
||||
|
||||
class FlakeId {
|
||||
constructor(options?: ConstructorOptions);
|
||||
next(callback?: (err: Error, id: Buffer) => void): Buffer;
|
||||
}
|
||||
export = FlakeId;
|
||||
}
|
||||
Reference in New Issue
Block a user