json-config-reader
Advanced tools
Comparing version 1.0.2 to 1.1.0
18
index.js
@@ -5,3 +5,3 @@ (function(fs, path){ | ||
Reader.__cache = {}; | ||
global.__jsoncache = global.__jsoncache || {}; | ||
@@ -14,4 +14,4 @@ Reader.read = function(file, call){ | ||
if (typeof call !== "undefined") { | ||
if (typeof Reader.__cache[file] !== "undefined") { | ||
call(error, Reader.__cache[file]); | ||
if (typeof global.__jsoncache[file] !== "undefined") { | ||
call(error, global.__jsoncache[file]); | ||
return config; | ||
@@ -23,3 +23,3 @@ }; | ||
config = JSON.parse(data); | ||
Reader.__cache[file] = config; | ||
global.__jsoncache[file] = config; | ||
} catch (err) { | ||
@@ -37,6 +37,6 @@ error = err; | ||
} else { | ||
if (typeof Reader.__cache[file] !== "undefined") return Reader.__cache[file]; | ||
if (typeof global.__jsoncache[file] !== "undefined") return global.__jsoncache[file]; | ||
try { | ||
config = JSON.parse(fs.readFileSync(file)); | ||
Reader.__cache[file] = config; | ||
global.__jsoncache[file] = config; | ||
return config; | ||
@@ -52,6 +52,6 @@ } catch (err) { | ||
if (typeof file !== "undefined") { | ||
Reader.__cache[path.resolve(file)] = undefined; | ||
global.__jsoncache[path.resolve(file)] = undefined; | ||
} else { | ||
for (var i in Reader.__cache) { | ||
Reader.__cache[i] = undefined; | ||
for (var i in global.__jsoncache) { | ||
global.__jsoncache[i] = undefined; | ||
} | ||
@@ -58,0 +58,0 @@ } |
{ | ||
"name": "json-config-reader", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Reads and caches JSON configurations.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node index.js", | ||
"postversion": "node postinstall.js" | ||
"test": "node index.js" | ||
}, | ||
@@ -10,0 +9,0 @@ "repository": { |
@@ -37,3 +37,3 @@ # json-config-reader | ||
// Both data1 and data2 are the same, because the second `.read` fetched from the cache. | ||
// data1 and data2 are the same. The second `.read` fetched from the cache. | ||
@@ -49,9 +49,9 @@ jc.purgeCache("some.json"); | ||
#### `Reader.__cache` | ||
#### `global.__jsoncache` | ||
`.__cache` is used internally. It's an object that routes file paths to the parsed data (if successfully parsed). | ||
`global.__jsoncache` 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"]; | ||
var data2 = global.__jsoncache["/home/jamen/some.json"]; | ||
@@ -61,2 +61,2 @@ // 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). | ||
*Note!* You should never have to refer to the `global.__jsoncache` object yourself. `Reader.read` implements cache lookups, and falls back by reading and parsing the file (then adding that data to the bank). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4948
4
50