Socket
Socket
Sign inDemoInstall

load-json-file

Package Overview
Dependencies
8
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.2.0 to 5.3.0

91

index.d.ts

@@ -1,45 +0,58 @@

export type Reviver = (this: unknown, key: string, value: unknown) => unknown;
export type BeforeParse = (data: string) => string;
import {JsonValue} from 'type-fest';
export interface Options {
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: {
/**
* Applies a function to the JSON string before parsing.
*/
readonly beforeParse?: BeforeParse;
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}
})();
```
*/
<T = JsonValue>(filePath: string, options?: loadJsonFile.Options): Promise<T>;
/**
* 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;
}
Read and parse a JSON file.
/**
* Read and parse a JSON file.
*
* Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors.
*
* @example
*
* import loadJsonFile from 'load-json-file';
*
* (async () => {
* const json = await loadJsonFile('foo.json');
* //=> {foo: true}
* })();
*/
export default function loadJsonFile<T = unknown>(filePath: string, options?: Options): Promise<T>;
Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors.
/**
* Read and parse a JSON file.
*
* Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors.
*
* @example
*
* import * as loadJsonFile from 'load-json-file';
*
* const json = loadJsonFile.sync('foo.json');
* //=> {foo: true}
*/
export function sync<T = unknown>(filePath: string, options?: Options): T;
@example
```
import loadJsonFile = require('load-json-file');
const json = loadJsonFile.sync('foo.json');
//=> {foo: true}
```
*/
sync<T = JsonValue>(filePath: string, options?: loadJsonFile.Options): T;
// TODO: Remove this for the next major release
default: typeof loadJsonFile;
};
export = loadJsonFile;

@@ -21,3 +21,4 @@ 'use strict';

module.exports = loadJsonFile;
// TODO: Remove this for the next major release
module.exports.default = loadJsonFile;
module.exports.sync = (filePath, options) => parse(fs.readFileSync(filePath, 'utf8'), filePath, options);
{
"name": "load-json-file",
"version": "5.2.0",
"version": "5.3.0",
"description": "Read and parse a JSON file",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},

@@ -33,12 +33,13 @@ "files": [

"dependencies": {
"graceful-fs": "^4.1.2",
"graceful-fs": "^4.1.15",
"parse-json": "^4.0.0",
"pify": "^3.0.0",
"strip-bom": "^3.0.0"
"pify": "^4.0.1",
"strip-bom": "^3.0.0",
"type-fest": "^0.3.0"
},
"devDependencies": {
"ava": "*",
"tsd-check": "^0.2.1",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc