CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-buffer

Determine if an object is a Buffer without including the full buffer module

93

1.02x
Quality

Pending

Does it follow best practices?

Impact

93%

1.02x

Average score across 9 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

task.mdevals/scenario-6/

Buffer Data Processor

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.

Capabilities

Processes Buffer inputs safely

  • Returns the same Buffer instance when given a Buffer created with Buffer.from([1, 2, 3]) @test
  • Returns the same Buffer instance when given a Buffer created with Buffer.alloc(10) @test

Converts string inputs to Buffer

  • Converts the string "hello" to a Buffer with UTF-8 encoding @test
  • Converts an empty string "" to an empty Buffer @test

Handles invalid inputs appropriately

  • Throws an error with message "Input must be a string or Buffer" when given null @test
  • Throws an error with message "Input must be a string or Buffer" when given a number like 123 @test
  • Throws an error with message "Input must be a string or Buffer" when given a plain object {} @test
  • Throws an error with message "Input must be a string or Buffer" when given an array [1, 2, 3] @test

Implementation

@generates

API

/**
 * 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,
};

Dependencies { .dependencies }

is-buffer { .dependency }

Provides reliable Buffer type detection using constructor-based validation.

@satisfied-by

tile.json