From 85d7e56d14e3bde6b67423c6372cb344d2795210 Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 5 Sep 2020 18:43:51 -0500 Subject: [PATCH] fix(buffer): restrict encodings --- docs/api/js-utils.encode.md | 4 ++-- src/Buffer.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/api/js-utils.encode.md b/docs/api/js-utils.encode.md index 665416e..129790c 100644 --- a/docs/api/js-utils.encode.md +++ b/docs/api/js-utils.encode.md @@ -9,7 +9,7 @@ Concatenate then encode a list of buffers. Signature: ```typescript -export declare function encode(chunks: Array, encoding: string): string; +export declare function encode(chunks: Array, encoding: AllowedBufferEncoding): string; ``` ## Parameters @@ -17,7 +17,7 @@ export declare function encode(chunks: Array, encoding: string): string; | Parameter | Type | Description | | --- | --- | --- | | chunks | Array<Buffer> | | -| encoding | string | | +| encoding | AllowedBufferEncoding | | Returns: diff --git a/src/Buffer.ts b/src/Buffer.ts index f336504..8bc0f8c 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -1,3 +1,5 @@ +export type AllowedBufferEncoding = 'ascii' | 'utf-8'; + /** * Concatenate a list of buffers. * @@ -13,7 +15,7 @@ export function concat(chunks: Array): Buffer { * * @public */ -export function encode(chunks: Array, encoding: string): string { +export function encode(chunks: Array, encoding: AllowedBufferEncoding): string { if (chunks.length === 0) { return ''; }