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
Build a TypeScript utility that validates and processes different types of data inputs, distinguishing between Buffer objects and other data types.
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:
type: "buffer"size: the buffer lengthcontent: the buffer converted to a hex stringtype: "other"value: the input converted to a string representation@generates
interface BufferResult {
type: "buffer";
size: number;
content: string;
}
interface OtherResult {
type: "other";
value: string;
}
type ProcessResult = BufferResult | OtherResult;
export function processInput(input: any): ProcessResult;Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f]), returns { type: "buffer", size: 5, content: "48656c6c6f" } @test"hello", returns { type: "other", value: "hello" } @test42, returns { type: "other", value: "42" } @testnull, returns { type: "other", value: "null" } @testProvides Buffer type detection with TypeScript support.
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9