From 3cf17699bab2daffc293a6baef4adaea200cc68d Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 19 Jan 2023 22:24:40 -0500 Subject: [PATCH] buffer: add isAscii method PR-URL: https://github.com/nodejs/node/pull/46046 Reviewed-By: Antoine du Hamel Reviewed-By: Matteo Collina --- doc/api/buffer.md | 14 ++++++++++ lib/buffer.js | 10 +++++++ src/node_buffer.cc | 17 +++++++++++ test/parallel/test-buffer-isascii.js | 42 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 test/parallel/test-buffer-isascii.js diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 5a387089c26d72..87d8cbf42bd9bf 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -5126,6 +5126,20 @@ For code running using Node.js APIs, converting between base64-encoded strings and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.** +### `buffer.isAscii(input)` + + + +* input {Buffer | ArrayBuffer | TypedArray} The input to validate. +* Returns: {boolean} + +This function returns `true` if `input` contains only valid ASCII-encoded data, +including the case in which `input` is empty. + +Throws if the `input` is a detached array buffer. + ### `buffer.isUtf8(input)`