• Stars
    star
    155
  • Rank 240,864 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zero-dependency nodejs config seeker.

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 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

More Repositories

1

why-npm-i-so-long

Checks project's dependencies size AKA why npm install so long
JavaScript
222
star
2

bad-practices.nvim

A plugin to help give up bad practices in vim.
Lua
87
star
3

coc-cssmodules

css modules autocompletion and go to definition coc.nvim plugin
TypeScript
70
star
4

markdowny.nvim

Markdown like keymaps for toggling text formatting
Lua
70
star
5

cssmodules-language-server

autocompletion and go-to-defintion for cssmodules
TypeScript
55
star
6

dot-files

A config collection
Lua
35
star
7

swaggerlint

Keep your API consistent
TypeScript
20
star
8

rainbow-actions

Redux actions + TypeScript = <3
TypeScript
17
star
9

lake.nvim

A simplified ocean color scheme with treesitter support
Lua
13
star
10

webdevandstuff

TypeScript
12
star
11

vim-plugin-templater

Templates for your next vim plugins
Vim Script
8
star
12

coc-protobuf

go to definition for protobuf messages
TypeScript
8
star
13

vimconf-2021

Lua
7
star
14

synd

Opinionated rsync wrapper that respects gitignore files
TypeScript
6
star
15

gitignore-grabber.nvim

Grab .gitignore for your project in Neovim
Lua
6
star
16

dirvish-fs.vim

fs menu for vim-dirvish
Vim Script
5
star
17

vim-slides.rs

Generate slides to present in vim. I have no idea what I am doing in rust
Rust
5
star
18

amake.nvim

Asynchronous make for neovim
Lua
5
star
19

npm_scripts.nvim

Run npm scripts from your favourite editor
Lua
5
star
20

browser-animation-talk

HTML
4
star
21

vim-tabber

vim tab navigation plugin
Vim Script
3
star
22

vim-lightline-ocean

lightline ocean theme
Vim Script
2
star
23

pico-cli

Typescript first / zero dependencies CLI framework
TypeScript
2
star
24

WorkspaceAppBar.spoon

Lua
2
star
25

make-me-a-content

Content generation made tiny and easy
TypeScript
2
star
26

eslint-plugin-latin-variable-names

JavaScript
1
star
27

wp-preset

1
star
28

turbo-caching-issue

TypeScript
1
star
29

swaggerlint-playground

TypeScript
1
star
30

denty.nvim

Indentation characters and auto set tabstop, shiftwidth, and expandtab for Neovim
Lua
1
star