flat-cache 3.0.3 → 3.0.4
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/changelog.md +5 -0
- package/package.json +4 -2
- package/src/del.js +13 -0
- package/src/utils.js +44 -0
package/changelog.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
# flat-cache - Changelog
|
|
3
|
+
## v3.0.4
|
|
4
|
+
- **Refactoring**
|
|
5
|
+
- add files by name to the list of exported files - [89a2698]( https://github.com/royriojas/flat-cache/commit/89a2698 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:35:39
|
|
6
|
+
|
|
7
|
+
|
|
3
8
|
## v3.0.3
|
|
4
9
|
- **Bug Fixes**
|
|
5
10
|
- Fix wrong eslint command - [f268e42]( https://github.com/royriojas/flat-cache/commit/f268e42 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:15:04
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-cache",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "A stupidly simple key/value storage using files to persist some data",
|
|
5
5
|
"repository": "royriojas/flat-cache",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"main": "src/cache.js",
|
|
12
12
|
"files": [
|
|
13
|
-
"
|
|
13
|
+
"src/cache.js",
|
|
14
|
+
"src/del.js",
|
|
15
|
+
"src/utils.js"
|
|
14
16
|
],
|
|
15
17
|
"engines": {
|
|
16
18
|
"node": "^10.12.0 || >=12.0.0"
|
package/src/del.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var rimraf = require('rimraf').sync;
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
|
|
4
|
+
module.exports = function del(file) {
|
|
5
|
+
if (fs.existsSync(file)) {
|
|
6
|
+
//if rimraf doesn't throw then the file has been deleted or didn't exist
|
|
7
|
+
rimraf(file, {
|
|
8
|
+
glob: false,
|
|
9
|
+
});
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var flatted = require('flatted');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
tryParse: function (filePath, defaultValue) {
|
|
7
|
+
var result;
|
|
8
|
+
try {
|
|
9
|
+
result = this.readJSON(filePath);
|
|
10
|
+
} catch (ex) {
|
|
11
|
+
result = defaultValue;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Read json file synchronously using flatted
|
|
18
|
+
*
|
|
19
|
+
* @method readJSON
|
|
20
|
+
* @param {String} filePath Json filepath
|
|
21
|
+
* @returns {*} parse result
|
|
22
|
+
*/
|
|
23
|
+
readJSON: function (filePath) {
|
|
24
|
+
return flatted.parse(
|
|
25
|
+
fs.readFileSync(filePath, {
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Write json file synchronously using circular-json
|
|
33
|
+
*
|
|
34
|
+
* @method writeJSON
|
|
35
|
+
* @param {String} filePath Json filepath
|
|
36
|
+
* @param {*} data Object to serialize
|
|
37
|
+
*/
|
|
38
|
+
writeJSON: function (filePath, data) {
|
|
39
|
+
fs.mkdirSync(path.dirname(filePath), {
|
|
40
|
+
recursive: true,
|
|
41
|
+
});
|
|
42
|
+
fs.writeFileSync(filePath, flatted.stringify(data));
|
|
43
|
+
},
|
|
44
|
+
};
|