diff --git a/.gitignore b/.gitignore index b8f34b2..218840d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea coverage/ +node_modules \ No newline at end of file diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0ce63b0 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for biguint-format +// Project: biguint-format https://github.com/T-PWK/flake-idgen +// Definitions by: m-star https://github.com/mstar-kk + +/// + +interface FORMATS { + dec: typeof toDecimalString; + hex: typeof toHexString; + bin: typeof toBinaryString; + oct: typeof toOctetString; +} + +interface formatOption { + format?: string; + groupsize?: number; + delimiter?: string; + padstr?: string; + size?: number; + trim?: boolean; + prefix?: string; +} + +export default function ( + buffer: Buffer, + base: 'dec' | 'hex' | 'bin' | 'oct', + options?: formatOption +): string; + +export function createBuffer(size: number): Buffer; + +export function createBufferFrom(object: object): Buffer; + +export function toDecimalString(buffer: Buffer, options?: formatOption): string; + +export function toBinaryString(buffer: Buffer, options?: formatOption): string; + +/* + * Converts given input (node Buffer or array of bytes) to hexadecimal string 0xDDDD where D is [0-9a-f]. + * All leading 0's are stripped out i.e. [0x00, 0x00, 0x00, 0x01] -> '0x1' + */ +export function toHexString(buffer: Buffer, options?: formatOption): string; + +export function toOctetString(buffer: Buffer, options?: formatOption): string; diff --git a/package.json b/package.json index 2e253df..1ab67c9 100644 --- a/package.json +++ b/package.json @@ -35,5 +35,8 @@ ], "bugs": { "url": "https://github.com/T-PWK/biguint-format/issues" + }, + "devDependencies": { + "@types/node": "^16.7.10" } }