buffer: add isAscii method

PR-URL: https://github.com/nodejs/node/pull/46046
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Yagiz Nizipli 2023-01-19 22:24:40 -05:00 committed by GitHub
parent 49413ad8ae
commit babe6d7c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 0 deletions

View file

@ -56,6 +56,7 @@ const {
compareOffset,
createFromString,
fill: bindingFill,
isAscii: bindingIsAscii,
isUtf8: bindingIsUtf8,
indexOfBuffer,
indexOfNumber,
@ -1320,11 +1321,20 @@ function isUtf8(input) {
throw new ERR_INVALID_ARG_TYPE('input', ['TypedArray', 'Buffer'], input);
}
function isAscii(input) {
if (isTypedArray(input) || isAnyArrayBuffer(input)) {
return bindingIsAscii(input);
}
throw new ERR_INVALID_ARG_TYPE('input', ['ArrayBuffer', 'Buffer', 'TypedArray'], input);
}
module.exports = {
Buffer,
SlowBuffer,
transcode,
isUtf8,
isAscii,
// Legacy
kMaxLength,