Determine if an object is a Buffer without including the full buffer module
93
Pending
Does it follow best practices?
Impact
93%
1.02xAverage score across 9 eval scenarios
Pending
The risk profile of this skill
Create a utility module that processes various data inputs and converts them to Buffer format when needed. The module must properly validate whether inputs are already Buffers before attempting conversion, using reliable type checking that works across different JavaScript environments.
Buffer.from([1, 2, 3]) @testBuffer.alloc(10) @test"hello" to a Buffer with UTF-8 encoding @test"" to an empty Buffer @test"Input must be a string or Buffer" when given null @test"Input must be a string or Buffer" when given a number like 123 @test"Input must be a string or Buffer" when given a plain object {} @test"Input must be a string or Buffer" when given an array [1, 2, 3] @test@generates
/**
* Processes input data and ensures it's in Buffer format.
* If input is already a Buffer, returns it unchanged.
* If input is a string, converts it to Buffer with UTF-8 encoding.
* For any other type, throws an error.
*
* @param {*} data - The input data to process (string or Buffer)
* @returns {Buffer} The data as a Buffer
* @throws {Error} If input is not a string or Buffer
*/
function toBuffer(data) {
// IMPLEMENTATION HERE
}
module.exports = {
toBuffer,
};Provides reliable Buffer type detection using constructor-based validation.
@satisfied-by
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9