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

Binary Data Validator

Build a validator utility for a data processing pipeline that checks if input values are binary data (Buffer objects) with optimal performance.

Context

You are building a high-throughput data processing system that handles thousands of inputs per second. The system must validate that incoming data is in Buffer format before processing, but this validation is in the critical path and cannot introduce significant overhead.

Requirements

Create a validation module that:

  1. Validates Buffer Type: Implements a function that determines whether a given input is a Buffer object
  2. High-frequency Usage: Is optimized for being called thousands of times with minimal performance impact
  3. Type Safety: Returns boolean results (true for Buffer, false for any non-Buffer type)
  4. Null Safety: Handles null and undefined inputs gracefully without throwing errors

Expected Behavior

The validator should:

  • Return true when given any type of Buffer (created with Buffer.from(), Buffer.alloc(), etc.)
  • Return false for all non-Buffer types including null, undefined, strings, numbers, arrays, and plain objects
  • Execute efficiently enough to be used in performance-critical code paths
  • Avoid unnecessary operations, object creation, or complex computations

Test Cases

  • Validates that Buffer.alloc(10) returns true @test
  • Validates that Buffer.from([1, 2, 3]) returns true @test
  • Returns false for null without throwing errors @test
  • Returns false for undefined without throwing errors @test
  • Returns false for string "test data" @test
  • Returns false for plain object {} @test

Implementation

@generates

API

/**
 * Checks if a value is a Buffer with minimal performance overhead.
 *
 * @param {any} value - The value to check
 * @returns {boolean} true if value is a Buffer, false otherwise
 */
function isValidBuffer(value) {
  // Implementation here
}

module.exports = isValidBuffer;

Dependencies { .dependencies }

is-buffer { .dependency }

Provides efficient Buffer type detection

@satisfied-by

tile.json