From d81eb34f674e3ddeaf34e6745ca5c5a8d83c1c56 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 1 Jan 2023 16:02:00 -0500 Subject: [PATCH] buffer: add isAscii method --- 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 c690cee485e1a2..51fc590b69fdbc 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -5130,6 +5130,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)`