or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-9/

Nested Path Accessor

Create a small helper module for reading, writing, updating, and removing values inside nested objects or arrays using property paths.

Capabilities

Read values with fallback

  • For { user: { profile: { name: "Ava" } } }, reading "user.profile.name" returns "Ava", while reading "user.profile.age" with a default of 30 returns 30. @test
  • When given a path as an array such as ["settings", "themes", 0], it returns the value at that location if present. @test

Write values into missing branches

  • Writing "#3366ff" to "appearance.palette.primary" creates intermediate objects if needed, stores the value on the original target, and returns that same target. @test

Update values via function

  • Applying an updater that increments numbers at "metrics.views" starts from the provided default when the path is missing, stores the updated number, and returns the mutated target. @test

Remove values by path

  • Removing "session.cache.token" deletes the property from the target and reports success; repeating the call reports failure without throwing. @test

Implementation

@generates

API

/**
 * Reads a value from a nested object/array using a string or string[] path,
 * returning defaultValue when no value exists.
 */
export function readAtPath(target, path, defaultValue);

/**
 * Writes value to target at the given path, creating intermediate objects/arrays
 * as needed. Mutates and returns target.
 */
export function writeAtPath(target, path, value);

/**
 * Applies updater to the current value at path (or defaultValue when missing),
 * stores the result at that path, and returns the mutated target.
 */
export function updateAtPath(target, path, updater, defaultValue);

/**
 * Removes the value at the given path. Returns true when a deletion occurred,
 * otherwise false. Mutates target.
 */
export function removeAtPath(target, path);

Dependencies { .dependencies }

lodash { .dependency }

Utility toolkit for property-path reads, writes, updates, and deletions.