UNPKG

2.46 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()
18
19joycon.load(['package-lock.json', 'yarn.lock'])
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()
30
31joycon.addLoader({
32 test: /\.toml$/,
33 load(filepath) {
34 return require('toml').parse(filepath)
35 }
36})
37
38joycon.load(['cargo.toml'])
39```
40
41## API
42
43### constructor([options])
44
45#### options
46
47##### files
48
49Type: `string[]`
50
51The files to search.
52
53##### cwd
54
55The directory to search files.
56
57### resolve([files], [cwd], [stopDir])
58
59`files` defaults to `options.files`.
60
61`cwd` defaults to `options.cwd`.
62
63`stopDir` defaults to `path.parse(cwd).root`.
64
65Search files and resolve the path of the file we found.
66
67### load(...args)
68
69The signature is the same as [resolve](#resolvefiles-cwd-stopdir).
70
71Search files and resolve `{ path, data }` of the file we found.
72
73### addLoader(Loader)
74
75```typescript
76interface Loader {
77 test: RegExp
78 load(filepath: string): any
79}
80```
81
82### clearCache()
83
84Each JoyCon instance uses its own cache.
85
86## Contributing
87
881. Fork it!
892. Create your feature branch: `git checkout -b my-new-feature`
903. Commit your changes: `git commit -am 'Add some feature'`
914. Push to the branch: `git push origin my-new-feature`
925. Submit a pull request :D
93
94## Author
95
96**joycon** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
97Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/joycon/contributors)).
98
99> [github.com/egoist](https://github.com/egoist) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)