Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jaid/read-file-json

Reads JSON and JSON5 from a file. Returns null if file does not exist (or is a directory) instead of throwing an Error.
https://github.com/jaid/read-file-json

file filesystem fs json json-parser json5 json5-parser lib library load-file loader promise read-file util utility

Last synced: 12 days ago
JSON representation

Reads JSON and JSON5 from a file. Returns null if file does not exist (or is a directory) instead of throwing an Error.

Awesome Lists containing this project

README

        

# read-file-json

License Sponsor read-file-json
Build status Commits since v1.1.0 Last commit Issues
Latest version on npm Dependents Downloads

**Reads JSON and JSON5 from a file. Returns null if file does not exist (or is a directory) instead of throwing an Error.**

## Installation

read-file-json on npm

```bash
npm install --save read-file-json@^1.1.0
```

read-file-json on Yarn

```bash
yarn add read-file-json@^1.1.0
```

@jaid/read-file-json on GitHub Packages
(if [configured properly](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages))

```bash
npm install --save @jaid/read-file-json@^1.1.0
```

## Example

```javascript
import readFileJson from "read-file-json"

readFileJson("./exists.json5").then(result => {

})

readFileJson("./doesNotExist.json5").then(result2 => {

})
```

Variable `result` will be:

```javascript
["a", "b", "c"]
```
Variable `result2` will be:

```javascript
null
```

## Development

Setting up:
```bash
git clone [email protected]:jaid/read-file-json.git
cd read-file-json
npm install
```
Testing:
```bash
npm run test:dev
```
Testing in production environment:
```bash
npm run test
```

## License
[MIT License](https://raw.githubusercontent.com/jaid/read-file-json/master/license.txt)
Copyright © 2021, Jaid \ (https://github.com/jaid)