UNPKG

2.3 kBMarkdownView Raw
1
2# joycon
3
4[![NPM version](https://img.shields.io/npm/v/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![NPM downloads](https://img.shields.io/npm/dm/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![CircleCI](https://circleci.com/gh/egoist/joycon/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/joycon/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe)
5
6## Install
7
8```bash
9yarn add joycon
10```
11
12## Usage
13
14```js
15const JoyCon = require('joycon')
16
17const joycon = new JoyCon(['package-lock.json', 'yarn.lock'])
18
19joycon.load()
20.then(result => {
21 // result is {} when files do not exist
22 // otherwise { path, data }
23})
24```
25
26By default only `.js` and `.json` file are parsed, otherwise raw data will be returned, so you can add custom loader to parse them:
27
28```js
29const joycon = new JoyCon(['cargo.toml'])
30
31joycon.addLoader({
32 test: /\.toml$/,
33 load(filepath) {
34 return require('toml').parse(filepath)
35 }
36})
37
38joycon.load()
39```
40
41## DOC
42
43## API
44
45### constructor(files, [options])
46
47#### files
48
49Type: `string[]`
50
51The files to search.
52
53#### options
54
55##### cwd
56
57Working directory to search files.
58
59##### stopDir
60
61Directory where the search will stop. By default it's `path.parse(cwd).root`.
62
63### resolve()
64
65Search files and resolve the path of the file we found.
66
67### load()
68
69Search files and resolve `{ path, data }` of the file we found.
70
71### addLoader(Loader)
72
73```typescript
74interface Loader {
75 test: RegExp
76 load(filepath: string): any
77}
78```
79
80## Contributing
81
821. Fork it!
832. Create your feature branch: `git checkout -b my-new-feature`
843. Commit your changes: `git commit -am 'Add some feature'`
854. Push to the branch: `git push origin my-new-feature`
865. Submit a pull request :D
87
88## Author
89
90**joycon** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
91Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/joycon/contributors)).
92
93> [github.com/egoist](https://github.com/egoist) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)