# if-file-read

> Return the content of the first file in array

Latest version **1.0.0** (published 2017-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install if-file-read
pnpm add if-file-read
yarn add if-file-read
bun add if-file-read
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-01-20 |
| First published | 2017-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dawson Botsford |
| Maintainers | dawsonbotsford |
| Keywords | documented, file, read, tested, licensed, dawson |

## Links

- npm: https://www.npmjs.com/package/if-file-read
- Repository: https://github.com/dawsonbotsford/if-file-read
- Homepage: https://github.com/dawsonbotsford/if-file-read#readme
- Issues: https://github.com/dawsonbotsford/if-file-read/issues
- npm.io page: https://npm.io/package/if-file-read

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-01-20

## README

# if-file-read
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![XO code style][xo-image]][xo-url]

> Return the content of the first file in array which exists

## Install

```
npm install --save if-file-read
```

## Usage

```js
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](http://dawsonbotsford.com)

[npm-image]: https://badge.fury.io/js/if-file-read.svg
[npm-url]: https://npmjs.org/package/if-file-read
[travis-image]: https://travis-ci.org/dawsonbotsford/if-file-read.svg?branch=master
[travis-url]: https://travis-ci.org/dawsonbotsford/if-file-read
[xo-image]: https://img.shields.io/badge/code_style-XO-5ed9c7.svg
[xo-url]: https://github.com/sindresorhus/xo

---
_Source: https://npm.io/package/if-file-read · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
