Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-json-sync

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-json-sync - npm Package Compare versions

Comparing version 2.0.0-2 to 2.0.0-3

34

index.js
'use strict';
const {inspect} = require('util');
const {readFileSync} = require('graceful-fs');
const CODE = 'ERR_INVALID_OPT_VALUE_ENCODING';
const ENCODING_ERROR = 'read-json-sync expected the encoding option to be a <string> (defaulting to \'utf8\' if nothing is specified) so as to convert file contents from <Buffer> to <string> before parsing it as JSON';
module.exports = function readJsonSync(...args) {
const argLen = args.length;
if (argLen !== 1 && argLen !== 2) {
if (argLen === 2) {
const options = args[1];
const isObject = typeof options === 'object';
if (options === null || (isObject && options.encoding !== undefined && typeof options.encoding !== 'string')) {
const encoding = options === null ? null : options.encoding;
const error = new TypeError(`${ENCODING_ERROR}, but a non-string value ${inspect(encoding)} was provided.`);
error.code = CODE;
throw error;
}
if (options === '' || (isObject && options.encoding === '')) {
const error = new TypeError(`${ENCODING_ERROR.replace('<', 'non-empty <')}, but '' (empty string) was provided.`);
error.code = CODE;
throw error;
}
if (isObject || options === undefined) {
args[1] = Object.assign({encoding: 'utf8'}, options);
}
} else if (argLen === 1) {
args.push('utf8');
} else {
throw new RangeError(`Expected 1 or 2 arguments (path[, options]), but got ${

@@ -14,5 +42,5 @@ argLen === 0 ? 'no' : argLen

const str = readFileSync(...args).toString();
const str = readFileSync(...args);
return JSON.parse(str.charCodeAt(0) === 65279 ? /* 0xFEFF */ str.slice(1) : str);
return JSON.parse(str.charCodeAt(0) === 65279 /* 0xFEFF */ ? str.slice(1) : str);
};

4

package.json
{
"name": "read-json-sync",
"version": "2.0.0-2",
"version": "2.0.0-3",
"description": "Read and parse a JSON file synchronously",

@@ -33,3 +33,3 @@ "repository": "shinnn/read-json-sync",

"chalk": "^2.3.0",
"eslint": "^4.10.0",
"eslint": "^4.11.0",
"istanbul": "^0.4.5",

@@ -36,0 +36,0 @@ "tape": "^4.8.0"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc