DefinitelyTyped/types/lexicographic-integer/index.d.ts
Carson Farmer 729be11faf feat: adds types and tests for lexicographic-integer (#41025)
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
2019-12-18 10:49:57 -08:00

17 lines
808 B
TypeScript

// Type definitions for lexicographic-integer 1.1
// Project: https://github.com/substack/lexicographic-integer
// Definitions by: Carson Farmer <https://github.com/me>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Return an array of byte values or a lexicographic hex string for an input integer.
* @param n The input integer as a javascript number.
* @param enc The encoding to use. Can be one of 'array' (default) or 'hex'.
*/
export function pack<T extends 'hex' | 'array' = 'array'>(n: number, enc?: T): T extends 'hex' ? string : T extends 'array' ? number[] : never;
/**
* Convert an array of bytes returned by .pack() back into the original javascript number.
* @param xs An array of bytes or a hex string.
*/
export function unpack(xs: number[] | string): number;