@wzyjs/utils 0.2.13 → 0.2.14
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/dist/cjs/browser/element.d.ts +0 -1
- package/dist/cjs/browser/index.d.ts +1 -1
- package/dist/cjs/browser/index.js +3 -1
- package/dist/cjs/browser/initHttpClient.d.ts +4 -0
- package/dist/cjs/browser/initHttpClient.js +62 -0
- package/dist/cjs/browser/other.d.ts +0 -1
- package/dist/cjs/browser/style.d.ts +0 -1
- package/dist/cjs/browser.d.ts +0 -1
- package/dist/cjs/common/classs.d.ts +0 -1
- package/dist/cjs/common/dayjs.d.ts +13 -2
- package/dist/cjs/common/dayjs.js +1 -0
- package/dist/cjs/common/index.d.ts +0 -1
- package/dist/cjs/common/number.d.ts +1 -1
- package/dist/cjs/common/number.js +14 -0
- package/dist/cjs/common/object.d.ts +0 -1
- package/dist/cjs/common/other.d.ts +0 -1
- package/dist/cjs/common/string.d.ts +2 -5
- package/dist/cjs/common/string.js +5 -0
- package/dist/cjs/node/file/index.d.ts +1 -0
- package/dist/cjs/node/file/index.js +58 -0
- package/dist/cjs/node/index.d.ts +1 -1
- package/dist/cjs/node/index.js +3 -1
- package/dist/cjs/node/jsonFile/index.d.ts +3 -3
- package/dist/cjs/node/jsonFile/index.js +37 -13
- package/dist/cjs/node/mail/index.d.ts +0 -1
- package/dist/cjs/node.d.ts +0 -1
- package/dist/esm/browser/element.d.ts +0 -1
- package/dist/esm/browser/index.d.ts +1 -1
- package/dist/esm/browser/index.js +2 -1
- package/dist/esm/browser/initHttpClient.d.ts +4 -0
- package/dist/esm/{node/database/Collection.js → browser/initHttpClient.js} +51 -340
- package/dist/esm/browser/other.d.ts +0 -1
- package/dist/esm/browser/style.d.ts +0 -1
- package/dist/esm/browser.d.ts +0 -1
- package/dist/esm/common/classs.d.ts +0 -1
- package/dist/esm/common/dayjs.d.ts +13 -2
- package/dist/esm/common/dayjs.js +1 -0
- package/dist/esm/common/index.d.ts +0 -1
- package/dist/esm/common/number.d.ts +1 -1
- package/dist/esm/common/number.js +21 -0
- package/dist/esm/common/object.d.ts +0 -1
- package/dist/esm/common/other.d.ts +0 -1
- package/dist/esm/common/string.d.ts +2 -5
- package/dist/esm/common/string.js +9 -0
- package/dist/esm/node/file/index.d.ts +1 -0
- package/dist/esm/node/file/index.js +52 -0
- package/dist/esm/node/index.d.ts +1 -1
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/node/jsonFile/index.d.ts +3 -3
- package/dist/esm/node/jsonFile/index.js +79 -21
- package/dist/esm/node/mail/index.d.ts +0 -1
- package/dist/esm/node.d.ts +0 -1
- package/package.json +8 -8
- package/dist/cjs/browser/element.d.ts.map +0 -1
- package/dist/cjs/browser/index.d.ts.map +0 -1
- package/dist/cjs/browser/other.d.ts.map +0 -1
- package/dist/cjs/browser/style.d.ts.map +0 -1
- package/dist/cjs/browser.d.ts.map +0 -1
- package/dist/cjs/common/classs.d.ts.map +0 -1
- package/dist/cjs/common/dayjs.d.ts.map +0 -1
- package/dist/cjs/common/index.d.ts.map +0 -1
- package/dist/cjs/common/number.d.ts.map +0 -1
- package/dist/cjs/common/object.d.ts.map +0 -1
- package/dist/cjs/common/other.d.ts.map +0 -1
- package/dist/cjs/common/string.d.ts.map +0 -1
- package/dist/cjs/node/database/Collection.d.ts +0 -23
- package/dist/cjs/node/database/Collection.d.ts.map +0 -1
- package/dist/cjs/node/database/Collection.js +0 -219
- package/dist/cjs/node/database/Database.d.ts +0 -11
- package/dist/cjs/node/database/Database.d.ts.map +0 -1
- package/dist/cjs/node/database/Database.js +0 -47
- package/dist/cjs/node/database/index.d.ts +0 -3
- package/dist/cjs/node/database/index.d.ts.map +0 -1
- package/dist/cjs/node/database/index.js +0 -38
- package/dist/cjs/node/database/types.d.ts +0 -152
- package/dist/cjs/node/database/types.d.ts.map +0 -1
- package/dist/cjs/node/database/types.js +0 -51
- package/dist/cjs/node/database/utils.d.ts +0 -4
- package/dist/cjs/node/database/utils.d.ts.map +0 -1
- package/dist/cjs/node/database/utils.js +0 -53
- package/dist/cjs/node/index.d.ts.map +0 -1
- package/dist/cjs/node/jsonFile/index.d.ts.map +0 -1
- package/dist/cjs/node/mail/index.d.ts.map +0 -1
- package/dist/cjs/node.d.ts.map +0 -1
- package/dist/esm/browser/element.d.ts.map +0 -1
- package/dist/esm/browser/index.d.ts.map +0 -1
- package/dist/esm/browser/other.d.ts.map +0 -1
- package/dist/esm/browser/style.d.ts.map +0 -1
- package/dist/esm/browser.d.ts.map +0 -1
- package/dist/esm/common/classs.d.ts.map +0 -1
- package/dist/esm/common/dayjs.d.ts.map +0 -1
- package/dist/esm/common/index.d.ts.map +0 -1
- package/dist/esm/common/number.d.ts.map +0 -1
- package/dist/esm/common/object.d.ts.map +0 -1
- package/dist/esm/common/other.d.ts.map +0 -1
- package/dist/esm/common/string.d.ts.map +0 -1
- package/dist/esm/node/database/Collection.d.ts +0 -23
- package/dist/esm/node/database/Collection.d.ts.map +0 -1
- package/dist/esm/node/database/Database.d.ts +0 -11
- package/dist/esm/node/database/Database.d.ts.map +0 -1
- package/dist/esm/node/database/Database.js +0 -36
- package/dist/esm/node/database/index.d.ts +0 -3
- package/dist/esm/node/database/index.d.ts.map +0 -1
- package/dist/esm/node/database/index.js +0 -2
- package/dist/esm/node/database/types.d.ts +0 -152
- package/dist/esm/node/database/types.d.ts.map +0 -1
- package/dist/esm/node/database/types.js +0 -55
- package/dist/esm/node/database/utils.d.ts +0 -4
- package/dist/esm/node/database/utils.d.ts.map +0 -1
- package/dist/esm/node/database/utils.js +0 -29
- package/dist/esm/node/index.d.ts.map +0 -1
- package/dist/esm/node/jsonFile/index.d.ts.map +0 -1
- package/dist/esm/node/mail/index.d.ts.map +0 -1
- package/dist/esm/node.d.ts.map +0 -1
|
@@ -45,6 +45,7 @@ var import_animejs = __toESM(require("animejs"));
|
|
|
45
45
|
__reExport(browser_exports, require("./style"), module.exports);
|
|
46
46
|
__reExport(browser_exports, require("./element"), module.exports);
|
|
47
47
|
__reExport(browser_exports, require("./other"), module.exports);
|
|
48
|
+
__reExport(browser_exports, require("./initHttpClient"), module.exports);
|
|
48
49
|
var localforage = {
|
|
49
50
|
config: import_localforage.config,
|
|
50
51
|
setItem: import_localforage.setItem,
|
|
@@ -60,5 +61,6 @@ var localforage = {
|
|
|
60
61
|
md5,
|
|
61
62
|
...require("./style"),
|
|
62
63
|
...require("./element"),
|
|
63
|
-
...require("./other")
|
|
64
|
+
...require("./other"),
|
|
65
|
+
...require("./initHttpClient")
|
|
64
66
|
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/browser/initHttpClient.ts
|
|
30
|
+
var initHttpClient_exports = {};
|
|
31
|
+
__export(initHttpClient_exports, {
|
|
32
|
+
initHttpClient: () => initHttpClient
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(initHttpClient_exports);
|
|
35
|
+
var import_axios = __toESM(require("axios"));
|
|
36
|
+
var import_lodash = require("lodash");
|
|
37
|
+
var ErrorMiddleware = (onError) => {
|
|
38
|
+
return async (_, next) => {
|
|
39
|
+
try {
|
|
40
|
+
await next();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
onError(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var initHttpClient = (setupHttpClient, option) => {
|
|
47
|
+
setupHttpClient({
|
|
48
|
+
middleware: [ErrorMiddleware(option.onError)],
|
|
49
|
+
fetcher: async (req, options) => {
|
|
50
|
+
const response = await (0, import_axios.default)({
|
|
51
|
+
...(0, import_lodash.pick)(req, ["method", "url", "data", "query", "headers"]),
|
|
52
|
+
...(0, import_lodash.pick)(options, ["baseURL", "withCredentials"]),
|
|
53
|
+
timeout: options.timeout
|
|
54
|
+
});
|
|
55
|
+
return response.data;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
initHttpClient
|
|
62
|
+
});
|
|
@@ -8,4 +8,3 @@ export declare const hexToRgba: (hexColor: string, a?: number) => {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
|
|
10
10
|
export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
|
|
11
|
-
//# sourceMappingURL=style.d.ts.map
|
package/dist/cjs/browser.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
3
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
4
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
5
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
6
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
2
7
|
import 'dayjs/locale/zh-cn';
|
|
3
8
|
export declare enum Timezone {
|
|
4
9
|
AsiaShanghai = "Asia/Shanghai"
|
|
5
10
|
}
|
|
6
11
|
export { Dayjs } from 'dayjs';
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
declare const _default: typeof dayjs & {
|
|
13
|
+
isBetween: typeof isBetween;
|
|
14
|
+
isSameOrAfter: typeof isSameOrAfter;
|
|
15
|
+
isSameOrBefore: typeof isSameOrBefore;
|
|
16
|
+
tz: typeof timezone;
|
|
17
|
+
updateLocale: typeof updateLocale;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
package/dist/cjs/common/dayjs.js
CHANGED
|
@@ -54,6 +54,7 @@ import_dayjs.default.extend(import_timezone.default);
|
|
|
54
54
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
55
55
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
56
56
|
import_dayjs.default.locale("zh-cn");
|
|
57
|
+
import_dayjs.default.tz.setDefault("Asia/Shanghai");
|
|
57
58
|
import_dayjs.default.updateLocale("zh-cn", {
|
|
58
59
|
weekStart: 1
|
|
59
60
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getRandomNum: (min: number, max: number) => number;
|
|
2
2
|
export declare const limitDecimals: (v: string, num: number | undefined, isForce: boolean) => string;
|
|
3
3
|
export declare const getFileSize: (size: number) => string;
|
|
4
|
-
|
|
4
|
+
export declare const isValidNumber: (value: any) => boolean;
|
|
@@ -21,6 +21,7 @@ var number_exports = {};
|
|
|
21
21
|
__export(number_exports, {
|
|
22
22
|
getFileSize: () => getFileSize,
|
|
23
23
|
getRandomNum: () => getRandomNum,
|
|
24
|
+
isValidNumber: () => isValidNumber,
|
|
24
25
|
limitDecimals: () => limitDecimals
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(number_exports);
|
|
@@ -47,9 +48,22 @@ var getFileSize = (size) => {
|
|
|
47
48
|
}
|
|
48
49
|
return `${(s.toFixed(1) / 1).toString()}${d}`;
|
|
49
50
|
};
|
|
51
|
+
var isValidNumber = (value) => {
|
|
52
|
+
if (typeof value !== "number") {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (isNaN(value)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (value === Infinity || value === -Infinity) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
50
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
64
|
0 && (module.exports = {
|
|
52
65
|
getFileSize,
|
|
53
66
|
getRandomNum,
|
|
67
|
+
isValidNumber,
|
|
54
68
|
limitDecimals
|
|
55
69
|
});
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
export declare const getChineseByStr: (str: string) => string;
|
|
2
2
|
export declare const getStrLength: (value: string) => number;
|
|
3
3
|
export declare const replaceAll: (str: string, searchValue: string, replaceValue: string) => string;
|
|
4
|
-
export declare const replaceByRules: (str: string, rules: [
|
|
5
|
-
string,
|
|
6
|
-
string
|
|
7
|
-
][]) => string;
|
|
4
|
+
export declare const replaceByRules: (str: string, rules: [string, string][]) => string;
|
|
8
5
|
export declare const getType: (value: any) => string;
|
|
9
6
|
export declare const amount: (str: string) => string;
|
|
10
7
|
export declare const jsonParse: (value: string | object) => object;
|
|
@@ -17,4 +14,4 @@ export declare const getSliceStr: (str: string, before: string, after: string) =
|
|
|
17
14
|
export declare const getProxyUrl: (url: string) => string;
|
|
18
15
|
export declare const getLength: (value: string) => number;
|
|
19
16
|
export declare const getCookie: (name: string) => string | null;
|
|
20
|
-
|
|
17
|
+
export declare const generateAlphabetArray: (n: number) => string[];
|
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var string_exports = {};
|
|
21
21
|
__export(string_exports, {
|
|
22
22
|
amount: () => amount,
|
|
23
|
+
generateAlphabetArray: () => generateAlphabetArray,
|
|
23
24
|
getChinese: () => getChinese,
|
|
24
25
|
getChineseByStr: () => getChineseByStr,
|
|
25
26
|
getCookie: () => getCookie,
|
|
@@ -136,9 +137,13 @@ var getCookie = (name) => {
|
|
|
136
137
|
const arr = document.cookie.match(reg);
|
|
137
138
|
return arr ? unescape(arr[2]) : null;
|
|
138
139
|
};
|
|
140
|
+
var generateAlphabetArray = (n) => {
|
|
141
|
+
return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
|
|
142
|
+
};
|
|
139
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
144
|
0 && (module.exports = {
|
|
141
145
|
amount,
|
|
146
|
+
generateAlphabetArray,
|
|
142
147
|
getChinese,
|
|
143
148
|
getChineseByStr,
|
|
144
149
|
getCookie,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/node/file/index.ts
|
|
30
|
+
var file_exports = {};
|
|
31
|
+
__export(file_exports, {
|
|
32
|
+
replaceContentInFile: () => replaceContentInFile
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(file_exports);
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
37
|
+
try {
|
|
38
|
+
const data = await import_fs_extra.default.readFile(filePath, "utf8");
|
|
39
|
+
if (replacement && data.includes(replacement)) {
|
|
40
|
+
console.error(`已替换过:${filePath}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!data.includes(targetContent)) {
|
|
44
|
+
console.error(`不包含目标内容:${targetContent}`);
|
|
45
|
+
throw new Error(`不包含目标内容:${targetContent}`);
|
|
46
|
+
}
|
|
47
|
+
const updatedData = data.replace(new RegExp(targetContent, "g"), replacement);
|
|
48
|
+
await import_fs_extra.default.writeFile(filePath, updatedData, "utf8");
|
|
49
|
+
console.log(`成功替换文件中的内容!`);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error(`处理文件时发生错误:${err}`);
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
replaceContentInFile
|
|
58
|
+
});
|
package/dist/cjs/node/index.d.ts
CHANGED
package/dist/cjs/node/index.js
CHANGED
|
@@ -36,11 +36,13 @@ __export(node_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(node_exports);
|
|
37
37
|
__reExport(node_exports, require("./jsonFile"), module.exports);
|
|
38
38
|
__reExport(node_exports, require("./mail"), module.exports);
|
|
39
|
+
__reExport(node_exports, require("./file"), module.exports);
|
|
39
40
|
var import_nedb = __toESM(require("nedb"));
|
|
40
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
42
|
0 && (module.exports = {
|
|
42
43
|
DataStore,
|
|
43
44
|
DataStoreOptions,
|
|
44
45
|
...require("./jsonFile"),
|
|
45
|
-
...require("./mail")
|
|
46
|
+
...require("./mail"),
|
|
47
|
+
...require("./file")
|
|
46
48
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class JsonFile {
|
|
2
2
|
filePath: string;
|
|
3
3
|
constructor(filePath: string);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
private ensureFileExists;
|
|
5
|
+
get(key: string): Promise<any>;
|
|
6
|
+
set(key: string, value: any): Promise<void>;
|
|
6
7
|
}
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/node/jsonFile/index.ts
|
|
@@ -22,27 +32,41 @@ __export(jsonFile_exports, {
|
|
|
22
32
|
JsonFile: () => JsonFile
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(jsonFile_exports);
|
|
25
|
-
var
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
26
36
|
var path = require("path");
|
|
27
37
|
var JsonFile = class {
|
|
28
38
|
constructor(filePath) {
|
|
29
39
|
this.filePath = path.resolve(__dirname, filePath);
|
|
40
|
+
this.ensureFileExists();
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
ensureFileExists() {
|
|
43
|
+
try {
|
|
44
|
+
if (!import_fs_extra.default.existsSync(this.filePath)) {
|
|
45
|
+
import_fs_extra.default.writeFileSync(this.filePath, "{}", "utf-8");
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Error ensuring file exists:", error);
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
async get(key) {
|
|
52
|
+
try {
|
|
53
|
+
const data = await import_fs_extra.default.readFile(this.filePath, "utf-8");
|
|
54
|
+
const json = data ? JSON.parse(data) : {};
|
|
55
|
+
return json[key];
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("Error reading file:", error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async set(key, value) {
|
|
62
|
+
try {
|
|
63
|
+
const data = await import_fs_extra.default.readFile(this.filePath, "utf-8");
|
|
41
64
|
const json = data ? JSON.parse(data || "{}") : {};
|
|
42
65
|
json[key] = value;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
66
|
+
await import_fs_extra.default.writeFile(this.filePath, JSON.stringify(json, null, 2));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Error writing file:", error);
|
|
69
|
+
}
|
|
46
70
|
}
|
|
47
71
|
};
|
|
48
72
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/node.d.ts
CHANGED