source: trip-planner-front/node_modules/lilconfig/readme.md@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 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](#loaders-example) 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 example
63
64If you need the YAML support you can provide your own loader
65
66```js
67import {lilconig} from 'lilconfig';
68import yaml from 'yaml';
69
70const options = {
71 loaders: {
72 '.yaml': (filepath, content) => {
73 return yaml.parse(content);
74 },
75 // loader for files with no extension
76 noExt: (filepath, content) => {
77 return yaml.parse(content);
78 }
79 }
80};
81
82lilconfig('myapp', options)
83 .search()
84 .then(result => {
85 result // {config, filepath}
86 });
87```
88
89## Version correlation
90
91- lilconig v1 → cosmiconfig v6
92- lilconig v2 → cosmiconfig v7
Note: See TracBrowser for help on using the repository browser.