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

Buffer Validation Utility

Build a TypeScript utility that validates and processes different types of data inputs, distinguishing between Buffer objects and other data types.

Requirements

Your utility should provide a function that accepts various input types and performs type-safe operations based on whether the input is a Buffer or not. The function should have proper TypeScript type definitions to ensure compile-time type safety.

Implement a module that exports a processInput function with the following behavior:

  1. The function accepts any type of input
  2. If the input is a Buffer, return an object with:
    • type: "buffer"
    • size: the buffer length
    • content: the buffer converted to a hex string
  3. If the input is not a Buffer, return an object with:
    • type: "other"
    • value: the input converted to a string representation
  4. The function should have proper TypeScript type annotations for both parameters and return values

Implementation

@generates

API

interface BufferResult {
  type: "buffer";
  size: number;
  content: string;
}

interface OtherResult {
  type: "other";
  value: string;
}

type ProcessResult = BufferResult | OtherResult;

export function processInput(input: any): ProcessResult;

Test Cases

  • When given Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f]), returns { type: "buffer", size: 5, content: "48656c6c6f" } @test
  • When given the string "hello", returns { type: "other", value: "hello" } @test
  • When given the number 42, returns { type: "other", value: "42" } @test
  • When given null, returns { type: "other", value: "null" } @test

Dependencies { .dependencies }

is-buffer { .dependency }

Provides Buffer type detection with TypeScript support.

tile.json