From 7b220b5616207bcd711b61662609a14b842e717f Mon Sep 17 00:00:00 2001 From: duowen Date: Mon, 6 Sep 2021 17:25:23 +0800 Subject: [PATCH 1/4] add type definitions file index.d.ts --- .gitignore | 1 + index.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ 3 files changed, 46 insertions(+) create mode 100644 index.d.ts 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..f23884d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,42 @@ +// 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; +} + +export default function ( + buffer: Buffer, + base: string, + 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" } } From e96d90db258b6e94ed65168a47199ddef11961c1 Mon Sep 17 00:00:00 2001 From: duowen Date: Mon, 6 Sep 2021 17:40:28 +0800 Subject: [PATCH 2/4] change paramter options --- index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index f23884d..ecb1c5e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,16 +12,16 @@ interface FORMATS { } interface formatOption { - format: string; - groupsize: number; - delimiter: string; - padstr: string; - size: number; + format?: string; + groupsize?: number; + delimiter?: string; + padstr?: string; + size?: number; } export default function ( buffer: Buffer, - base: string, + base: 'dec' | 'hex' | 'bin' | 'oct', options: formatOption ): string; From a41adceeaca4fd84fff4971c3db4acef79482fa1 Mon Sep 17 00:00:00 2001 From: duowen Date: Mon, 6 Sep 2021 17:47:42 +0800 Subject: [PATCH 3/4] add format options --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index ecb1c5e..2ee8ac0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,6 +17,8 @@ interface formatOption { delimiter?: string; padstr?: string; size?: number; + trim?: boolean; + prefix?: string; } export default function ( From 621bfb94353fd8db1552f68a64534bf19b7077f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E9=97=BB?= Date: Tue, 4 Jan 2022 13:28:06 +0800 Subject: [PATCH 4/4] change property to be optional --- index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2ee8ac0..0ce63b0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -24,21 +24,21 @@ interface formatOption { export default function ( buffer: Buffer, base: 'dec' | 'hex' | 'bin' | 'oct', - options: formatOption + 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 toDecimalString(buffer: Buffer, options?: formatOption): string; -export function toBinaryString(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 toHexString(buffer: Buffer, options?: formatOption): string; -export function toOctetString(buffer: Buffer, options: formatOption): string; +export function toOctetString(buffer: Buffer, options?: formatOption): string;