includes
fun includes(value: String, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean(source)
fun includes(value: Double, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean(source)
fun includes(value: Buffer, byteOffset: Number = definedExternally, encoding: BufferEncoding = definedExternally): Boolean(source)
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
Content copied to clipboard
Since
v5.3.0
Return
true
if value
was found in buf
, false
otherwise.
Parameters
value
What to search for.
encoding='utf8' If value
is a string, this is its encoding.