Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#6042 from yuce/flake-idgen
Browse files Browse the repository at this point in the history
Added definitions for flake-idgen
  • Loading branch information
horiuchi committed Sep 29, 2015
2 parents 6037dbb + c98ea9d commit ffceea9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions flake-idgen/flake-idgen-tests.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions flake-idgen/flake-idgen.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ffceea9

Please sign in to comment.