lilconfig
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.3 • Public • Published

    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 option lilconfig
    cache
    loaders
    ignoreEmptySearchPlaces
    packageProp
    searchPlaces
    stopDir
    transform

    Loaders example

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

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

    Version correlation

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

    Install

    npm i lilconfig

    DownloadsWeekly Downloads

    2,356,634

    Version

    2.0.3

    License

    MIT

    Unpacked Size

    14.6 kB

    Total Files

    4

    Last publish

    Collaborators

    • antonk52