@nsnanocat/util 0.0.0-preview-7be35e5 → 0.0.0-preview-a256400
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/lib/index.js +17 -1
- package/dist/polyfill/Storage.cjs +28 -18
- package/dist/polyfill/Storage.js +24 -34
- package/package.json +1 -1
package/dist/lib/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__app_js__ from "./app.js";
|
|
2
2
|
export * from "./done.js";
|
|
3
3
|
export * from "./notification.js";
|
|
4
4
|
export * from "./time.js";
|
|
5
5
|
export * from "./wait.js";
|
|
6
|
+
var __webpack_modules__ = {
|
|
7
|
+
"./app.js": function(module) {
|
|
8
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__app_js__;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var __webpack_module_cache__ = {};
|
|
12
|
+
function __webpack_require__(moduleId) {
|
|
13
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
14
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
15
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
16
|
+
exports: {}
|
|
17
|
+
};
|
|
18
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
19
|
+
return module.exports;
|
|
20
|
+
}
|
|
21
|
+
__webpack_require__("./app.js");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
4
|
-
module.exports =
|
|
3
|
+
fs: function(module) {
|
|
4
|
+
module.exports = import("fs");
|
|
5
5
|
},
|
|
6
|
-
|
|
7
|
-
module.exports =
|
|
6
|
+
path: function(module) {
|
|
7
|
+
module.exports = import("path");
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
var __webpack_module_cache__ = {};
|
|
@@ -69,7 +69,7 @@ function _define_property(obj, key, value) {
|
|
|
69
69
|
else obj[key] = value;
|
|
70
70
|
return obj;
|
|
71
71
|
}
|
|
72
|
-
var _loadData = /*#__PURE__*/ new WeakSet(), _writeData = /*#__PURE__*/ new WeakSet();
|
|
72
|
+
var _getNodeModule = /*#__PURE__*/ new WeakSet(), _loadData = /*#__PURE__*/ new WeakSet(), _writeData = /*#__PURE__*/ new WeakSet();
|
|
73
73
|
class StorageClass {
|
|
74
74
|
getItem(keyName, defaultValue = null) {
|
|
75
75
|
let keyValue = defaultValue;
|
|
@@ -168,32 +168,42 @@ class StorageClass {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
constructor(){
|
|
171
|
+
_class_private_method_init(this, _getNodeModule);
|
|
171
172
|
_class_private_method_init(this, _loadData);
|
|
172
173
|
_class_private_method_init(this, _writeData);
|
|
173
174
|
_define_property(this, "data", null);
|
|
174
175
|
_define_property(this, "dataFile", 'box.dat');
|
|
175
176
|
_define_property(this, "nameRegex", /^@(?<key>[^.]+)(?:\.(?<path>.*))?$/);
|
|
176
|
-
if ('Node.js' === app_cjs_namespaceObject.$app) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.data = _class_private_method_get(this, _loadData, loadData).call(this, this.dataFile, fs, path);
|
|
180
|
-
}
|
|
177
|
+
if ('Node.js' === app_cjs_namespaceObject.$app) _class_private_method_get(this, _loadData, loadData).call(this, this.dataFile).then((res)=>{
|
|
178
|
+
this.data = res;
|
|
179
|
+
});
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
|
-
function
|
|
182
|
+
async function getNodeModule() {
|
|
183
|
+
if ('Node.js' === app_cjs_namespaceObject.$app) {
|
|
184
|
+
const fs = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "fs"));
|
|
185
|
+
const path = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "path"));
|
|
186
|
+
return {
|
|
187
|
+
fs,
|
|
188
|
+
path
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
async function loadData(dataFile) {
|
|
194
|
+
const { fs, path } = await _class_private_method_get(this, _getNodeModule, getNodeModule).call(this) ?? {};
|
|
195
|
+
if (!fs || !path) return {};
|
|
184
196
|
const curDirDataFilePath = path.resolve(dataFile);
|
|
185
197
|
const rootDirDataFilePath = path.resolve(process.cwd(), dataFile);
|
|
186
198
|
if (fs.existsSync(curDirDataFilePath)) return JSON.parse(fs.readFileSync(curDirDataFilePath, 'utf-8')) || {};
|
|
187
199
|
if (fs.existsSync(rootDirDataFilePath)) return JSON.parse(fs.readFileSync(rootDirDataFilePath, 'utf-8')) || {};
|
|
188
200
|
return {};
|
|
189
201
|
}
|
|
190
|
-
function writeData(dataFile) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
fs.writeFileSync(dataFilePath, JSON.stringify(this.data), 'utf-8');
|
|
196
|
-
}
|
|
202
|
+
async function writeData(dataFile) {
|
|
203
|
+
const { fs, path } = await _class_private_method_get(this, _getNodeModule, getNodeModule).call(this) ?? {};
|
|
204
|
+
if (!fs || !path) return;
|
|
205
|
+
const dataFilePath = path.resolve(dataFile);
|
|
206
|
+
fs.writeFileSync(dataFilePath, JSON.stringify(this.data), 'utf-8');
|
|
197
207
|
}
|
|
198
208
|
const Storage = new StorageClass();
|
|
199
209
|
var __webpack_export_target__ = exports;
|
package/dist/polyfill/Storage.js
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
3
1
|
import * as __WEBPACK_EXTERNAL_MODULE__Lodash_js__ from "./Lodash.js";
|
|
4
2
|
import * as __WEBPACK_EXTERNAL_MODULE__lib_app_js__ from "../lib/app.js";
|
|
5
|
-
var __webpack_modules__ = {
|
|
6
|
-
"node:fs": function(module) {
|
|
7
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs__;
|
|
8
|
-
},
|
|
9
|
-
"node:path": function(module) {
|
|
10
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path__;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var __webpack_module_cache__ = {};
|
|
14
|
-
function __webpack_require__(moduleId) {
|
|
15
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
16
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
17
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
18
|
-
exports: {}
|
|
19
|
-
};
|
|
20
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
21
|
-
return module.exports;
|
|
22
|
-
}
|
|
23
3
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
24
4
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
25
5
|
}
|
|
@@ -41,7 +21,7 @@ function _define_property(obj, key, value) {
|
|
|
41
21
|
else obj[key] = value;
|
|
42
22
|
return obj;
|
|
43
23
|
}
|
|
44
|
-
var _loadData = /*#__PURE__*/ new WeakSet(), _writeData = /*#__PURE__*/ new WeakSet();
|
|
24
|
+
var _getNodeModule = /*#__PURE__*/ new WeakSet(), _loadData = /*#__PURE__*/ new WeakSet(), _writeData = /*#__PURE__*/ new WeakSet();
|
|
45
25
|
class StorageClass {
|
|
46
26
|
getItem(keyName, defaultValue = null) {
|
|
47
27
|
let keyValue = defaultValue;
|
|
@@ -140,32 +120,42 @@ class StorageClass {
|
|
|
140
120
|
}
|
|
141
121
|
}
|
|
142
122
|
constructor(){
|
|
123
|
+
_class_private_method_init(this, _getNodeModule);
|
|
143
124
|
_class_private_method_init(this, _loadData);
|
|
144
125
|
_class_private_method_init(this, _writeData);
|
|
145
126
|
_define_property(this, "data", null);
|
|
146
127
|
_define_property(this, "dataFile", 'box.dat');
|
|
147
128
|
_define_property(this, "nameRegex", /^@(?<key>[^.]+)(?:\.(?<path>.*))?$/);
|
|
148
|
-
if ('Node.js' === __WEBPACK_EXTERNAL_MODULE__lib_app_js__.$app) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
129
|
+
if ('Node.js' === __WEBPACK_EXTERNAL_MODULE__lib_app_js__.$app) _class_private_method_get(this, _loadData, loadData).call(this, this.dataFile).then((res)=>{
|
|
130
|
+
this.data = res;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function getNodeModule() {
|
|
135
|
+
if ('Node.js' === __WEBPACK_EXTERNAL_MODULE__lib_app_js__.$app) {
|
|
136
|
+
const fs = await import("fs");
|
|
137
|
+
const path = await import("path");
|
|
138
|
+
return {
|
|
139
|
+
fs,
|
|
140
|
+
path
|
|
141
|
+
};
|
|
153
142
|
}
|
|
143
|
+
return null;
|
|
154
144
|
}
|
|
155
|
-
function loadData(dataFile
|
|
145
|
+
async function loadData(dataFile) {
|
|
146
|
+
const { fs, path } = await _class_private_method_get(this, _getNodeModule, getNodeModule).call(this) ?? {};
|
|
147
|
+
if (!fs || !path) return {};
|
|
156
148
|
const curDirDataFilePath = path.resolve(dataFile);
|
|
157
149
|
const rootDirDataFilePath = path.resolve(process.cwd(), dataFile);
|
|
158
150
|
if (fs.existsSync(curDirDataFilePath)) return JSON.parse(fs.readFileSync(curDirDataFilePath, 'utf-8')) || {};
|
|
159
151
|
if (fs.existsSync(rootDirDataFilePath)) return JSON.parse(fs.readFileSync(rootDirDataFilePath, 'utf-8')) || {};
|
|
160
152
|
return {};
|
|
161
153
|
}
|
|
162
|
-
function writeData(dataFile) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
fs.writeFileSync(dataFilePath, JSON.stringify(this.data), 'utf-8');
|
|
168
|
-
}
|
|
154
|
+
async function writeData(dataFile) {
|
|
155
|
+
const { fs, path } = await _class_private_method_get(this, _getNodeModule, getNodeModule).call(this) ?? {};
|
|
156
|
+
if (!fs || !path) return;
|
|
157
|
+
const dataFilePath = path.resolve(dataFile);
|
|
158
|
+
fs.writeFileSync(dataFilePath, JSON.stringify(this.data), 'utf-8');
|
|
169
159
|
}
|
|
170
160
|
const Storage = new StorageClass();
|
|
171
161
|
export { Storage, StorageClass };
|
package/package.json
CHANGED