CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-safe-stable-stringify

Deterministic and safely JSON.stringify to quickly serialize JavaScript objects

90

1.08x

Evaluation90%

1.08x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-4/

Binary Data Logger

A logging utility that serializes binary data buffers (TypedArrays) to JSON format for debugging and analysis purposes.

Requirements

Create a module that exports a function logBinaryData which serializes TypedArray instances to JSON strings. The function should handle various typed array types and preserve any custom properties attached to the arrays.

Core Functionality

The function should:

  • Accept a TypedArray (such as Uint8Array, Int32Array, Float64Array, etc.) as input
  • Return a JSON string representation of the array
  • Include numeric indices in the output
  • Include any additional custom properties that have been added to the array instance
  • Use deterministic ordering to ensure consistent output across multiple calls

Behavioral Requirements

  • The output must be a valid JSON string
  • Numeric array indices should be serialized in order
  • Custom properties added to the typed array should also be included in the serialization
  • The serialization should be deterministic (same input always produces same output)
  • The function should work with all standard TypedArray types (Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array)

Test Cases

  • Given a Uint8Array with values [1, 2, 3], the function returns a valid JSON string containing these values. @test
  • Given a Float32Array with custom property metadata: "test", the function includes both array elements and the metadata property. @test
  • Given an Int32Array with values [-5, 0, 5], calling the function twice produces identical output strings. @test

Implementation

@generates

API

/**
 * Serializes a TypedArray to a JSON string, including numeric indices and custom properties.
 *
 * @param {TypedArray} typedArray - The typed array to serialize
 * @returns {string} JSON string representation of the typed array
 */
function logBinaryData(typedArray) {
  // Implementation here
}

module.exports = { logBinaryData };

Dependencies { .dependencies }

safe-stable-stringify { .dependency }

Provides deterministic JSON serialization with TypedArray support.

Install with Tessl CLI

npx tessl i tessl/npm-safe-stable-stringify

tile.json