@xfe-repo/mini-utils 0.0.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/README.md +3 -0
- package/dist/appJSBridge.d.ts +30 -0
- package/dist/appJSBridge.js +184 -0
- package/dist/env.d.ts +15 -0
- package/dist/env.js +96 -0
- package/dist/storage.d.ts +9 -0
- package/dist/storage.h5.d.ts +9 -0
- package/dist/storage.h5.js +55 -0
- package/dist/storage.js +79 -0
- package/dist/storage.weapp.d.ts +9 -0
- package/dist/storage.weapp.js +54 -0
- package/dist/tool.d.ts +2 -0
- package/dist/tool.js +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare function appLogin(params: {
|
|
2
|
+
redirect: string;
|
|
3
|
+
}): Promise<{
|
|
4
|
+
userToken: string;
|
|
5
|
+
}>;
|
|
6
|
+
declare function appChooseImage(params: {
|
|
7
|
+
count?: number;
|
|
8
|
+
sourceType?: 'album' | 'camera';
|
|
9
|
+
}): Promise<{
|
|
10
|
+
list: string[];
|
|
11
|
+
}>;
|
|
12
|
+
declare function appWechatShareImg(params: {
|
|
13
|
+
shareImg: string;
|
|
14
|
+
imageWidth: string;
|
|
15
|
+
imageHeight: string;
|
|
16
|
+
wmsOrderNo: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
declare function appSaveImage(params: {
|
|
19
|
+
imageList?: string[];
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
declare function appH5RouterChange(params: {
|
|
22
|
+
path?: string;
|
|
23
|
+
}): Promise<Number>;
|
|
24
|
+
declare function appScanCode(params: {
|
|
25
|
+
type: 'general' | 'business';
|
|
26
|
+
}): Promise<{
|
|
27
|
+
code: string;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
export { appChooseImage, appH5RouterChange, appLogin, appSaveImage, appScanCode, appWechatShareImg };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/appJSBridge.ts
|
|
51
|
+
var appJSBridge_exports = {};
|
|
52
|
+
__export(appJSBridge_exports, {
|
|
53
|
+
appChooseImage: () => appChooseImage,
|
|
54
|
+
appH5RouterChange: () => appH5RouterChange,
|
|
55
|
+
appLogin: () => appLogin,
|
|
56
|
+
appSaveImage: () => appSaveImage,
|
|
57
|
+
appScanCode: () => appScanCode,
|
|
58
|
+
appWechatShareImg: () => appWechatShareImg
|
|
59
|
+
});
|
|
60
|
+
module.exports = __toCommonJS(appJSBridge_exports);
|
|
61
|
+
|
|
62
|
+
// src/env.ts
|
|
63
|
+
var import_taro2 = __toESM(require("@tarojs/taro"));
|
|
64
|
+
|
|
65
|
+
// src/storage.h5.ts
|
|
66
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
67
|
+
function getLocalData(name) {
|
|
68
|
+
return import_js_cookie.default.get(name) || "";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/storage.weapp.ts
|
|
72
|
+
var import_taro = __toESM(require("@tarojs/taro"));
|
|
73
|
+
function getLocalData2(name) {
|
|
74
|
+
return import_taro.default.getStorageSync(name);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/storage.ts
|
|
78
|
+
var platform = process.env.TARO_ENV || "weapp";
|
|
79
|
+
var isWeapp = platform === "weapp";
|
|
80
|
+
var getLocalData3 = isWeapp ? getLocalData2 : getLocalData;
|
|
81
|
+
|
|
82
|
+
// src/env.ts
|
|
83
|
+
var ENV = import_taro2.default.getEnv().toLocaleLowerCase();
|
|
84
|
+
var platform2 = process.env.TARO_ENV || "weapp";
|
|
85
|
+
var isH5 = platform2 === "h5";
|
|
86
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
87
|
+
var _a;
|
|
88
|
+
var isSaasAndroidApp = isH5 && /SAAS_ANDROID/i.test((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent);
|
|
89
|
+
var _a2;
|
|
90
|
+
var isSaasIOSApp = isH5 && /SAAS_IOS/i.test((_a2 = window == null ? void 0 : window.navigator) == null ? void 0 : _a2.userAgent);
|
|
91
|
+
var isSaasAPP = isSaasAndroidApp || isSaasIOSApp;
|
|
92
|
+
var isApp = isSaasAPP;
|
|
93
|
+
var _a3, _b, _c;
|
|
94
|
+
var appVersion = isApp ? ((_c = (_b = (_a3 = window == null ? void 0 : window.navigator) == null ? void 0 : _a3.userAgent) == null ? void 0 : _b.match(/version:(\d+\.\d+\.\d+);/)) == null ? void 0 : _c[1]) || "" : "";
|
|
95
|
+
var apiEnv = process.env.API_ENV || getLocalData3("apiEnv");
|
|
96
|
+
|
|
97
|
+
// src/appJSBridge.ts
|
|
98
|
+
var import_compare_versions = require("compare-versions");
|
|
99
|
+
var AppJSBridge = class {
|
|
100
|
+
constructor() {
|
|
101
|
+
this.callbackDict = {};
|
|
102
|
+
// 触发app调用
|
|
103
|
+
this.sendMessage = (methodKey, params = {}) => {
|
|
104
|
+
if (!isApp) throw new Error("\u975Eapp\u73AF\u5883");
|
|
105
|
+
if (isSaasIOSApp) {
|
|
106
|
+
window.flutter_inappwebview.callHandler(methodKey, params);
|
|
107
|
+
} else if (isSaasAndroidApp) {
|
|
108
|
+
window.jsObj[methodKey](JSON.stringify(params));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// 监听app调用
|
|
112
|
+
this.listen = (methodKey, callback) => {
|
|
113
|
+
if (!isApp) return Promise.reject("\u975Eapp\u73AF\u5883");
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
this.callbackDict[methodKey] = (result) => {
|
|
116
|
+
const jsonResult = JSON.parse(result || "{}");
|
|
117
|
+
if (!jsonResult.code || jsonResult.code !== 200) throw new Error(jsonResult.msg);
|
|
118
|
+
if (!jsonResult.data) throw new Error("\u8FD4\u56DE\u6570\u636E\u4E3A\u7A7A");
|
|
119
|
+
resolve(jsonResult.data);
|
|
120
|
+
callback == null ? void 0 : callback(jsonResult.data);
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
// 触发app调用并监听
|
|
125
|
+
this.call = (methodKey, params, minimumVersion) => {
|
|
126
|
+
if (minimumVersion && (0, import_compare_versions.compare)(appVersion, minimumVersion, "<")) throw new Error("\u8BF7\u5347\u7EA7\u81F3\u6700\u65B0\u7248\u672CAPP\u540E\u4F7F\u7528");
|
|
127
|
+
const callback = this.listen(methodKey);
|
|
128
|
+
this.sendMessage(methodKey, params);
|
|
129
|
+
return callback;
|
|
130
|
+
};
|
|
131
|
+
// 触发app调用并监听 通用版本 此方法在APP中优化了版本控制逻辑 当方法不存在时会返回404
|
|
132
|
+
this.callCommon = (methodKey, params, minimumVersion) => {
|
|
133
|
+
if (minimumVersion && (0, import_compare_versions.compare)(appVersion, minimumVersion, "<")) throw new Error("\u8BF7\u5347\u7EA7\u81F3\u6700\u65B0\u7248\u672CAPP\u540E\u4F7F\u7528");
|
|
134
|
+
const callback = this.listen(methodKey);
|
|
135
|
+
this.sendMessage("JSBridge" /* JS_BRIDGE */, { method: methodKey, params });
|
|
136
|
+
return callback;
|
|
137
|
+
};
|
|
138
|
+
if (!isApp) return;
|
|
139
|
+
window.ejsBridgeCallback = (type, jsonString) => {
|
|
140
|
+
var _a4, _b2;
|
|
141
|
+
return (_b2 = (_a4 = this.callbackDict)[type]) == null ? void 0 : _b2.call(_a4, jsonString);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var appJSBridge = new AppJSBridge();
|
|
146
|
+
function appLogin(params) {
|
|
147
|
+
return __async(this, null, function* () {
|
|
148
|
+
return appJSBridge.call("login" /* LOGIN */, params);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function appChooseImage(params) {
|
|
152
|
+
return __async(this, null, function* () {
|
|
153
|
+
return appJSBridge.call("chooseImage" /* CHOOSE_IMAGE */, params);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function appWechatShareImg(params) {
|
|
157
|
+
return __async(this, null, function* () {
|
|
158
|
+
return appJSBridge.call("wechatShareImg" /* WECHAT_SHARE_IMG */, params);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function appSaveImage(params) {
|
|
162
|
+
return __async(this, null, function* () {
|
|
163
|
+
return appJSBridge.call("saveImage" /* SAVE_IMAGE */, params);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function appH5RouterChange(params) {
|
|
167
|
+
return __async(this, null, function* () {
|
|
168
|
+
return appJSBridge.call("h5RouterChange" /* H5_ROUTER_CHANGE */, params);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function appScanCode(params) {
|
|
172
|
+
return __async(this, null, function* () {
|
|
173
|
+
return appJSBridge.callCommon("scanCode" /* SCAN_CODE */, params, "3.21.0");
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
appChooseImage,
|
|
179
|
+
appH5RouterChange,
|
|
180
|
+
appLogin,
|
|
181
|
+
appSaveImage,
|
|
182
|
+
appScanCode,
|
|
183
|
+
appWechatShareImg
|
|
184
|
+
});
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ApiEnv = 'dev' | 'stage' | 'beta' | 'prod' | `test${number | ''}`;
|
|
2
|
+
declare const ENV: string;
|
|
3
|
+
declare const version = "0.0.1";
|
|
4
|
+
declare const platform: string;
|
|
5
|
+
declare const isH5: boolean;
|
|
6
|
+
declare const isWeapp: boolean;
|
|
7
|
+
declare const isProduction: boolean;
|
|
8
|
+
declare const isSaasAndroidApp: boolean;
|
|
9
|
+
declare const isSaasIOSApp: boolean;
|
|
10
|
+
declare const isSaasAPP: boolean;
|
|
11
|
+
declare const isApp: boolean;
|
|
12
|
+
declare const appVersion: string;
|
|
13
|
+
declare const apiEnv: ApiEnv;
|
|
14
|
+
|
|
15
|
+
export { type ApiEnv, ENV, apiEnv, appVersion, isApp, isH5, isProduction, isSaasAPP, isSaasAndroidApp, isSaasIOSApp, isWeapp, platform, version };
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/env.ts
|
|
31
|
+
var env_exports = {};
|
|
32
|
+
__export(env_exports, {
|
|
33
|
+
ENV: () => ENV,
|
|
34
|
+
apiEnv: () => apiEnv,
|
|
35
|
+
appVersion: () => appVersion,
|
|
36
|
+
isApp: () => isApp,
|
|
37
|
+
isH5: () => isH5,
|
|
38
|
+
isProduction: () => isProduction,
|
|
39
|
+
isSaasAPP: () => isSaasAPP,
|
|
40
|
+
isSaasAndroidApp: () => isSaasAndroidApp,
|
|
41
|
+
isSaasIOSApp: () => isSaasIOSApp,
|
|
42
|
+
isWeapp: () => isWeapp2,
|
|
43
|
+
platform: () => platform2,
|
|
44
|
+
version: () => version
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(env_exports);
|
|
47
|
+
var import_taro2 = __toESM(require("@tarojs/taro"));
|
|
48
|
+
|
|
49
|
+
// src/storage.h5.ts
|
|
50
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
51
|
+
function getLocalData(name) {
|
|
52
|
+
return import_js_cookie.default.get(name) || "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/storage.weapp.ts
|
|
56
|
+
var import_taro = __toESM(require("@tarojs/taro"));
|
|
57
|
+
function getLocalData2(name) {
|
|
58
|
+
return import_taro.default.getStorageSync(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/storage.ts
|
|
62
|
+
var platform = process.env.TARO_ENV || "weapp";
|
|
63
|
+
var isWeapp = platform === "weapp";
|
|
64
|
+
var getLocalData3 = isWeapp ? getLocalData2 : getLocalData;
|
|
65
|
+
|
|
66
|
+
// src/env.ts
|
|
67
|
+
var ENV = import_taro2.default.getEnv().toLocaleLowerCase();
|
|
68
|
+
var version = "0.0.1";
|
|
69
|
+
var platform2 = process.env.TARO_ENV || "weapp";
|
|
70
|
+
var isH5 = platform2 === "h5";
|
|
71
|
+
var isWeapp2 = platform2 === "weapp";
|
|
72
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
73
|
+
var _a;
|
|
74
|
+
var isSaasAndroidApp = isH5 && /SAAS_ANDROID/i.test((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent);
|
|
75
|
+
var _a2;
|
|
76
|
+
var isSaasIOSApp = isH5 && /SAAS_IOS/i.test((_a2 = window == null ? void 0 : window.navigator) == null ? void 0 : _a2.userAgent);
|
|
77
|
+
var isSaasAPP = isSaasAndroidApp || isSaasIOSApp;
|
|
78
|
+
var isApp = isSaasAPP;
|
|
79
|
+
var _a3, _b, _c;
|
|
80
|
+
var appVersion = isApp ? ((_c = (_b = (_a3 = window == null ? void 0 : window.navigator) == null ? void 0 : _a3.userAgent) == null ? void 0 : _b.match(/version:(\d+\.\d+\.\d+);/)) == null ? void 0 : _c[1]) || "" : "";
|
|
81
|
+
var apiEnv = process.env.API_ENV || getLocalData3("apiEnv");
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
ENV,
|
|
85
|
+
apiEnv,
|
|
86
|
+
appVersion,
|
|
87
|
+
isApp,
|
|
88
|
+
isH5,
|
|
89
|
+
isProduction,
|
|
90
|
+
isSaasAPP,
|
|
91
|
+
isSaasAndroidApp,
|
|
92
|
+
isSaasIOSApp,
|
|
93
|
+
isWeapp,
|
|
94
|
+
platform,
|
|
95
|
+
version
|
|
96
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { setLocalData as setLocalData$1 } from './storage.h5.js';
|
|
2
|
+
import { getLocalData as getLocalData$1, removeLocalData as removeLocalData$1 } from './storage.weapp.js';
|
|
3
|
+
|
|
4
|
+
declare const platform: string;
|
|
5
|
+
declare const getLocalData: typeof getLocalData$1;
|
|
6
|
+
declare const setLocalData: typeof setLocalData$1;
|
|
7
|
+
declare const removeLocalData: typeof removeLocalData$1;
|
|
8
|
+
|
|
9
|
+
export { getLocalData, platform, removeLocalData, setLocalData };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function getLocalData(name: string): string;
|
|
2
|
+
declare function setLocalData(params: {
|
|
3
|
+
key: string;
|
|
4
|
+
data: any;
|
|
5
|
+
expireDays?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function removeLocalData(key: string): void;
|
|
8
|
+
|
|
9
|
+
export { getLocalData, removeLocalData, setLocalData };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/storage.h5.ts
|
|
31
|
+
var storage_h5_exports = {};
|
|
32
|
+
__export(storage_h5_exports, {
|
|
33
|
+
getLocalData: () => getLocalData,
|
|
34
|
+
removeLocalData: () => removeLocalData,
|
|
35
|
+
setLocalData: () => setLocalData
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(storage_h5_exports);
|
|
38
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
39
|
+
function getLocalData(name) {
|
|
40
|
+
return import_js_cookie.default.get(name) || "";
|
|
41
|
+
}
|
|
42
|
+
function setLocalData(params) {
|
|
43
|
+
const { key, data, expireDays = 365 } = params;
|
|
44
|
+
const expires = new Date(Date.now() + expireDays * 24 * 60 * 60 * 1e3);
|
|
45
|
+
import_js_cookie.default.set(key, data, { expires });
|
|
46
|
+
}
|
|
47
|
+
function removeLocalData(key) {
|
|
48
|
+
setLocalData({ key, data: "", expireDays: -1 });
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getLocalData,
|
|
53
|
+
removeLocalData,
|
|
54
|
+
setLocalData
|
|
55
|
+
});
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/storage.ts
|
|
31
|
+
var storage_exports = {};
|
|
32
|
+
__export(storage_exports, {
|
|
33
|
+
getLocalData: () => getLocalData3,
|
|
34
|
+
platform: () => platform,
|
|
35
|
+
removeLocalData: () => removeLocalData3,
|
|
36
|
+
setLocalData: () => setLocalData3
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(storage_exports);
|
|
39
|
+
|
|
40
|
+
// src/storage.h5.ts
|
|
41
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
42
|
+
function getLocalData(name) {
|
|
43
|
+
return import_js_cookie.default.get(name) || "";
|
|
44
|
+
}
|
|
45
|
+
function setLocalData(params) {
|
|
46
|
+
const { key, data, expireDays = 365 } = params;
|
|
47
|
+
const expires = new Date(Date.now() + expireDays * 24 * 60 * 60 * 1e3);
|
|
48
|
+
import_js_cookie.default.set(key, data, { expires });
|
|
49
|
+
}
|
|
50
|
+
function removeLocalData(key) {
|
|
51
|
+
setLocalData({ key, data: "", expireDays: -1 });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/storage.weapp.ts
|
|
55
|
+
var import_taro = __toESM(require("@tarojs/taro"));
|
|
56
|
+
function getLocalData2(name) {
|
|
57
|
+
return import_taro.default.getStorageSync(name);
|
|
58
|
+
}
|
|
59
|
+
function setLocalData2(params) {
|
|
60
|
+
const { key, data } = params;
|
|
61
|
+
import_taro.default.setStorageSync(key, data);
|
|
62
|
+
}
|
|
63
|
+
function removeLocalData2(key) {
|
|
64
|
+
import_taro.default.removeStorageSync(key);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/storage.ts
|
|
68
|
+
var platform = process.env.TARO_ENV || "weapp";
|
|
69
|
+
var isWeapp = platform === "weapp";
|
|
70
|
+
var getLocalData3 = isWeapp ? getLocalData2 : getLocalData;
|
|
71
|
+
var setLocalData3 = isWeapp ? setLocalData2 : setLocalData;
|
|
72
|
+
var removeLocalData3 = isWeapp ? removeLocalData2 : removeLocalData;
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
getLocalData,
|
|
76
|
+
platform,
|
|
77
|
+
removeLocalData,
|
|
78
|
+
setLocalData
|
|
79
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function getLocalData(name: string): any;
|
|
2
|
+
declare function setLocalData(params: {
|
|
3
|
+
key: string;
|
|
4
|
+
data: any;
|
|
5
|
+
expireDays?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function removeLocalData(key: string): void;
|
|
8
|
+
|
|
9
|
+
export { getLocalData, removeLocalData, setLocalData };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/storage.weapp.ts
|
|
31
|
+
var storage_weapp_exports = {};
|
|
32
|
+
__export(storage_weapp_exports, {
|
|
33
|
+
getLocalData: () => getLocalData,
|
|
34
|
+
removeLocalData: () => removeLocalData,
|
|
35
|
+
setLocalData: () => setLocalData
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(storage_weapp_exports);
|
|
38
|
+
var import_taro = __toESM(require("@tarojs/taro"));
|
|
39
|
+
function getLocalData(name) {
|
|
40
|
+
return import_taro.default.getStorageSync(name);
|
|
41
|
+
}
|
|
42
|
+
function setLocalData(params) {
|
|
43
|
+
const { key, data } = params;
|
|
44
|
+
import_taro.default.setStorageSync(key, data);
|
|
45
|
+
}
|
|
46
|
+
function removeLocalData(key) {
|
|
47
|
+
import_taro.default.removeStorageSync(key);
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
getLocalData,
|
|
52
|
+
removeLocalData,
|
|
53
|
+
setLocalData
|
|
54
|
+
});
|
package/dist/tool.d.ts
ADDED
package/dist/tool.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xfe-repo/mini-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"module": "dist/*.js",
|
|
6
|
+
"types": "types/*.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./*": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/*.d.ts",
|
|
11
|
+
"default": "./dist/*.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/*.d.ts",
|
|
15
|
+
"default": "./dist/*.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"js-cookie": "^3.0.5",
|
|
24
|
+
"@tarojs/taro": "4.0.8",
|
|
25
|
+
"compare-versions": "^6.1.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/js-cookie": "^3.0.6",
|
|
29
|
+
"@types/node": "^20.10.3",
|
|
30
|
+
"@xfe-repo/typescript-config": "0.0.6",
|
|
31
|
+
"@xfe-repo/eslint-config": "0.0.5"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"dev": "tsup --watch",
|
|
36
|
+
"lint": "eslint \"src/**/*.ts*\"",
|
|
37
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
38
|
+
}
|
|
39
|
+
}
|