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

API Field Name Normalizer

Build a utility that normalizes field names in API responses to different naming conventions based on configuration.

Problem Description

You need to create a field name normalizer that can transform object keys in API response data according to specified naming conventions. The normalizer should support converting between different case styles commonly used in APIs (e.g., converting database snake_case to JavaScript camelCase, or vice versa).

Requirements

Your solution should:

  1. Accept an object with string keys and values of any type
  2. Accept a target naming convention as a parameter
  3. Return a new object with all keys transformed to the target convention
  4. Preserve the original values unchanged
  5. Support nested objects (transform keys at all levels)
  6. Support the following naming conventions:
    • camel: camelCase (e.g., firstName)
    • snake: snake_case (e.g., first_name)
    • kebab: kebab-case (e.g., first-name)

Implementation

@generates

API

/**
 * Normalizes field names in an object to a specified naming convention.
 *
 * @param {Object} data - The object whose keys should be normalized
 * @param {string} convention - The target naming convention ('camel', 'snake', or 'kebab')
 * @returns {Object} A new object with normalized keys
 */
function normalizeFields(data, convention) {
  // Implementation here
}

module.exports = { normalizeFields };

Test Cases

  • When given { first_name: "John", last_name: "Doe" } with convention camel, it returns { firstName: "John", lastName: "Doe" } @test
  • When given { firstName: "Jane", lastName: "Smith" } with convention snake, it returns { first_name: "Jane", last_name: "Smith" } @test
  • When given { user_id: 123, is-active: true } with convention kebab, it returns { "user-id": 123, "is-active": true } @test
  • When given nested object { user_data: { first_name: "Bob" } } with convention camel, it returns { userData: { firstName: "Bob" } } @test

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for data transformation.