From b3fbc0ad8f46b07bd1fabc5dc435ccc42465c483 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Tue, 28 Aug 2018 10:14:39 -0700 Subject: [PATCH 1/2] adds typings for the 'bloem' package --- types/bloem/bloem-tests.ts | 15 +++++++++++++++ types/bloem/index.d.ts | 39 ++++++++++++++++++++++++++++++++++++++ types/bloem/tsconfig.json | 23 ++++++++++++++++++++++ types/bloem/tslint.json | 3 +++ 4 files changed, 80 insertions(+) create mode 100644 types/bloem/bloem-tests.ts create mode 100644 types/bloem/index.d.ts create mode 100644 types/bloem/tsconfig.json create mode 100644 types/bloem/tslint.json diff --git a/types/bloem/bloem-tests.ts b/types/bloem/bloem-tests.ts new file mode 100644 index 0000000000..bcebbecebb --- /dev/null +++ b/types/bloem/bloem-tests.ts @@ -0,0 +1,15 @@ +import bloem = require('bloem'); + +const base = new bloem.Bloem(1, 2, Buffer.from('1', 'hex')); +const safe = new bloem.SafeBloem(1, 2, Buffer.from('2', 'hex')); +const scaling = new bloem.ScalingBloem(1, + {ratio: 1, initial_capacity: 2, scaling: 3} +); + +// options are optional +const scaling2 = new bloem.ScalingBloem(1); + +// $ExpectType number +bloem.calculateSize(1, 2); +// $ExpectType number +bloem.calculateSlices(1, 2); diff --git a/types/bloem/index.d.ts b/types/bloem/index.d.ts new file mode 100644 index 0000000000..a913e9f883 --- /dev/null +++ b/types/bloem/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for bloem 0.2 +// Project: https://github.com/wiedi/node-bloem +// Definitions by: Daniel Byrne +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export as namespace bloem; + +export function calculateSize(capacity: number, error_rate: number): number; +export function calculateSlices(size: number, capacity: number): number; + +export class Bloem { + constructor(size: number, slices: number, buffer: Buffer); + + has(key: Buffer): boolean; + add(key: Buffer): void; +} + +export class SafeBloem { + constructor(capacity: number, error_rate: number, buffer: Buffer); + + has(key: Buffer): boolean; + add(key: Buffer): boolean; +} + +export class ScalingBloem { + constructor( + error_rate: number, + options?: { + ratio?: number; + initial_capacity?: number; + scaling?: number; + } + ); + + has(key: Buffer): boolean; + add(key: Buffer): void; +} diff --git a/types/bloem/tsconfig.json b/types/bloem/tsconfig.json new file mode 100644 index 0000000000..f5ecad97bd --- /dev/null +++ b/types/bloem/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bloem-tests.ts" + ] +} \ No newline at end of file diff --git a/types/bloem/tslint.json b/types/bloem/tslint.json new file mode 100644 index 0000000000..6fafe521cb --- /dev/null +++ b/types/bloem/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" + } From ad7a113daf102ec5c0df8f515678f309abe93b49 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Tue, 28 Aug 2018 16:50:19 -0700 Subject: [PATCH 2/2] fixes needless namespace --- types/bloem/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/bloem/index.d.ts b/types/bloem/index.d.ts index a913e9f883..bcf6b35820 100644 --- a/types/bloem/index.d.ts +++ b/types/bloem/index.d.ts @@ -5,8 +5,6 @@ /// -export as namespace bloem; - export function calculateSize(capacity: number, error_rate: number): number; export function calculateSlices(size: number, capacity: number): number;