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

json-config-reader

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-config-reader - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

postinstall.js

5

package.json
{
"name": "json-config-reader",
"version": "1.0.0",
"version": "1.0.1",
"description": "Reads and caches JSON configurations.",
"main": "index.js",
"scripts": {
"test": "node index.js"
"test": "node index.js",
"postinstall": "node postinstall.js"
},

@@ -9,0 +10,0 @@ "repository": {

@@ -5,1 +5,56 @@ # json-config-reader

json-config-reader reads configurations, parses them, and caches them in case they need to be referenced again.
## Usage
`Reader` consists of a simple API.
#### `Reader.read(file, [call])`
With `.read`, you can read asynchronously or synchronously depending on if you provide a callback.
```javascript
var jc = require("json-config-reader");
// Read synchronously
var data = jc.read("some.json");
console.log(data);
// Read asynchronously
jc.read("some.json", function(data){
console.log("data");
});
```
Note that both refer to the same cache bank.
#### `Reader.purgeCache([file])`
`.purgeCache` sets cache values to undefined in the `Reader.__cache` bank. This is helpful if you update a JSON file mid-script and need to read it again to get the new value.
```javascript
// Lets say some.json is { "test": 1 }
var data1 = jc.read("some.json");
fs.writeFileSync("some.json", JSON.stringify({"new": "values!"}));
var data2 = jc.read("some.json");
// Both data1 and data2 are the same, because the second `.read` fetched from the cache.
jc.purgeCache("some.json");
var data3 = jc.read("some.json");
// Now we have:
// data1 and data2 = { "test": 1 }
// data3 = { "new": "values!" }
```
#### `Reader.__cache`
`.__cache` is used internally. It's an object that routes file paths to the parsed data (if successfully parsed).
```javascript
var data1 = jc.read("/home/jamen/some.json");
var data2 = jc.__cache["/home/jamen/some.json"];
// Both data1 and data2 are the same.
```
*Note!* You should never have to refer to the `Reader.__cache` object yourself. `Reader.read` implements cache lookups, and falls back by reading and parsing the file (then adding that data to the bank).
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