Skip to content

Commit 7a62045

Browse files
committed
feat: ts definitions
1 parent a20cf8a commit 7a62045

8 files changed

+63
-2
lines changed

compare.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export = compare;
2+
/**
3+
* Can be used with Array.sort to sort and array with Uint8Array entries
4+
*
5+
* @param {Uint8Array} a
6+
* @param {Uint8Array} b
7+
* @returns {Number}
8+
*/
9+
declare function compare(a: Uint8Array, b: Uint8Array): number;

concat.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export = concat;
2+
/**
3+
* Returns a new Uint8Array created by concatenating the passed ArrayLikes
4+
*
5+
* @param {Array<ArrayLike<number>>} arrays
6+
* @param {Number} length
7+
* @returns {Uint8Array}
8+
*/
9+
declare function concat(arrays: Array<ArrayLike<number>>, length: number): Uint8Array;

equals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export = equals;
2+
/**
3+
* Returns true if the two passed Uint8Arrays have the same content
4+
*
5+
* @param {Uint8Array} a
6+
* @param {Uint8Array} b
7+
* @returns {boolean}
8+
*/
9+
declare function equals(a: Uint8Array, b: Uint8Array): boolean;

from-string.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export = fromString;
2+
/**
3+
* Create a `Uint8Array` from the passed string
4+
*
5+
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
6+
*
7+
* Also `ascii` which is similar to node's 'binary' encoding.
8+
*
9+
* @param {String} string
10+
* @param {String} [encoding=utf8] utf8, base16, base64, base64urlpad, etc
11+
* @returns {Uint8Array}
12+
* @see {@link https://www.npmjs.com/package/multibase|multibase} for supported encodings other than `utf8`
13+
*/
14+
declare function fromString(string: string, encoding?: string): Uint8Array;

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare const compare: typeof import("./compare");
2+
export declare const concat: typeof import("./concat");
3+
export declare const equals: typeof import("./equals");
4+
export declare const fromString: typeof import("./from-string");
5+
export declare const toString: typeof import("./to-string");

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"equals.js",
1313
"from-string.js",
1414
"index.js",
15-
"to-string.js"
15+
"to-string.js",
16+
"*.d.ts"
1617
],
1718
"repository": {
1819
"type": "git",

to-string.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export = toString;
2+
/**
3+
* Turns a `Uint8Array` into a string.
4+
*
5+
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
6+
*
7+
* Also `ascii` which is similar to node's 'binary' encoding.
8+
*
9+
* @param {Uint8Array} array The array to turn into a string
10+
* @param {String} [encoding=utf8] The encoding to use
11+
* @returns {String}
12+
* @see {@link https://www.npmjs.com/package/multibase|multibase} for supported encodings other than `utf8`
13+
*/
14+
declare function toString(array: Uint8Array, encoding?: string): string;

0 commit comments

Comments
 (0)