pax_global_header00006660000000000000000000000064135115716020014513gustar00rootroot0000000000000052 comment=85fcfc5225fb3ac11d2e93c9e2bd4a9d43c52b69 load-json-file-6.2.0/000077500000000000000000000000001351157160200143235ustar00rootroot00000000000000load-json-file-6.2.0/.editorconfig000066400000000000000000000002571351157160200170040ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 load-json-file-6.2.0/.gitattributes000066400000000000000000000000231351157160200172110ustar00rootroot00000000000000* text=auto eol=lf load-json-file-6.2.0/.github/000077500000000000000000000000001351157160200156635ustar00rootroot00000000000000load-json-file-6.2.0/.github/funding.yml000066400000000000000000000001701351157160200200360ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/load-json-file custom: https://sindresorhus.com/donate load-json-file-6.2.0/.github/security.md000066400000000000000000000002631351157160200200550ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. load-json-file-6.2.0/.gitignore000066400000000000000000000000271351157160200163120ustar00rootroot00000000000000node_modules yarn.lock load-json-file-6.2.0/.npmrc000066400000000000000000000000231351157160200154360ustar00rootroot00000000000000package-lock=false load-json-file-6.2.0/.travis.yml000066400000000000000000000000651351157160200164350ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' load-json-file-6.2.0/index.d.ts000066400000000000000000000025121351157160200162240ustar00rootroot00000000000000import {JsonValue} from 'type-fest'; declare namespace loadJsonFile { type Reviver = (this: unknown, key: string, value: any) => unknown; type BeforeParse = (data: string) => string; interface Options { /** Applies a function to the JSON string before parsing. */ readonly beforeParse?: BeforeParse; /** Prescribes how the value originally produced by parsing is transformed, before being returned. See the [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more. */ readonly reviver?: Reviver; } } declare const loadJsonFile: { /** Read and parse a JSON file. Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. @example ``` import loadJsonFile = require('load-json-file'); (async () => { const json = await loadJsonFile('foo.json'); //=> {foo: true} })(); ``` */ (filePath: string, options?: loadJsonFile.Options): Promise; /** Read and parse a JSON file. Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. @example ``` import loadJsonFile = require('load-json-file'); const json = loadJsonFile.sync('foo.json'); //=> {foo: true} ``` */ sync(filePath: string, options?: loadJsonFile.Options): T; }; export = loadJsonFile; load-json-file-6.2.0/index.js000066400000000000000000000012421351157160200157670ustar00rootroot00000000000000'use strict'; const path = require('path'); const {promisify} = require('util'); const fs = require('graceful-fs'); const stripBom = require('strip-bom'); const parseJson = require('parse-json'); const parse = (data, filePath, options = {}) => { data = stripBom(data); if (typeof options.beforeParse === 'function') { data = options.beforeParse(data); } return parseJson(data, options.reviver, path.relative(process.cwd(), filePath)); }; module.exports = async (filePath, options) => parse(await promisify(fs.readFile)(filePath, 'utf8'), filePath, options); module.exports.sync = (filePath, options) => parse(fs.readFileSync(filePath, 'utf8'), filePath, options); load-json-file-6.2.0/index.test-d.ts000066400000000000000000000007041351157160200172020ustar00rootroot00000000000000import {expectType} from 'tsd'; import {JsonValue} from 'type-fest'; import loadJsonFile = require('.'); import {Reviver, BeforeParse} from '.'; expectType(() => 1); expectType((a: string) => a.length); expectType((a: string, b: string) => a.length - b.length); expectType(data => data); expectType>(loadJsonFile('unicorn.json')); expectType(loadJsonFile.sync('unicorn.json')); load-json-file-6.2.0/license000066400000000000000000000021251351157160200156700ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. load-json-file-6.2.0/package.json000066400000000000000000000012701351157160200166110ustar00rootroot00000000000000{ "name": "load-json-file", "version": "6.2.0", "description": "Read and parse a JSON file", "license": "MIT", "repository": "sindresorhus/load-json-file", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "read", "json", "parse", "file", "fs", "graceful", "load" ], "dependencies": { "graceful-fs": "^4.1.15", "parse-json": "^5.0.0", "strip-bom": "^4.0.0", "type-fest": "^0.6.0" }, "devDependencies": { "ava": "^2.1.0", "tsd": "^0.7.3", "xo": "^0.24.0" } } load-json-file-6.2.0/readme.md000066400000000000000000000033411351157160200161030ustar00rootroot00000000000000# load-json-file [![Build Status](https://travis-ci.org/sindresorhus/load-json-file.svg?branch=master)](https://travis-ci.org/sindresorhus/load-json-file) > Read and parse a JSON file [Strips UTF-8 BOM](https://github.com/sindresorhus/strip-bom), uses [`graceful-fs`](https://github.com/isaacs/node-graceful-fs), and throws more [helpful JSON errors](https://github.com/sindresorhus/parse-json). ## Install ``` $ npm install load-json-file ``` ## Usage ```js const loadJsonFile = require('load-json-file'); (async () => { console.log(await loadJsonFile('foo.json')); //=> {foo: true} })(); ``` ## API ### loadJsonFile(filePath, options?) Returns a `Promise` with the parsed JSON. ### loadJsonFile.sync(filepath, options?) Returns the parsed JSON. #### options Type: `object` ##### beforeParse Type: `Function` Applies a function to the JSON string before parsing. ##### reviver Type: `Function` Prescribes how the value originally produced by parsing is transformed, before being returned. See the [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more. ## Related - [write-json-file](https://github.com/sindresorhus/write-json-file) - Stringify and write JSON to a file atomically ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
load-json-file-6.2.0/test.js000066400000000000000000000013011351157160200156330ustar00rootroot00000000000000import path from 'path'; import test from 'ava'; import loadJsonFile from '.'; const fixture = path.join(__dirname, 'package.json'); test('async', async t => { const data = await loadJsonFile(fixture); t.is(data.name, 'load-json-file'); }); test('sync', t => { t.is(loadJsonFile.sync(fixture).name, 'load-json-file'); }); test('beforeParse option', async t => { const data = await loadJsonFile(fixture, { beforeParse: string => string.replace('"name": "load-json-file"', '"name": "foo"') }); t.is(data.name, 'foo'); }); test('reviver option', async t => { const data = await loadJsonFile(fixture, { reviver: (key, value) => key === 'name' ? 'foo' : value }); t.is(data.name, 'foo'); });