https://github.com/btholt/oscuro
Read from a list of files and return only the first one
https://github.com/btholt/oscuro
Last synced: 2 months ago
JSON representation
Read from a list of files and return only the first one
- Host: GitHub
- URL: https://github.com/btholt/oscuro
- Owner: btholt
- License: apache-2.0
- Created: 2017-10-12T05:04:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-14T17:28:12.000Z (over 8 years ago)
- Last Synced: 2025-12-23T03:46:22.625Z (6 months ago)
- Language: JavaScript
- Size: 40 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Oscuro
Provide oscuro with a list of files and you'll only get the first one back that exists. Useful for looking for config files in different places. Similar to cosmiconfig (great package!) but less batteries included.
## API
Oscuro exports a function.
```es6
const promise = oscuro([
'./file1.json',
'file2.yaml',
'file3.js',
{ path: "./.file5", type: "json" },
{ path: "./file6.json", key: "path.to.my.prop" },
'file4.html'
], "default thing to give if none are found");
```
`paths`: array of strings and objects, required. First param is a list of paths to try to read, in order. Every path will be read and it will wait until all resolve before returning your answer. Items in the array can be strings or objects.
Objects must have a `path` prop and may have a `type` prop and/or a `key` prop. Type will tell it how to interept the data. `json` and `yaml` are parsed and returned as objects. `js` is required and returned. Anything else is returned as a string. The type is inferred from the path if no type is provided. `key` prop will use lodash's `get` method to return only part of the object that you specify.
`defaultResponse`: mixed, optional. what to be passed back if none of the paths resolve.
## License
Apache 2.0