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-8/

Binary Data Type Checker

Build a utility function that checks whether inputs are Buffer objects for a file processing system. The system needs to determine if incoming data is binary (Buffer) or needs conversion.

Requirements

Create a function checkBinaryData(data) that:

  1. Returns a result object with two properties:

    • isBinary: boolean that is true if the input is a Buffer, false otherwise
    • needsConversion: boolean that is true if the input is not a Buffer (needs conversion to Buffer)
  2. Handles various input types safely:

    • Buffer objects created with Buffer.from(), Buffer.alloc(), etc.
    • Non-Buffer types like strings, numbers, arrays, objects, null, undefined
  3. Works without throwing errors for any input type

Test Cases

  • Returns { isBinary: true, needsConversion: false } for Buffer.alloc(10) @test
  • Returns { isBinary: true, needsConversion: false } for Buffer.from([1, 2, 3]) @test
  • Returns { isBinary: false, needsConversion: true } for string "hello" @test
  • Returns { isBinary: false, needsConversion: true } for null @test
  • Returns { isBinary: false, needsConversion: true } for array [1, 2, 3] @test

Implementation

@generates

API

/**
 * Checks if data is binary (Buffer) format.
 *
 * @param {any} data - The data to check
 * @returns {Object} Result with isBinary and needsConversion properties
 */
function checkBinaryData(data) {
  // IMPLEMENTATION HERE
}

module.exports = { checkBinaryData };

Dependencies { .dependencies }

is-buffer { .dependency }

Provides lightweight Buffer type detection without requiring the full Buffer module.

tile.json