From 562e74741a73091dd2ac78a2382aaaf3085892fb Mon Sep 17 00:00:00 2001 From: Lukas Tetzlaff Date: Wed, 27 Mar 2019 15:15:39 +0100 Subject: [PATCH 1/3] Add typings for cuint --- types/cuint/cuint-tests.ts | 5 +++++ types/cuint/index.d.ts | 34 ++++++++++++++++++++++++++++++++++ types/cuint/tsconfig.json | 23 +++++++++++++++++++++++ types/cuint/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/cuint/cuint-tests.ts create mode 100644 types/cuint/index.d.ts create mode 100644 types/cuint/tsconfig.json create mode 100644 types/cuint/tslint.json diff --git a/types/cuint/cuint-tests.ts b/types/cuint/cuint-tests.ts new file mode 100644 index 0000000000..6b2abbeb51 --- /dev/null +++ b/types/cuint/cuint-tests.ts @@ -0,0 +1,5 @@ +import { UINT32 } from "cuint"; + +const u = UINT32(1, 2, 3); +const d = u.fromBits(4, 5, 6); +d.add(u.multiply(d)).rotl(17).subtract(u).shiftRight(123); diff --git a/types/cuint/index.d.ts b/types/cuint/index.d.ts new file mode 100644 index 0000000000..9adf41a581 --- /dev/null +++ b/types/cuint/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for cuint 0.2 +// Project: https://github.com/pierrec/js-cuint +// Definitions by: Lukas Tetzlaff +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type UIntFactory = ( + ...numbers: Array +) => T; + +export const UINT64: UIntFactory; +export const UINT32: UIntFactory; + +export class UInt { + protected constructor() + + clone(): this; + add(x: this): this; + subtract(x: this): this; + multiply(x: this): this; + xor(x: this): this; + rotl(n: number): this; + shiftRight(n: number): this; + + fromNumber(n: number): this; + fromBits(...bits: number[]): this; + + _low: number; + _high: number; + + toString(base?: number): string; +} + +export class UInt64 extends UInt {} +export class UInt32 extends UInt {} diff --git a/types/cuint/tsconfig.json b/types/cuint/tsconfig.json new file mode 100644 index 0000000000..44d73f84be --- /dev/null +++ b/types/cuint/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", + "cuint-tests.ts" + ] +} diff --git a/types/cuint/tslint.json b/types/cuint/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cuint/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 0f0e87ab9af99353c5d4d10468815423cec182fe Mon Sep 17 00:00:00 2001 From: Lukas Tetzlaff Date: Sun, 31 Mar 2019 22:25:22 +0200 Subject: [PATCH 2/3] Change exports to be types rather than values according to review --- types/cuint/cuint-tests.ts | 2 +- types/cuint/index.d.ts | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/types/cuint/cuint-tests.ts b/types/cuint/cuint-tests.ts index 6b2abbeb51..6a5abe305e 100644 --- a/types/cuint/cuint-tests.ts +++ b/types/cuint/cuint-tests.ts @@ -1,5 +1,5 @@ import { UINT32 } from "cuint"; -const u = UINT32(1, 2, 3); +const u = UINT32(1, 2); const d = u.fromBits(4, 5, 6); d.add(u.multiply(d)).rotl(17).subtract(u).shiftRight(123); diff --git a/types/cuint/index.d.ts b/types/cuint/index.d.ts index 9adf41a581..7b56ee89be 100644 --- a/types/cuint/index.d.ts +++ b/types/cuint/index.d.ts @@ -3,16 +3,7 @@ // Definitions by: Lukas Tetzlaff // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export type UIntFactory = ( - ...numbers: Array -) => T; - -export const UINT64: UIntFactory; -export const UINT32: UIntFactory; - -export class UInt { - protected constructor() - +export interface Uint { clone(): this; add(x: this): this; subtract(x: this): this; @@ -30,5 +21,22 @@ export class UInt { toString(base?: number): string; } -export class UInt64 extends UInt {} -export class UInt32 extends UInt {} +export interface UintConstructor { + // called as a function: + (value: number): T; + (low: number, high: number): T; + (text: string, radix?: number): T; + + // called as a constructor: + new (value: number): T; + new (low: number, high: number): T; + new (text: string, radix?: number): T; + + prototype: T; + } + +export interface Uint64 extends Uint {} +export interface Uint32 extends Uint {} + +export const UINT64: UintConstructor; +export const UINT32: UintConstructor; From c26c43b7e2a90670ce3975c2b619f98d799c035a Mon Sep 17 00:00:00 2001 From: Lukas Tetzlaff Date: Mon, 1 Apr 2019 00:27:11 +0200 Subject: [PATCH 3/3] fix linter issues --- types/cuint/index.d.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/types/cuint/index.d.ts b/types/cuint/index.d.ts index 7b56ee89be..4b20b33973 100644 --- a/types/cuint/index.d.ts +++ b/types/cuint/index.d.ts @@ -23,20 +23,17 @@ export interface Uint { export interface UintConstructor { // called as a function: - (value: number): T; - (low: number, high: number): T; + (low: number, high?: number): T; + // tslint:disable-next-line:unified-signatures (text: string, radix?: number): T; // called as a constructor: - new (value: number): T; - new (low: number, high: number): T; + new (low: number, high?: number): T; + // tslint:disable-next-line:unified-signatures new (text: string, radix?: number): T; prototype: T; } -export interface Uint64 extends Uint {} -export interface Uint32 extends Uint {} - -export const UINT64: UintConstructor; -export const UINT32: UintConstructor; +export const UINT64: UintConstructor; +export const UINT32: UintConstructor;