Skip to main content
Skip to main content

isEncoding

BufferConstructor.isEncoding

isEncoding(encoding): encoding is BufferEncoding

Returns true if encoding is the name of a supported character encoding, or false otherwise.

import { Buffer } from 'buffer';

console.log(Buffer.isEncoding('utf8'));
// Prints: true

console.log(Buffer.isEncoding('hex'));
// Prints: true

console.log(Buffer.isEncoding('utf/8'));
// Prints: false

console.log(Buffer.isEncoding(''));
// Prints: false

Parameters

encodingstringRequired
A character encoding name to check.

Returns

encoding is BufferEncoding

encodingencoding is BufferEncoding

Since

v0.9.1

Was this section helpful?