1.0.0 • Published 9 years ago
if-file-read v1.0.0
if-file-read
Return the content of the first file in array which exists
Install
npm install --save if-file-readUsage
const ifFileRead = require('if-file-read');
// Where c.txt is the only file:
ifFileRead(['a.txt', 'b.txt', 'c.txt']);
//=> 'contents of c.txt file'
// Where src/c.txt is the only file
ifFileRead(['a.txt', 'b.txt', 'c.txt'], {prepend: 'src'});
//=> 'contents of src/c.txt file'API
ifFileRead(files, options)
Returns a readFileSync for the first valid file
Arguments
| Name | Description | Type | Default |
|---|---|---|---|
| files | Array of file paths | array | arg required |
| options.prepend | string to prepend to each file | string | '' |
Returns
Type: string
Throws Error "No files found" if none of the files exist
License
MIT © Dawson Botsford
1.0.0
9 years ago