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 to 2.0.1

56

index.js
'use strict';
const {inspect} = require('util');
const {readFileSync} = require('graceful-fs');
const {readFileSync} = require('fs');

@@ -10,37 +10,37 @@ const CODE = 'ERR_INVALID_OPT_VALUE_ENCODING';

module.exports = function readJsonSync(...args) {
const argLen = args.length;
const argLen = args.length;
if (argLen === 2) {
const options = args[1];
const isObject = typeof options === 'object';
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;
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;
}
throw error;
}
if (options === '' || (isObject && options.encoding === '')) {
const error = new TypeError(`${ENCODING_ERROR.replace('<', 'non-empty <')}, but '' (empty string) was provided.`);
error.code = CODE;
if (options === '' || (isObject && options.encoding === '')) {
const error = new TypeError(`${ENCODING_ERROR.replace('<', 'non-empty <')}, but '' (empty string) was provided.`);
error.code = CODE;
throw error;
}
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 ${
argLen === 0 ? 'no' : argLen
} arguments.`);
}
if (isObject || options === undefined) {
args[1] = {encoding: 'utf8', ...options};
}
} else if (argLen === 1) {
args.push('utf8');
} else {
throw new RangeError(`Expected 1 or 2 arguments (path[, options]), but got ${
argLen === 0 ? 'no' : argLen
} arguments.`);
}
const str = readFileSync(...args);
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);
};
{
"name": "read-json-sync",
"version": "2.0.0",
"description": "Read and parse a JSON file synchronously",
"repository": "shinnn/read-json-sync",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"bench": "node benchmark/runner string-slice && node benchmark/runner string-replace && node benchmark/runner buffer-string-slice",
"pretest": "eslint --fix --format=codeframe benchmark index.js test",
"test": "istanbul cover test/test.js"
},
"license": "ISC",
"files": [
"index.js"
],
"keywords": [
"data",
"json",
"file",
"read",
"load",
"bom",
"parse",
"synchronous",
"synchronously",
"sync"
],
"dependencies": {
"graceful-fs": "^4.1.11"
},
"devDependencies": {
"@shinnn/eslint-config-node": "^4.0.2",
"chalk": "^2.3.0",
"eslint": "^4.11.0",
"istanbul": "^0.4.5",
"tape": "^4.8.0"
},
"eslintConfig": {
"extends": "@shinnn/node"
}
"name": "read-json-sync",
"version": "2.0.1",
"description": "Read and parse a JSON file synchronously",
"repository": "shinnn/read-json-sync",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"license": "ISC",
"scripts": {
"bench": "node benchmark/runner string-slice && node benchmark/runner string-replace && node benchmark/runner buffer-string-slice",
"pretest": "eslint .",
"test": "nyc node test/test.js"
},
"files": [
"index.js"
],
"keywords": [
"data",
"json",
"file",
"read",
"load",
"bom",
"parse",
"synchronous",
"synchronously",
"sync"
],
"devDependencies": {
"@shinnn/eslint-config": "^6.8.7",
"chalk": "^2.4.1",
"eslint": "^5.10.0",
"nyc": "^13.1.0",
"nyc-config-common": "^1.0.1",
"tape": "^4.9.1"
},
"eslintConfig": {
"extends": "@shinnn"
},
"nyc": {
"extends": "nyc-config-common"
}
}
# read-json-sync
[![npm version](https://img.shields.io/npm/v/read-json-sync.svg)](https://www.npmjs.com/package/read-json-sync)
[![Build Status](https://travis-ci.org/shinnn/read-json-sync.svg?branch=master)](https://travis-ci.org/shinnn/read-json-sync)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-json-sync.svg)](https://david-dm.org/shinnn/read-json-sync)
[![Build Status](https://travis-ci.com/shinnn/read-json-sync.svg?branch=master)](https://travis-ci.com/shinnn/read-json-sync)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-json-sync.svg)](https://coveralls.io/github/shinnn/read-json-sync)
A [Node.js](https://nodejs.org/) module to read and parse a [JSON](http://www.json.org/) file synchronously
A [Node.js](https://nodejs.org/) module to read and parse a [JSON](https://json.org/) file synchronously

@@ -19,3 +19,3 @@ ```javascript

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

@@ -38,3 +38,3 @@ ```

It automatically ignores the leading [byte order mark](https://www.unicode.org/faq/utf_bom.html).
It automatically ignores the leading [byte order mark](https://unicode.org/faq/utf_bom.html).

@@ -51,2 +51,2 @@ ```javascript

[ISC License](./LICENSE) © 2017 Shinnosuke Watanabe
[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe

Sorry, the diff of this file is not supported yet

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