mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #62987 [buffer-json-encoding] Add types by @BendingBender
This commit is contained in:
14
types/buffer-json-encoding/buffer-json-encoding-tests.ts
Normal file
14
types/buffer-json-encoding/buffer-json-encoding-tests.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { encode, decode, encodingLength } from 'buffer-json-encoding';
|
||||
|
||||
encode(Buffer.of(1)); // $ExpectType Buffer
|
||||
encode(Buffer.of(1), 5); // $ExpectType Buffer
|
||||
encode(Buffer.of(1), Buffer.alloc(10)); // $ExpectType Buffer
|
||||
encode(Buffer.of(1), Buffer.alloc(10), 5); // $ExpectType Buffer
|
||||
encode.bytes; // $ExpectType number | undefined
|
||||
|
||||
decode(Buffer.alloc(10)); // $ExpectType Buffer
|
||||
decode(Buffer.alloc(10), 2); // $ExpectType Buffer
|
||||
decode(Buffer.alloc(10), 2, 5); // $ExpectType Buffer
|
||||
decode.bytes; // $ExpectType number | undefined
|
||||
|
||||
encodingLength(Buffer.alloc(10)); // $ExpectType number
|
||||
52
types/buffer-json-encoding/index.d.ts
vendored
Normal file
52
types/buffer-json-encoding/index.d.ts
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Type definitions for buffer-json-encoding 1.0
|
||||
// Project: https://github.com/lachenmayer/buffer-json-encoding
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
/**
|
||||
* An [abstract-encoding](https://github.com/mafintosh/abstract-encoding) compatible JSON encoder
|
||||
* that properly encodes `Buffer`s.
|
||||
*
|
||||
* @param buffer The `Buffer` to encode.
|
||||
* @param [offset=0] The byte offset to encode `buffer` at in the newly allocated `Buffer`.
|
||||
*/
|
||||
export function encode(buffer: Buffer, offset?: number): Buffer;
|
||||
/**
|
||||
* An [abstract-encoding](https://github.com/mafintosh/abstract-encoding) compatible JSON encoder
|
||||
* that properly encodes `Buffer`s.
|
||||
*
|
||||
* @param buffer The `Buffer` to encode.
|
||||
* @param target The `Buffer` to encode the `buffer` into.
|
||||
* @param [offset=0] The byte offset to encode `buffer` at in `target`.
|
||||
*/
|
||||
export function encode(buffer: Buffer, target: Buffer, offset?: number): Buffer;
|
||||
export namespace encode {
|
||||
/**
|
||||
* The amount of bytes used to encode the `Buffer`. This property is set after each call to `encode()`.
|
||||
*/
|
||||
const bytes: number | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* An [abstract-encoding](https://github.com/mafintosh/abstract-encoding) compatible JSON decoder
|
||||
* that properly decodes `Buffer`s.
|
||||
*
|
||||
* @param buffer The `Buffer` to decode a stringified `Buffer` from.
|
||||
* @param [start=0] The byte offset into `buffer` to start decoding the encoded `Buffer`.
|
||||
* @param [end=buffer.length] The byte offset into `buffer` to end decoding the encoded `Buffer`
|
||||
* (not including the byte at the end-offset).
|
||||
*/
|
||||
export function decode(buffer: Buffer, start?: number, end?: number): Buffer;
|
||||
export namespace decode {
|
||||
/**
|
||||
* The amount of bytes used to decode the `Buffer`. This property is set after each call to `decode()`.
|
||||
*/
|
||||
const bytes: number | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The amount of bytes needed to encode `buffer`.
|
||||
*/
|
||||
export function encodingLength(buffer: Buffer): number;
|
||||
23
types/buffer-json-encoding/tsconfig.json
Normal file
23
types/buffer-json-encoding/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"buffer-json-encoding-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/buffer-json-encoding/tslint.json
Normal file
1
types/buffer-json-encoding/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "@definitelytyped/dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user