Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

lilconfig

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Issues
File Explorer

Advanced tools

lilconfig

A zero-dependency alternative to cosmiconfig

    2.0.6latest

Version published
Maintainers
1
Weekly downloads
7,943,043
decreased by-21.08%

Weekly downloads

Changelog

Source

v2.0.6 adds missing LICENSE file

Thanks for reporting @edgan 👏

Readme

Source

Lilconfig ⚙️

npm version install size Coverage Status

A zero-dependency alternative to cosmiconfig with the same API.

Installation

npm install lilconfig

Usage

import {lilconfig, lilconfigSync} from 'lilconfig'; // all keys are optional const options = { stopDir: '/Users/you/some/dir', searchPlaces: ['package.json', 'myapp.conf.js'], ignoreEmptySearchPlaces: false } lilconfig( 'myapp', options // optional ).search() // Promise<LilconfigResult> lilconfigSync( 'myapp', options // optional ).load(pathToConfig) // LilconfigResult /** * LilconfigResult * { * config: any; // your config * filepath: string; * } */

Difference to cosmiconfig

Lilconfig does not intend to be 100% compatible with cosmiconfig but tries to mimic it where possible. The key differences are:

  • no support for yaml files out of the box(lilconfig attempts to parse files with no extension as JSON instead of YAML). You can still add the support for YAML files by providing a loader, see an example below.
  • no cache

Options difference between the two.

cosmiconfig optionlilconfig
cache
loaders
ignoreEmptySearchPlaces
packageProp
searchPlaces
stopDir
transform

Loaders examples

Yaml loader

If you need the YAML support you can provide your own loader

import {lilconfig} from 'lilconfig'; import yaml from 'yaml'; function loadYaml(filepath, content) { return yaml.parse(content); } const options = { loaders: { '.yaml': loadYaml, '.yml': loadYaml, // loader for files with no extension noExt: loadYaml } }; lilconfig('myapp', options) .search() .then(result => { result // {config, filepath} });

ESM loader

Lilconfig v2 does not support ESM modules out of the box. However, you can support it with a custom a loader. Note that this will only work with the async lilconfig function and won't work with the sync lilconfigSync.

import {lilconfig} from 'lilconfig'; const loadEsm = filepath => import(filepath); lilconfig('myapp', { loaders: { '.js': loadEsm, '.mjs': loadEsm, } }) .search() .then(result => { result // {config, filepath} result.config.default // if config uses `export default` });

Version correlation

  • lilconig v1 → cosmiconfig v6
  • lilconig v2 → cosmiconfig v7

Keywords

FAQs

What is lilconfig?

A zero-dependency alternative to cosmiconfig

Is lilconfig popular?

The npm package lilconfig receives a total of 6,622,230 weekly downloads. As such, lilconfig popularity was classified as popular.

Is lilconfig well maintained?

We found that lilconfig demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 10 Jul 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc