flat-cache 5.0.0 → 6.0.0
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/LICENSE +10 -13
- package/README.md +78 -67
- package/dist/index.cjs +360 -0
- package/dist/index.d.cts +226 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.js +321 -0
- package/package.json +42 -51
- package/src/cache.js +0 -215
- package/src/del.js +0 -31
- package/src/utils.js +0 -43
package/src/utils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs');
|
|
2
|
-
const path = require('node:path');
|
|
3
|
-
const flatted = require('flatted');
|
|
4
|
-
|
|
5
|
-
function tryParse(filePath, defaultValue) {
|
|
6
|
-
let result;
|
|
7
|
-
try {
|
|
8
|
-
result = readJSON(filePath);
|
|
9
|
-
} catch {
|
|
10
|
-
result = defaultValue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Read json file synchronously using flatted
|
|
18
|
-
*
|
|
19
|
-
* @param {String} filePath Json filepath
|
|
20
|
-
* @returns {*} parse result
|
|
21
|
-
*/
|
|
22
|
-
function readJSON(filePath) {
|
|
23
|
-
return flatted.parse(
|
|
24
|
-
fs.readFileSync(filePath, {
|
|
25
|
-
encoding: 'utf8',
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Write json file synchronously using circular-json
|
|
32
|
-
*
|
|
33
|
-
* @param {String} filePath Json filepath
|
|
34
|
-
* @param {*} data Object to serialize
|
|
35
|
-
*/
|
|
36
|
-
function writeJSON(filePath, data) {
|
|
37
|
-
fs.mkdirSync(path.dirname(filePath), {
|
|
38
|
-
recursive: true,
|
|
39
|
-
});
|
|
40
|
-
fs.writeFileSync(filePath, flatted.stringify(data));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = {tryParse, readJSON, writeJSON};
|