Skip to main content
Buffer.includes - buffer - Node documentation
method Buffer.includes

Usage in Deno

import { type Buffer } from "node:buffer";
Buffer.includes(
value:
string
| number
| Buffer
,
byteOffset?: number,
encoding?: BufferEncoding,
): boolean

Equivalent to buf.indexOf() !== -1.

import { Buffer } from 'node:buffer';

const buf = Buffer.from('this is a buffer');

console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false

Parameters

value:
string
| number
| Buffer

What to search for.

optional
byteOffset: number = 0

Where to begin searching in buf. If negative, then offset is calculated from the end of buf.

optional
encoding: BufferEncoding = 'utf8'

If value is a string, this is its encoding.

Return Type

boolean

true if value was found in buf, false otherwise.