source: frontend/node_modules/lilconfig/readme.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.0 KB
Line 
1# Lilconfig ⚙️
2[![npm version](https://badge.fury.io/js/lilconfig.svg)](https://badge.fury.io/js/lilconfig)
3[![install size](https://packagephobia.now.sh/badge?p=lilconfig)](https://packagephobia.now.sh/result?p=lilconfig)
4[![Coverage Status](https://coveralls.io/repos/github/antonk52/lilconfig/badge.svg)](https://coveralls.io/github/antonk52/lilconfig)
5
6A zero-dependency alternative to [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) with the same API.
7
8## Installation
9
10```sh
11npm install lilconfig
12```
13
14## Usage
15
16```js
17import {lilconfig, lilconfigSync} from 'lilconfig';
18
19// all keys are optional
20const options = {
21 stopDir: '/Users/you/some/dir',
22 searchPlaces: ['package.json', 'myapp.conf.js'],
23 ignoreEmptySearchPlaces: false
24}
25
26lilconfig(
27 'myapp',
28 options // optional
29).search() // Promise<LilconfigResult>
30
31lilconfigSync(
32 'myapp',
33 options // optional
34).load(pathToConfig) // LilconfigResult
35
36/**
37 * LilconfigResult
38 * {
39 * config: any; // your config
40 * filepath: string;
41 * }
42 */
43```
44
45## Difference to `cosmiconfig`
46Lilconfig does not intend to be 100% compatible with `cosmiconfig` but tries to mimic it where possible. The key differences are:
47- **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](#yaml-loader) below.
48- **no** cache
49
50### Options difference between the two.
51
52|cosmiconfig option | lilconfig |
53|------------------------|-----------|
54|cache | ❌ |
55|loaders | ✅ |
56|ignoreEmptySearchPlaces | ✅ |
57|packageProp | ✅ |
58|searchPlaces | ✅ |
59|stopDir | ✅ |
60|transform | ✅ |
61
62## Loaders examples
63
64### Yaml loader
65
66If you need the YAML support you can provide your own loader
67
68```js
69import {lilconfig} from 'lilconfig';
70import yaml from 'yaml';
71
72function loadYaml(filepath, content) {
73 return yaml.parse(content);
74}
75
76const options = {
77 loaders: {
78 '.yaml': loadYaml,
79 '.yml': loadYaml,
80 // loader for files with no extension
81 noExt: loadYaml
82 }
83};
84
85lilconfig('myapp', options)
86 .search()
87 .then(result => {
88 result // {config, filepath}
89 });
90```
91
92### ESM loader
93
94Lilconfig 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`.
95
96```js
97import {lilconfig} from 'lilconfig';
98
99const loadEsm = filepath => import(filepath);
100
101lilconfig('myapp', {
102 loaders: {
103 '.js': loadEsm,
104 '.mjs': loadEsm,
105 }
106})
107 .search()
108 .then(result => {
109 result // {config, filepath}
110
111 result.config.default // if config uses `export default`
112 });
113```
114
115## Version correlation
116
117- lilconig v1 → cosmiconfig v6
118- lilconig v2 → cosmiconfig v7
Note: See TracBrowser for help on using the repository browser.