fetch-json-cache 0.1.11 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/getSync.js +13 -0
- package/lib/index.js +7 -0
- package/lib/polyfills.js +1 -0
- package/package.json +7 -7
package/lib/getSync.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = function getCacheAsync(endpoint) {
|
|
5
|
+
var fullPath = path.join(this.cacheDirectory, this.options.hash(endpoint) + '.json');
|
|
6
|
+
try {
|
|
7
|
+
var contents = fs.readFileSync(fullPath, 'utf8');
|
|
8
|
+
var record = JSON.parse(contents.toString());
|
|
9
|
+
return record.body;
|
|
10
|
+
} catch (err) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require('./polyfills')
|
|
1
2
|
var rimraf = require('rimraf');
|
|
2
3
|
|
|
3
4
|
var get = require('./get');
|
|
5
|
+
var getSync = require('./getSync');
|
|
4
6
|
var hash = require('./hash');
|
|
5
7
|
var update = require('./update');
|
|
6
8
|
|
|
@@ -28,6 +30,11 @@ Cache.prototype.get = function (endpoint, options, callback) {
|
|
|
28
30
|
});
|
|
29
31
|
};
|
|
30
32
|
|
|
33
|
+
Cache.prototype.getSync = function (endpoint, options) {
|
|
34
|
+
// TODO: add async fetching
|
|
35
|
+
return getSync.call(this, endpoint);
|
|
36
|
+
};
|
|
37
|
+
|
|
31
38
|
Cache.prototype.clear = function (callback) {
|
|
32
39
|
var self = this;
|
|
33
40
|
if (typeof callback === 'function')
|
package/lib/polyfills.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('es6-promise/auto');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-json-cache",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Caches fetched json. Updates when etag changes and is uses cache regardless if endpoint unreachable. Uses write-file-atomic for safe updates",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"every",
|
|
@@ -22,24 +22,24 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"format": "prettier --write .",
|
|
24
24
|
"lint": "eslint .",
|
|
25
|
-
"prepublishOnly": "
|
|
25
|
+
"prepublishOnly": "npm run lint && depcheck",
|
|
26
26
|
"test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"
|
|
29
|
+
"es6-promise": "^4.2.8",
|
|
30
|
+
"get-remote": "^0.7.1",
|
|
30
31
|
"mkpath": "^1.0.0",
|
|
31
32
|
"rimraf": "^2.7.1",
|
|
32
33
|
"write-file-atomic": "^1.3.4"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@typescript-eslint/parser": "^5.30.
|
|
36
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
36
37
|
"depcheck": "^1.4.3",
|
|
37
|
-
"
|
|
38
|
-
"eslint": "^8.18.0",
|
|
38
|
+
"eslint": "^8.20.0",
|
|
39
39
|
"eslint-config-prettier": "^8.5.0",
|
|
40
40
|
"eslint-config-standard": "^17.0.0",
|
|
41
41
|
"eslint-plugin-import": "^2.26.0",
|
|
42
|
-
"eslint-plugin-n": "^15.2.
|
|
42
|
+
"eslint-plugin-n": "^15.2.4",
|
|
43
43
|
"eslint-plugin-promise": "^6.0.0",
|
|
44
44
|
"fs-access-sync-compat": "^1.0.1",
|
|
45
45
|
"mocha-compat": "^3.5.5",
|