|
3 | 3 | // Definitions by: David Brockman Smoliansky <https://github.com/dbrockman> |
4 | 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
5 | 5 |
|
6 | | -/// <reference types="node"/> |
| 6 | +interface Varint { |
| 7 | + encode: { |
| 8 | + /** |
| 9 | + * Encodes `num` into `buffer` starting at `offset`. returns `buffer`, with the encoded varint written into it. |
| 10 | + * `varint.encode.bytes` will now be set to the number of bytes modified. |
| 11 | + */ |
| 12 | + (num: number, buffer: Uint8Array, offset?: number): Buffer; |
7 | 13 |
|
8 | | -export const encode: { |
9 | | - /** |
10 | | - * Encodes `num` into `buffer` starting at `offset`. returns `buffer`, with the encoded varint written into it. |
11 | | - * `varint.encode.bytes` will now be set to the number of bytes modified. |
12 | | - */ |
13 | | - (num: number, buffer: Uint8Array, offset?: number): Buffer; |
| 14 | + /** |
| 15 | + * Encodes `num` into `array` starting at `offset`. returns `array`, with the encoded varint written into it. |
| 16 | + * If `array` is not provided, it will default to a new array. |
| 17 | + * `varint.encode.bytes` will now be set to the number of bytes modified. |
| 18 | + */ |
| 19 | + (num: number, array?: number[], offset?: number): number[] |
14 | 20 |
|
15 | | - /** |
16 | | - * Encodes `num` into `array` starting at `offset`. returns `array`, with the encoded varint written into it. |
17 | | - * If `array` is not provided, it will default to a new array. |
18 | | - * `varint.encode.bytes` will now be set to the number of bytes modified. |
19 | | - */ |
20 | | - (num: number, array?: number[], offset?: number): number[] |
| 21 | + /** |
| 22 | + * Similar to `decode.bytes` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). |
| 23 | + * You can access this via `varint.encode.bytes` which holds the number of bytes written in the last encode. |
| 24 | + */ |
| 25 | + bytes: number |
| 26 | + }, |
21 | 27 |
|
22 | | - /** |
23 | | - * Similar to `decode.bytes` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). |
24 | | - * You can access this via `varint.encode.bytes` which holds the number of bytes written in the last encode. |
25 | | - */ |
26 | | - bytes: number |
27 | | -} |
| 28 | + decode: { |
| 29 | + /** |
| 30 | + * Decodes `data`, which can be either a buffer or array of integers, from position `offset` or default 0 and returns the decoded original integer. |
| 31 | + * Throws a `RangeError` when `data` does not represent a valid encoding. |
| 32 | + */ |
| 33 | + (buf: Uint8Array | number[], offset?: number): number |
28 | 34 |
|
29 | | -export const decode: { |
30 | | - /** |
31 | | - * Decodes `data`, which can be either a buffer or array of integers, from position `offset` or default 0 and returns the decoded original integer. |
32 | | - * Throws a `RangeError` when `data` does not represent a valid encoding. |
33 | | - */ |
34 | | - (buf: Uint8Array | number[], offset?: number): number |
| 35 | + /** |
| 36 | + * If you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytes`. |
| 37 | + * This is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. |
| 38 | + */ |
| 39 | + bytes: number |
| 40 | + }, |
35 | 41 |
|
36 | 42 | /** |
37 | | - * If you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytes`. |
38 | | - * This is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. |
| 43 | + * returns the number of bytes this number will be encoded as, up to a maximum of 8. |
39 | 44 | */ |
40 | | - bytes: number |
| 45 | + encodingLength(num: number): number |
41 | 46 | } |
42 | 47 |
|
43 | | -/** |
44 | | - * returns the number of bytes this number will be encoded as, up to a maximum of 8. |
45 | | - */ |
46 | | -export function encodingLength(num: number): number |
| 48 | +declare const varint:Varint |
| 49 | +export default varint |
0 commit comments