diff --git a/types/base-x/base-x-tests.ts b/types/base-x/base-x-tests.ts index 44e302d2d5..7f50a98e54 100644 --- a/types/base-x/base-x-tests.ts +++ b/types/base-x/base-x-tests.ts @@ -1,13 +1,10 @@ +import * as baseX from 'base-x'; -import * as basex from 'base-x'; +const BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; +const bs58 = baseX(BASE58); -let bs16 = basex('0123456789ABCDEF'); +const decoded = bs58.decode('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr'); +decoded; // $ExpectType Buffer +bs58.decodeUnsafe('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr'); // $ExpectType Buffer | undefined -{ - let encoded: string; - - encoded = bs16.encode([255]); - encoded = bs16.encode({0: 255, length: 1}); -} - -let decoded: number[] = bs16.decode('FF'); +bs58.encode(decoded); // $ExpectType string diff --git a/types/base-x/index.d.ts b/types/base-x/index.d.ts index bbad200ce1..1b8fa16cee 100644 --- a/types/base-x/index.d.ts +++ b/types/base-x/index.d.ts @@ -1,23 +1,21 @@ -// Type definitions for base-x v1.0.1 +// Type definitions for base-x 3.0 // Project: https://github.com/cryptocoinjs/base-x // Definitions by: Ilya Mochalov +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var BaseX: BaseX.Base; -export = BaseX; +/// -declare namespace BaseX { - interface EncodeBuffer { - [index: number]: number; - length: number; - } +import { Buffer } from 'buffer'; - interface BaseConverter { - encode: (buffer: EncodeBuffer) => string; - decode: (string: string) => number[]; - } +export = baseX; - interface Base { - (ALPHABET: string): BaseX.BaseConverter - } +declare function baseX(ALPHABET: string): baseX.BaseConverter; + +declare namespace baseX { + interface BaseConverter { + encode(buffer: Buffer): string; + decodeUnsafe(string: string): Buffer | undefined; + decode(string: string): Buffer; + } } diff --git a/types/base-x/tsconfig.json b/types/base-x/tsconfig.json index d69790c7d6..6f491037d2 100644 --- a/types/base-x/tsconfig.json +++ b/types/base-x/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -20,4 +20,4 @@ "index.d.ts", "base-x-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/base-x/tslint.json b/types/base-x/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/base-x/tslint.json +++ b/types/base-x/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } diff --git a/types/base-x/v1/base-x-tests.ts b/types/base-x/v1/base-x-tests.ts new file mode 100644 index 0000000000..3af01f8ca0 --- /dev/null +++ b/types/base-x/v1/base-x-tests.ts @@ -0,0 +1,12 @@ +import * as basex from 'base-x'; + +const bs16 = basex('0123456789ABCDEF'); + +{ + let encoded: string; + + encoded = bs16.encode([255]); + encoded = bs16.encode({0: 255, length: 1}); +} + +const decoded: number[] = bs16.decode('FF'); diff --git a/types/base-x/v1/index.d.ts b/types/base-x/v1/index.d.ts new file mode 100644 index 0000000000..379eeb8182 --- /dev/null +++ b/types/base-x/v1/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for base-x 1.0 +// Project: https://github.com/cryptocoinjs/base-x +// Definitions by: Ilya Mochalov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare var BaseX: BaseX.Base; +export = BaseX; + +declare namespace BaseX { + interface EncodeBuffer { + [index: number]: number; + length: number; + } + + interface BaseConverter { + encode: (buffer: EncodeBuffer) => string; + decode: (string: string) => number[]; + } + + type Base = (ALPHABET: string) => BaseConverter; +} diff --git a/types/base-x/v1/tsconfig.json b/types/base-x/v1/tsconfig.json new file mode 100644 index 0000000000..b48e3e2932 --- /dev/null +++ b/types/base-x/v1/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "base-x": [ + "base-x/v1" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "base-x-tests.ts" + ] +} diff --git a/types/base-x/v1/tslint.json b/types/base-x/v1/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/base-x/v1/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/bs58/index.d.ts b/types/bs58/index.d.ts index 1539910e12..bb0ef823e6 100644 --- a/types/bs58/index.d.ts +++ b/types/bs58/index.d.ts @@ -3,8 +3,6 @@ // Definitions by: Ilya Mochalov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// - import * as BaseX from 'base-x'; declare namespace base58 { } diff --git a/types/bs58/tsconfig.json b/types/bs58/tsconfig.json index 9e0ed25701..fe7563905d 100644 --- a/types/bs58/tsconfig.json +++ b/types/bs58/tsconfig.json @@ -12,6 +12,11 @@ "typeRoots": [ "../" ], + "paths": { + "base-x": [ + "base-x/v1" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true @@ -20,4 +25,4 @@ "index.d.ts", "bs58-tests.ts" ] -} \ No newline at end of file +}