CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lilconfig

A zero-dependency alternative to cosmiconfig for loading configuration files

89

1.21x
Overview
Eval results
Files

task.mdevals/scenario-6/

Configuration Value Extractor

A utility that extracts configuration values from package.json files using property paths. The utility must properly handle edge cases where property paths reference null or undefined values.

Requirements

Build a configuration extractor that:

  • Accepts a package.json file path and a property path (e.g., "config.tool" or ["config", "tool"])
  • Returns the configuration value if it exists
  • Returns null when a property in the path is undefined
  • Throws an error when a property in the path is explicitly null

Test Cases

  • Given a package.json with nested config at {"config": {"tool": "value"}}, extracting path ["config", "tool"] returns "value" @test
  • Given a package.json where a property in the path doesn't exist, extracting that path returns null @test
  • Given a package.json where a property in the path is explicitly null, extracting that path throws an error @test
  • Given a package.json with deeply nested config at {"app": {"settings": {"theme": "dark"}}}, extracting path ["app", "settings", "theme"] returns "dark" @test

Implementation

@generates

API

/**
 * Extracts a configuration value from a package.json file using a property path.
 *
 * @param {string} packageJsonPath - Path to the package.json file
 * @param {string|string[]} propertyPath - Property path as dot-notation string or array
 * @returns {any|null} The configuration value, or null if path doesn't exist
 * @throws {Error} When a property in the path is explicitly null
 */
function extractConfig(packageJsonPath, propertyPath) {
  // Implementation here
}

module.exports = { extractConfig };

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file loading and property path extraction with proper null/undefined handling.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json