Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type definitions file index.d.ts #6

Merged
merged 4 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
coverage/
node_modules
44 changes: 44 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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

/// <reference types="node" />

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;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
],
"bugs": {
"url": "https://github.com/T-PWK/biguint-format/issues"
},
"devDependencies": {
"@types/node": "^16.7.10"
}
}