source: trip-planner-front/node_modules/lilconfig/readme.md@ 571e0df

Last change on this file since 571e0df was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • 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
70function loadYaml(filepath, content) {
71 return yaml.parse(content);
72}
73
74const options = {
75 loaders: {
76 '.yaml': loadYaml,
77 '.yml': loadYaml,
78 // loader for files with no extension
79 noExt: loadYaml
80 }
81};
82
83lilconfig('myapp', options)
84 .search()
85 .then(result => {
86 result // {config, filepath}
87 });
88```
89
90## Version correlation
91
92- lilconig v1 → cosmiconfig v6
93- lilconig v2 → cosmiconfig v7
Note: See TracBrowser for help on using the repository browser.