Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.unescape@4.0.x
tile.json

tessl/npm-lodash-unescape

tessl install tessl/npm-lodash-unescape@4.0.0

Converts HTML entities to their corresponding characters in a string

Agent Success

Agent success rate when using this tile

85%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.39x

Baseline

Agent success rate without this tile

61%

task.mdevals/scenario-1/

Configuration Query System

Build a configuration query system that allows users to extract and match values from nested configuration objects using string path notation.

Requirements

Implement a module that provides the following functionality:

  1. Value Extraction: Create a function getValue(config, path) that safely extracts values from nested configuration objects using dot notation paths (e.g., "server.port" or "database.connection.host"). If the path doesn't exist, return undefined.

  2. Property Matcher: Create a function createPropertyMatcher(path, value) that returns a predicate function. This predicate should check if objects have a property at the given path that matches the specified value. The predicate should work with arrays of objects (e.g., for filtering).

  3. Path Normalization: Create a function normalizePath(pathString) that converts various path formats into a standardized array format. It should handle:

    • Dot notation: "a.b.c" → ["a", "b", "c"]
    • Bracket notation: "a[0].b" → ["a", "0", "b"]
    • Mixed notation: "a.b[1].c" → ["a", "b", "1", "c"]

Test Cases

Basic value extraction { @test }

@test

const config = {
  server: {
    port: 3000,
    host: 'localhost'
  },
  database: {
    connection: {
      host: 'db.example.com',
      port: 5432
    }
  }
};

getValue(config, 'server.port'); // returns 3000
getValue(config, 'database.connection.host'); // returns 'db.example.com'
getValue(config, 'server.missing'); // returns undefined

Property matcher filtering { @test }

@test

const servers = [
  { name: 'web-1', status: 'active', port: 8080 },
  { name: 'web-2', status: 'inactive', port: 8081 },
  { name: 'web-3', status: 'active', port: 8082 }
];

const isActive = createPropertyMatcher('status', 'active');
servers.filter(isActive); // returns [{name: 'web-1', ...}, {name: 'web-3', ...}]

const hasPort8080 = createPropertyMatcher('port', 8080);
servers.filter(hasPort8080); // returns [{name: 'web-1', ...}]

Path normalization { @test }

@test

normalizePath('a.b.c'); // returns ['a', 'b', 'c']
normalizePath('users[0].name'); // returns ['users', '0', 'name']
normalizePath('data.items[2].value'); // returns ['data', 'items', '2', 'value']
normalizePath('simple'); // returns ['simple']

Implementation

@generates

API

/**
 * Safely extracts a value from a nested object using a path string
 * @param {Object} config - The configuration object to query
 * @param {string} path - The path to the desired value (e.g., 'server.port')
 * @returns {*} The value at the path, or undefined if not found
 */
function getValue(config, path) {
  // Implementation here
}

/**
 * Creates a predicate function that checks if objects have a property matching a value
 * @param {string} path - The path to the property to check
 * @param {*} value - The value to match against
 * @returns {Function} A predicate function that takes an object and returns true/false
 */
function createPropertyMatcher(path, value) {
  // Implementation here
}

/**
 * Converts a path string into an array of path segments
 * @param {string} pathString - The path string to normalize
 * @returns {Array<string>} An array of path segments
 */
function normalizePath(pathString) {
  // Implementation here
}

module.exports = {
  getValue,
  createPropertyMatcher,
  normalizePath
};

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for working with objects and property paths.