Skip to content

Commit

Permalink
feat: ts definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Sep 9, 2020
1 parent a20cf8a commit 7a62045
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 2 deletions.
9 changes: 9 additions & 0 deletions compare.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export = compare;
/**
* Can be used with Array.sort to sort and array with Uint8Array entries
*
* @param {Uint8Array} a
* @param {Uint8Array} b
* @returns {Number}
*/
declare function compare(a: Uint8Array, b: Uint8Array): number;
9 changes: 9 additions & 0 deletions concat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export = concat;
/**
* Returns a new Uint8Array created by concatenating the passed ArrayLikes
*
* @param {Array<ArrayLike<number>>} arrays
* @param {Number} length
* @returns {Uint8Array}
*/
declare function concat(arrays: Array<ArrayLike<number>>, length: number): Uint8Array;
9 changes: 9 additions & 0 deletions equals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export = equals;
/**
* Returns true if the two passed Uint8Arrays have the same content
*
* @param {Uint8Array} a
* @param {Uint8Array} b
* @returns {boolean}
*/
declare function equals(a: Uint8Array, b: Uint8Array): boolean;
14 changes: 14 additions & 0 deletions from-string.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export = fromString;
/**
* Create a `Uint8Array` from the passed string
*
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
*
* Also `ascii` which is similar to node's 'binary' encoding.
*
* @param {String} string
* @param {String} [encoding=utf8] utf8, base16, base64, base64urlpad, etc
* @returns {Uint8Array}
* @see {@link https://www.npmjs.com/package/multibase|multibase} for supported encodings other than `utf8`
*/
declare function fromString(string: string, encoding?: string): Uint8Array;
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare const compare: typeof import("./compare");
export declare const concat: typeof import("./concat");
export declare const equals: typeof import("./equals");
export declare const fromString: typeof import("./from-string");
export declare const toString: typeof import("./to-string");
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"equals.js",
"from-string.js",
"index.js",
"to-string.js"
"to-string.js",
"*.d.ts"
],
"repository": {
"type": "git",
Expand Down
14 changes: 14 additions & 0 deletions to-string.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export = toString;
/**
* Turns a `Uint8Array` into a string.
*
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
*
* Also `ascii` which is similar to node's 'binary' encoding.
*
* @param {Uint8Array} array The array to turn into a string
* @param {String} [encoding=utf8] The encoding to use
* @returns {String}
* @see {@link https://www.npmjs.com/package/multibase|multibase} for supported encodings other than `utf8`
*/
declare function toString(array: Uint8Array, encoding?: string): string;

0 comments on commit 7a62045

Please sign in to comment.