GithubHelp home page GithubHelp logo

akiyamka / lilconfig Goto Github PK

View Code? Open in Web Editor NEW

This project forked from antonk52/lilconfig

0.0 1.0 0.0 807 KB

Zero-dependency nodejs config seeker.

TypeScript 97.44% JavaScript 2.47% CoffeeScript 0.08%

lilconfig's Introduction

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

lilconfig's People

Contributors

antonk52 avatar dependabot[bot] avatar jeetiss avatar jounqin avatar lttb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.