1.0.0 • Published 7 years ago

if-file-read v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

if-file-read

NPM version Build Status XO code style

Return the content of the first file in array which exists

Install

npm install --save if-file-read

Usage

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

NameDescriptionTypeDefault
filesArray of file pathsarrayarg required
options.prependstring to prepend to each filestring''

Returns

Type: string

Throws Error "No files found" if none of the files exist

License

MIT © Dawson Botsford