A zero-dependency alternative to cosmiconfig for loading configuration files
89
Build a synchronous configuration loader utility that searches for and loads application configuration files from the filesystem. The utility should handle common configuration scenarios and provide a simple interface for retrieving configuration data.
Your utility should provide the following functionality:
Configuration Search
Direct File Loading
Cache Management
@generates
/**
* Searches for a configuration file starting from the given directory
* @param {string} searchFrom - The directory path to start searching from
* @returns {Object|null} Configuration result with 'config' and 'filepath' properties, or null if not found
*/
function findConfig(searchFrom) {
// Implementation here
}
/**
* Loads a configuration file from the specified path
* @param {string} filepath - The path to the configuration file
* @returns {Object} Configuration result with 'config' and 'filepath' properties
*/
function loadConfig(filepath) {
// Implementation here
}
/**
* Clears all cached configuration data
*/
function clearCache() {
// Implementation here
}
module.exports = {
findConfig,
loadConfig,
clearCache
};.myapprc.json file, the utility returns the parsed configuration and the file path @testProvides configuration file search and loading support.
Install with Tessl CLI
npx tessl i tessl/npm-lilconfigdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10