CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lodash-unescape

Converts HTML entities to their corresponding characters in a string

Overall
score

85%

Evaluation85%

1.39x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-8/

User Configuration Manager

Build a utility that manages user configuration objects by extracting, filtering, and transforming their properties and values.

Requirements

Implement a module that provides functions to analyze and manipulate configuration objects:

  1. Extract configuration keys: Create a function getConfigKeys(config) that returns an array of all configuration property names (own properties only).

  2. Extract configuration values: Create a function getConfigValues(config) that returns an array of all configuration values (own properties only).

  3. Get configuration entries: Create a function getConfigEntries(config) that returns an array of key-value pairs as [key, value] tuples for all own properties.

  4. Filter by value type: Create a function filterByValueType(config, type) that returns an object containing only the properties whose values match the specified JavaScript type string (e.g., 'string', 'number', 'boolean'). Use typeof to check value types.

  5. Get all keys including inherited: Create a function getAllKeys(config) that returns an array of all property names, including inherited properties from the prototype chain.

Behavior

  • All functions should handle edge cases like null, undefined, and empty objects gracefully
  • The filtering function should preserve the original object structure for matched properties
  • Functions should work with nested configuration objects
  • Property extraction should maintain the order of properties as they appear in the object

Test Cases

  • Given {theme: 'dark', fontSize: 14, showNotifications: true}, getConfigKeys returns ['theme', 'fontSize', 'showNotifications'] @test

  • Given {theme: 'dark', fontSize: 14, showNotifications: true}, getConfigValues returns ['dark', 14, true] @test

  • Given {theme: 'dark', fontSize: 14}, getConfigEntries returns [['theme', 'dark'], ['fontSize', 14]] @test

  • Given {theme: 'dark', fontSize: 14, showNotifications: true} and type 'string', filterByValueType returns {theme: 'dark'} @test

  • Given an object with inherited properties, getAllKeys returns both own and inherited property names @test

Implementation

@generates

API

/**
 * Returns an array of own enumerable property names.
 * @param {Object} config - The configuration object.
 * @returns {string[]} Array of property names.
 */
function getConfigKeys(config) {
  // IMPLEMENTATION HERE
}

/**
 * Returns an array of own enumerable property values.
 * @param {Object} config - The configuration object.
 * @returns {any[]} Array of property values.
 */
function getConfigValues(config) {
  // IMPLEMENTATION HERE
}

/**
 * Returns an array of own enumerable key-value pairs.
 * @param {Object} config - The configuration object.
 * @returns {Array<[string, any]>} Array of [key, value] pairs.
 */
function getConfigEntries(config) {
  // IMPLEMENTATION HERE
}

/**
 * Filters the configuration object by value type.
 * @param {Object} config - The configuration object.
 * @param {string} type - The type to filter by (e.g., 'string', 'number', 'boolean').
 * @returns {Object} Object containing only properties matching the specified type.
 */
function filterByValueType(config, type) {
  // IMPLEMENTATION HERE
}

/**
 * Returns an array of all property names, including inherited properties.
 * @param {Object} config - The configuration object.
 * @returns {string[]} Array of all property names.
 */
function getAllKeys(config) {
  // IMPLEMENTATION HERE
}

module.exports = {
  getConfigKeys,
  getConfigValues,
  getConfigEntries,
  filterByValueType,
  getAllKeys,
};

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for working with objects and their properties.

Install with Tessl CLI

npx tessl i tessl/npm-lodash-unescape

tile.json