Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/jaid/read-file-json
- Owner: Jaid
- License: mit
- Created: 2019-12-19T20:58:09.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-07-27T09:34:35.000Z (over 2 years ago)
- Last Synced: 2024-12-17T03:39:16.786Z (21 days ago)
- Topics: file, filesystem, fs, json, json-parser, json5, json5-parser, lib, library, load-file, loader, promise, read-file, util, utility
- Language: JavaScript
- Homepage: https://github.com/Jaid/read-file-json
- Size: 1.62 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.txt
Awesome Lists containing this project
README
# 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.**
## Installation
```bash
npm install --save read-file-json@^1.1.0
``````bash
yarn add read-file-json@^1.1.0
```
(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)