read-json-sync
Advanced tools
Comparing version
12
index.js
@@ -5,4 +5,12 @@ 'use strict'; | ||
module.exports = function readJsonSync(filePath, options) { | ||
return JSON.parse(readFileSync(filePath, options).toString().replace(/^\ufeff/g, '')); | ||
module.exports = function readJsonSync(...args) { | ||
const argLen = args.length; | ||
if (argLen !== 1 && argLen !== 2) { | ||
throw new RangeError(`Expected 1 or 2 arguments (path[, options]), but got ${ | ||
argLen === 0 ? 'no' : argLen | ||
} arguments.`); | ||
} | ||
return JSON.parse(readFileSync(...args).toString().replace(/^\ufeff/g, '')); | ||
}; |
{ | ||
"name": "read-json-sync", | ||
"version": "2.0.0-0", | ||
"version": "2.0.0-1", | ||
"description": "Read and parse a JSON file synchronously", | ||
@@ -9,4 +9,3 @@ "repository": "shinnn/read-json-sync", | ||
"pretest": "eslint --fix --format=codeframe index.js test/test.js", | ||
"test": "node --throw-deprecation --track-heap-objects test/test.js | tap-spec", | ||
"coverage": "istanbul cover test/test.js" | ||
"test": "istanbul cover test/test.js" | ||
}, | ||
@@ -33,5 +32,4 @@ "license": "CC0-1.0", | ||
"@shinnn/eslint-config-node": "^4.0.2", | ||
"eslint": "^4.4.1", | ||
"eslint": "^4.6.1", | ||
"istanbul": "^0.4.5", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.8.0" | ||
@@ -38,0 +36,0 @@ }, |
# read-json-sync | ||
[](https://www.npmjs.com/package/read-json-sync) | ||
[](https://www.npmjs.com/package/read-json-sync) | ||
[](https://travis-ci.org/shinnn/read-json-sync) | ||
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/read-json-sync) | ||
[](https://david-dm.org/shinnn/read-json-sync) | ||
@@ -32,7 +31,7 @@ | ||
### readJsonSync(*filePath* [, *options*]) | ||
### readJsonSync(*path* [, *options*]) | ||
*filePath*: `String` (path to a JSON file) | ||
*options*: `Object` ([`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback) options) | ||
Return: `Object` (parsed [JSON](https://tools.ietf.org/html/rfc7159) data) | ||
*path*: `string` [`Buffer`](https://nodejs.org/api/buffer.html#buffer_class_buffer) [`URL`](https://nodejs.org/api/url.html#url_class_url) (JSON filename) or `integer` (file descriptor) | ||
*options*: `Object` ([`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options) | ||
Return: `any` (parsed [JSON](https://tools.ietf.org/html/rfc7159) data) | ||
@@ -39,0 +38,0 @@ ## License |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
2764
1.92%4
-20%11
120%0
-100%40
-2.44%