package/package.json000644 000765 000024 0000001421 12621705714013020 0ustar00000000 000000 { "name": "load-json-file", "version": "1.1.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": ">=0.10.0" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "json", "read", "parse", "file", "fs", "graceful", "load" ], "dependencies": { "graceful-fs": "^4.1.2", "parse-json": "^2.2.0", "pify": "^2.0.0", "pinkie-promise": "^2.0.0", "strip-bom": "^2.0.0" }, "devDependencies": { "ava": "*", "xo": "*" }, "xo": { "ignores": [ "test.js" ] } } package/index.js000644 000765 000024 0000001035 12571514366012205 0ustar00000000 000000 'use strict'; var path = require('path'); var fs = require('graceful-fs'); var stripBom = require('strip-bom'); var parseJson = require('parse-json'); var Promise = require('pinkie-promise'); var pify = require('pify'); function parse(x, fp) { return parseJson(stripBom(x), path.relative(process.cwd(), fp)); } module.exports = function (fp) { return pify(fs.readFile, Promise)(fp, 'utf8').then(function (data) { return parse(data, fp); }); }; module.exports.sync = function (fp) { return parse(fs.readFileSync(fp, 'utf8'), fp); }; package/license000644 000765 000024 0000002137 12320273017012074 0ustar00000000 000000 The MIT License (MIT) 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. package/readme.md000644 000765 000024 0000001667 12617651057012332 0ustar00000000 000000 # 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 --save load-json-file ``` ## Usage ```js const loadJsonFile = require('load-json-file'); loadJsonFile('foo.json').then(json => { console.log(json); //=> {foo: true} }); ``` ## API ### loadJsonFile(filepath) Returns a promise that resolves to the parsed JSON. ### loadJsonFile.sync(filepath) Returns the parsed JSON. ## Related - [write-json-file](https://github.com/sindresorhus/write-json-file) - Stringify and write JSON to a file atomically ## License MIT © [Sindre Sorhus](http://sindresorhus.com)