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

Object Preview Generator

Build a utility that generates human-readable preview strings for large objects and arrays. When working with objects that have many properties or arrays with many elements, it can be useful to display a truncated version that shows only the first few items for readability.

Capabilities

Generate object previews with limited properties

Create a function that serializes objects but limits the number of properties shown. This helps when logging or displaying large objects where showing all properties would be overwhelming.

  • Given an object with 10 properties and a limit of 3, the output includes only 3 properties plus an indicator showing how many were omitted. @test
  • Given an object with 5 properties and a limit of 10, all 5 properties are included in the output. @test

Generate array previews with limited elements

Create a function that serializes arrays but limits the number of elements shown. This is particularly useful for logging large data sets where you only need to see a sample.

  • Given an array with 100 elements and a limit of 5, the output includes only 5 elements plus an indicator showing how many were omitted. @test
  • Given an array with 3 elements and a limit of 5, all 3 elements are included in the output. @test

Handle nested structures with breadth limiting

The preview generation should work correctly with nested objects and arrays, applying the breadth limit at each level of the structure.

  • Given a nested structure where the top-level object has many properties and some of those properties are themselves objects with many properties, the breadth limit applies independently at each nesting level. @test

Implementation

@generates

API

/**
 * Creates a preview generator with a specified property/element limit.
 *
 * @param {number} maxItems - Maximum number of properties/elements to include per object/array
 * @returns {function} A function that generates preview strings
 */
function createPreviewGenerator(maxItems) {
  // Returns a function with signature: (value) => string
}

module.exports = { createPreviewGenerator };

Dependencies { .dependencies }

safe-stable-stringify { .dependency }

Provides JSON serialization with configurable breadth limiting to control how many properties or elements are included in the output.

@satisfied-by

Install with Tessl CLI

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

tile.json