read from a list of files and get only the first one that returns

config, file system, rc, dotfiles
npm install oscuro@2.0.0



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.


Oscuro exports a function.

const promise = oscuro([
    { path: "./.file5", type: "json" }, 
    { path: "./file6.json", key: "path.to.my.prop" }, 
], "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.


Apache 2.0