Skip to content

Commit 9a81831

Browse files
Match DefinitelyTyped types interface name
Co-authored-by: Dimitri Benin <dimitri.benin@gmail.com>
1 parent f037e38 commit 9a81831

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "base-x",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"description": "Fast base encoding / decoding of any given alphabet",
55
"keywords": [
66
"base-x",

src/index.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/// <reference types="node" />
2-
declare function base(ALPHABET: string): {
3-
encode: (source: Buffer) => string;
4-
decodeUnsafe: (source: string) => Buffer | undefined;
5-
decode: (string: string) => Buffer;
6-
};
2+
declare function base(ALPHABET: string): base.BaseConverter;
73
export = base;
4+
declare namespace base {
5+
interface BaseConverter {
6+
encode(buffer: Buffer): string;
7+
decodeUnsafe(string: string): Buffer | undefined;
8+
decode(string: string): Buffer;
9+
}
10+
}

ts_src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// @ts-ignore
88
const _Buffer = require('safe-buffer').Buffer;
99

10-
function base (ALPHABET: string) {
10+
function base (ALPHABET: string): base.BaseConverter {
1111
if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long')
1212

1313
const BASE_MAP = new Uint8Array(256)
@@ -26,7 +26,7 @@ function base (ALPHABET: string) {
2626
const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
2727
const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
2828

29-
function encode (source: Buffer) {
29+
function encode (source: Buffer): string {
3030
if (!_Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
3131
if (source.length === 0) return ''
3232

@@ -151,3 +151,11 @@ function base (ALPHABET: string) {
151151
}
152152

153153
export = base;
154+
155+
declare namespace base {
156+
interface BaseConverter {
157+
encode(buffer: Buffer): string;
158+
decodeUnsafe(string: string): Buffer | undefined;
159+
decode(string: string): Buffer;
160+
}
161+
}

0 commit comments

Comments
 (0)