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
|
9 | yarn add joycon
|
10 | ```
|
11 |
|
12 | ## Usage
|
13 |
|
14 | ```js
|
15 | const JoyCon = require('joycon')
|
16 |
|
17 | const joycon = new JoyCon(['package-lock.json', 'yarn.lock'])
|
18 |
|
19 | joycon.load()
|
20 | .then(result => {
|
21 | // result is {} when files do not exist
|
22 | // otherwise { path, data }
|
23 | })
|
24 | ```
|
25 |
|
26 | By 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
|
29 | const joycon = new JoyCon(['cargo.toml'])
|
30 |
|
31 | joycon.addLoader({
|
32 | test: /\.toml$/,
|
33 | load(filepath) {
|
34 | return require('toml').parse(filepath)
|
35 | }
|
36 | })
|
37 |
|
38 | joycon.load()
|
39 | ```
|
40 |
|
41 | ## DOC
|
42 |
|
43 | ## API
|
44 |
|
45 | ### constructor(files, [options])
|
46 |
|
47 | #### files
|
48 |
|
49 | Type: `string[]`
|
50 |
|
51 | The files to search.
|
52 |
|
53 | #### options
|
54 |
|
55 | ##### cwd
|
56 |
|
57 | Working directory to search files.
|
58 |
|
59 | ##### stopDir
|
60 |
|
61 | Directory where the search will stop. By default it's `path.parse(cwd).root`.
|
62 |
|
63 | ### resolve()
|
64 |
|
65 | Search files and resolve the path of the file we found.
|
66 |
|
67 | ### load()
|
68 |
|
69 | Search files and resolve `{ path, data }` of the file we found.
|
70 |
|
71 | ### addLoader(Loader)
|
72 |
|
73 | ```typescript
|
74 | interface Loader {
|
75 | test: RegExp
|
76 | load(filepath: string): any
|
77 | }
|
78 | ```
|
79 |
|
80 | ## Contributing
|
81 |
|
82 | 1. Fork it!
|
83 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
84 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
85 | 4. Push to the branch: `git push origin my-new-feature`
|
86 | 5. Submit a pull request :D
|
87 |
|
88 | ## Author
|
89 |
|
90 | **joycon** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
|
91 | Authored 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)
|