@nsnanocat/util 0.0.0-preview-255840e → 0.0.0-preview-b0f521c
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/{getStorage.js → getStorage.mjs} +5 -5
- package/dist/index.js +11 -11
- package/dist/index.mjs +11 -0
- package/dist/lib/app.d.ts +1 -1
- package/dist/lib/{done.js → done.mjs} +13 -13
- package/dist/lib/{environment.js → environment.mjs} +2 -2
- package/dist/lib/{index.js → index.mjs} +6 -6
- package/dist/lib/{notification.js → notification.mjs} +10 -10
- package/dist/lib/{runScript.js → runScript.mjs} +7 -7
- package/dist/polyfill/{Console.js → Console.mjs} +2 -2
- package/dist/polyfill/Storage.d.ts +7 -11
- package/dist/polyfill/Storage.mjs +188 -0
- package/dist/polyfill/fetch-node.d.ts +1 -0
- package/dist/polyfill/fetch-node.mjs +8 -0
- package/dist/polyfill/{fetch.js → fetch.mjs} +14 -16
- package/dist/polyfill/index.mjs +5 -0
- package/package.json +8 -12
- package/dist/env.d.cjs +0 -6
- package/dist/env.d.js +0 -0
- package/dist/getStorage.cjs +0 -96
- package/dist/index.cjs +0 -155
- package/dist/lib/app.cjs +0 -48
- package/dist/lib/done.cjs +0 -109
- package/dist/lib/environment.cjs +0 -70
- package/dist/lib/index.cjs +0 -101
- package/dist/lib/notification.cjs +0 -135
- package/dist/lib/runScript.cjs +0 -67
- package/dist/lib/time.cjs +0 -54
- package/dist/lib/wait.cjs +0 -40
- package/dist/polyfill/Console.cjs +0 -250
- package/dist/polyfill/Lodash.cjs +0 -132
- package/dist/polyfill/StatusTexts.cjs +0 -99
- package/dist/polyfill/Storage.cjs +0 -213
- package/dist/polyfill/Storage.js +0 -161
- package/dist/polyfill/fetch.cjs +0 -200
- package/dist/polyfill/index.cjs +0 -101
- package/dist/polyfill/index.js +0 -5
- /package/dist/lib/{app.js → app.mjs} +0 -0
- /package/dist/lib/{time.js → time.mjs} +0 -0
- /package/dist/lib/{wait.js → wait.mjs} +0 -0
- /package/dist/polyfill/{Lodash.js → Lodash.mjs} +0 -0
- /package/dist/polyfill/{StatusTexts.js → StatusTexts.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__ from "./polyfill/Lodash.mjs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Storage_mjs__ from "./polyfill/Storage.mjs";
|
|
3
3
|
function getStorage(key, names, database) {
|
|
4
4
|
var _database_Default, _database_Default1;
|
|
5
5
|
const nameList = Array.isArray(names) ? names : [
|
|
@@ -23,9 +23,9 @@ function getStorage(key, names, database) {
|
|
|
23
23
|
});
|
|
24
24
|
if ('string' == typeof $argument) {
|
|
25
25
|
const parsedArgument = Object.fromEntries($argument.split('&').map((item)=>item.split('=', 2).map((i)=>i.replace(/\"/g, ''))));
|
|
26
|
-
Object.keys(parsedArgument).forEach((key)=>(0,
|
|
27
|
-
} else if ('object' == typeof $argument) Object.keys($argument).forEach((key)=>(0,
|
|
28
|
-
const BoxJs =
|
|
26
|
+
Object.keys(parsedArgument).forEach((key)=>(0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.set)(Store.Settings, key, parsedArgument[key]));
|
|
27
|
+
} else if ('object' == typeof $argument) Object.keys($argument).forEach((key)=>(0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.set)(Store.Settings, key, $argument[key]));
|
|
28
|
+
const BoxJs = __WEBPACK_EXTERNAL_MODULE__polyfill_Storage_mjs__.Storage.getItem(key);
|
|
29
29
|
if (BoxJs) nameList.forEach((name)=>{
|
|
30
30
|
var _BoxJs_name, _BoxJs_name1;
|
|
31
31
|
const boxSettings = null == BoxJs ? void 0 : null === (_BoxJs_name = BoxJs[name]) || void 0 === _BoxJs_name ? void 0 : _BoxJs_name.Settings;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from "./lib/app.
|
|
2
|
-
export * from "./lib/done.
|
|
3
|
-
export * from "./lib/notification.
|
|
4
|
-
export * from "./lib/time.
|
|
5
|
-
export * from "./lib/wait.
|
|
6
|
-
export * from "./polyfill/Console.
|
|
7
|
-
export * from "./polyfill/fetch.
|
|
8
|
-
export * from "./polyfill/Lodash.
|
|
9
|
-
export * from "./polyfill/StatusTexts.
|
|
10
|
-
export * from "./polyfill/Storage.
|
|
11
|
-
export * from "./getStorage.
|
|
1
|
+
export * from "./lib/app.mjs";
|
|
2
|
+
export * from "./lib/done.mjs";
|
|
3
|
+
export * from "./lib/notification.mjs";
|
|
4
|
+
export * from "./lib/time.mjs";
|
|
5
|
+
export * from "./lib/wait.mjs";
|
|
6
|
+
export * from "./polyfill/Console.mjs";
|
|
7
|
+
export * from "./polyfill/fetch.mjs";
|
|
8
|
+
export * from "./polyfill/Lodash.mjs";
|
|
9
|
+
export * from "./polyfill/StatusTexts.mjs";
|
|
10
|
+
export * from "./polyfill/Storage.mjs";
|
|
11
|
+
export * from "./getStorage.mjs";
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./lib/app.mjs";
|
|
2
|
+
export * from "./lib/done.mjs";
|
|
3
|
+
export * from "./lib/notification.mjs";
|
|
4
|
+
export * from "./lib/time.mjs";
|
|
5
|
+
export * from "./lib/wait.mjs";
|
|
6
|
+
export * from "./polyfill/Console.mjs";
|
|
7
|
+
export * from "./polyfill/fetch.mjs";
|
|
8
|
+
export * from "./polyfill/Lodash.mjs";
|
|
9
|
+
export * from "./polyfill/StatusTexts.mjs";
|
|
10
|
+
export * from "./polyfill/Storage.mjs";
|
|
11
|
+
export * from "./getStorage.mjs";
|
package/dist/lib/app.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Current app name
|
|
3
3
|
*/
|
|
4
|
-
export declare const $app:
|
|
4
|
+
export declare const $app: 'Quantumult X' | 'Loon' | 'Shadowrocket' | 'Egern' | 'Surge' | 'Stash' | 'Node.js' | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__ from "../polyfill/Lodash.mjs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__ from "../polyfill/Console.mjs";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_StatusTexts_mjs__ from "../polyfill/StatusTexts.mjs";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__app_mjs__ from "./app.mjs";
|
|
5
5
|
const transformQuantumultXBody = (object)=>{
|
|
6
6
|
if (object.body instanceof ArrayBuffer) return {
|
|
7
7
|
bodyBytes: object.body,
|
|
@@ -17,22 +17,22 @@ const transformQuantumultXBody = (object)=>{
|
|
|
17
17
|
};
|
|
18
18
|
const transformQuantumultXStatus = (object)=>{
|
|
19
19
|
if ('number' == typeof object.status) return {
|
|
20
|
-
status: `HTTP/1.1 ${object.status} ${
|
|
20
|
+
status: `HTTP/1.1 ${object.status} ${__WEBPACK_EXTERNAL_MODULE__polyfill_StatusTexts_mjs__.StatusTexts[object.status]}`
|
|
21
21
|
};
|
|
22
22
|
if ('string' != typeof object.status && void 0 !== object.status) throw new TypeError(`${done.name}: 参数类型错误, status 必须为数字或字符串`);
|
|
23
23
|
return {};
|
|
24
24
|
};
|
|
25
25
|
const handleDoneFactory = (startTime)=>(result)=>{
|
|
26
|
-
|
|
26
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.log('🚩 执行结束!', startTime ? `🕛 ${((Date.now() - startTime) / 1000).toFixed(3)} 秒` : void 0);
|
|
27
27
|
$done(result);
|
|
28
28
|
};
|
|
29
29
|
function done(object = {}) {
|
|
30
30
|
let startTime = null == $script ? void 0 : $script.startTime;
|
|
31
|
-
if ('Surge' ===
|
|
31
|
+
if ('Surge' === __WEBPACK_EXTERNAL_MODULE__app_mjs__.$app) startTime *= 1000;
|
|
32
32
|
const handleDone = handleDoneFactory(startTime);
|
|
33
|
-
switch(
|
|
33
|
+
switch(__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app){
|
|
34
34
|
case 'Surge':
|
|
35
|
-
if (object.policy) (0,
|
|
35
|
+
if (object.policy) (0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.set)(object, 'headers.X-Surge-Policy', object.policy);
|
|
36
36
|
handleDone(object);
|
|
37
37
|
break;
|
|
38
38
|
case 'Loon':
|
|
@@ -40,7 +40,7 @@ function done(object = {}) {
|
|
|
40
40
|
handleDone(object);
|
|
41
41
|
break;
|
|
42
42
|
case 'Stash':
|
|
43
|
-
if (object.policy) (0,
|
|
43
|
+
if (object.policy) (0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.set)(object, 'headers.X-Stash-Selected-Proxy', encodeURI(object.policy));
|
|
44
44
|
handleDone(object);
|
|
45
45
|
break;
|
|
46
46
|
case 'Egern':
|
|
@@ -52,7 +52,7 @@ function done(object = {}) {
|
|
|
52
52
|
case 'Quantumult X':
|
|
53
53
|
{
|
|
54
54
|
const transformedObject = {
|
|
55
|
-
...(0,
|
|
55
|
+
...(0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.pick)(object, [
|
|
56
56
|
'status',
|
|
57
57
|
'url',
|
|
58
58
|
'headers',
|
|
@@ -62,13 +62,13 @@ function done(object = {}) {
|
|
|
62
62
|
...transformQuantumultXStatus(object),
|
|
63
63
|
...transformQuantumultXBody(object)
|
|
64
64
|
};
|
|
65
|
-
if (object.policy) (0,
|
|
65
|
+
if (object.policy) (0, __WEBPACK_EXTERNAL_MODULE__polyfill_Lodash_mjs__.set)(transformedObject, 'opts.policy', object.policy);
|
|
66
66
|
handleDone(transformedObject);
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
69
|
case 'Node.js':
|
|
70
70
|
default:
|
|
71
|
-
|
|
71
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.log('🚩 执行结束!');
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__app_mjs__ from "./app.mjs";
|
|
2
2
|
function environment_rslib_entry_environment() {
|
|
3
|
-
switch(
|
|
3
|
+
switch(__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app){
|
|
4
4
|
case 'Surge':
|
|
5
5
|
$environment.app = 'Surge';
|
|
6
6
|
return $environment;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
export * from "./done.
|
|
3
|
-
export * from "./notification.
|
|
4
|
-
export * from "./time.
|
|
5
|
-
export * from "./wait.
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__app_mjs__ from "./app.mjs";
|
|
2
|
+
export * from "./done.mjs";
|
|
3
|
+
export * from "./notification.mjs";
|
|
4
|
+
export * from "./time.mjs";
|
|
5
|
+
export * from "./wait.mjs";
|
|
6
6
|
var __webpack_modules__ = {
|
|
7
7
|
"./app.js": function(module) {
|
|
8
|
-
module.exports =
|
|
8
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__app_mjs__;
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
var __webpack_module_cache__ = {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
function notification(title = `ℹ️ ${
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__ from "../polyfill/Console.mjs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__app_mjs__ from "./app.mjs";
|
|
3
|
+
function notification(title = `ℹ️ ${__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app} 通知`, subtitle = '', body = '', content = {}) {
|
|
4
4
|
const mutableContent = getMutableContent(content);
|
|
5
|
-
switch(
|
|
5
|
+
switch(__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app){
|
|
6
6
|
case 'Quantumult X':
|
|
7
7
|
$notify(title, subtitle, body, mutableContent);
|
|
8
8
|
break;
|
|
@@ -12,9 +12,9 @@ function notification(title = `ℹ️ ${__WEBPACK_EXTERNAL_MODULE__app_js__.$app
|
|
|
12
12
|
$notification.post(title, subtitle, body, mutableContent);
|
|
13
13
|
break;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.group('📣 系统通知');
|
|
16
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.log(title, subtitle, body, JSON.stringify(mutableContent, null, 2));
|
|
17
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.groupEnd();
|
|
18
18
|
}
|
|
19
19
|
function getMutableContent(content) {
|
|
20
20
|
const mutableContent = {};
|
|
@@ -28,13 +28,13 @@ function getMutableContent(content) {
|
|
|
28
28
|
if (content) assignObjectContent(mutableContent, content);
|
|
29
29
|
break;
|
|
30
30
|
default:
|
|
31
|
-
|
|
31
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.error(`不支持的通知参数类型: ${typeof content}`);
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
34
|
return mutableContent;
|
|
35
35
|
}
|
|
36
36
|
function assignSimpleContent(mutableContent, content) {
|
|
37
|
-
switch(
|
|
37
|
+
switch(__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app){
|
|
38
38
|
case 'Quantumult X':
|
|
39
39
|
mutableContent['open-url'] = content;
|
|
40
40
|
break;
|
|
@@ -51,7 +51,7 @@ function assignObjectContent(mutableContent, content) {
|
|
|
51
51
|
const openUrl = content.open || content['open-url'] || content.url || content.openUrl;
|
|
52
52
|
const copyUrl = content.copy || content['update-pasteboard'] || content.updatePasteboard;
|
|
53
53
|
const mediaUrl = content.media || content['media-url'] || content.mediaUrl;
|
|
54
|
-
switch(
|
|
54
|
+
switch(__WEBPACK_EXTERNAL_MODULE__app_mjs__.$app){
|
|
55
55
|
case 'Quantumult X':
|
|
56
56
|
if (openUrl) mutableContent['open-url'] = openUrl;
|
|
57
57
|
if (null == mediaUrl ? void 0 : mediaUrl.startsWith('http')) mutableContent['media-url'] = mediaUrl;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__ from "../polyfill/Console.mjs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_Storage_mjs__ from "../polyfill/Storage.mjs";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__polyfill_fetch_mjs__ from "../polyfill/fetch.mjs";
|
|
4
4
|
async function runScript(script, runOpts = {}) {
|
|
5
5
|
try {
|
|
6
6
|
var _Storage_getItem_replace, _Storage_getItem;
|
|
7
|
-
const httpapi = null === (_Storage_getItem =
|
|
7
|
+
const httpapi = null === (_Storage_getItem = __WEBPACK_EXTERNAL_MODULE__polyfill_Storage_mjs__.Storage.getItem('@chavy_boxjs_userCfgs.httpapi')) || void 0 === _Storage_getItem ? void 0 : null === (_Storage_getItem_replace = _Storage_getItem.replace(/\n/g, '')) || void 0 === _Storage_getItem_replace ? void 0 : _Storage_getItem_replace.trim();
|
|
8
8
|
if (!httpapi) throw new Error('httpapi 配置未找到,请检查配置项!');
|
|
9
|
-
const httpapiTimeoutFromConfig = Number.parseInt(
|
|
9
|
+
const httpapiTimeoutFromConfig = Number.parseInt(__WEBPACK_EXTERNAL_MODULE__polyfill_Storage_mjs__.Storage.getItem('@chavy_boxjs_userCfgs.httpapi_timeout') || '20', 10);
|
|
10
10
|
const timeout = runOpts.timeout ?? httpapiTimeoutFromConfig;
|
|
11
11
|
const [password, address] = httpapi.split('@');
|
|
12
12
|
if (!password || !address) throw new Error('httpapi 配置格式错误,应为 password@address 格式!');
|
|
@@ -23,10 +23,10 @@ async function runScript(script, runOpts = {}) {
|
|
|
23
23
|
},
|
|
24
24
|
timeout
|
|
25
25
|
};
|
|
26
|
-
const response = await (0,
|
|
26
|
+
const response = await (0, __WEBPACK_EXTERNAL_MODULE__polyfill_fetch_mjs__.fetch)(request);
|
|
27
27
|
return response.body;
|
|
28
28
|
} catch (error) {
|
|
29
|
-
|
|
29
|
+
__WEBPACK_EXTERNAL_MODULE__polyfill_Console_mjs__.Console.error('运行脚本时发生错误:', error.message);
|
|
30
30
|
throw error;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__lib_app_mjs__ from "../lib/app.mjs";
|
|
2
2
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
3
3
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
4
|
}
|
|
@@ -44,7 +44,7 @@ var _counts = /*#__PURE__*/ new WeakMap(), _groups = /*#__PURE__*/ new WeakMap()
|
|
|
44
44
|
class ConsoleFactory {
|
|
45
45
|
error(...msg) {
|
|
46
46
|
if (_class_private_field_get(this, _level) < 1) return;
|
|
47
|
-
switch(
|
|
47
|
+
switch(__WEBPACK_EXTERNAL_MODULE__lib_app_mjs__.$app){
|
|
48
48
|
case 'Surge':
|
|
49
49
|
case 'Loon':
|
|
50
50
|
case 'Stash':
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
export declare class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
setItem(keyName: string, value: any): boolean;
|
|
9
|
-
removeItem(keyName: string): boolean;
|
|
10
|
-
clear(): boolean;
|
|
1
|
+
export declare class Storage {
|
|
2
|
+
static data: Record<string, any>;
|
|
3
|
+
static dataFile: string;
|
|
4
|
+
static getItem<T = any>(keyName: string, defaultValue?: T): T;
|
|
5
|
+
static setItem(keyName: string, value: any): boolean;
|
|
6
|
+
static removeItem(keyName: string): boolean;
|
|
7
|
+
static clear(): boolean;
|
|
11
8
|
}
|
|
12
|
-
export declare const Storage: StorageClass;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { $app } from '../lib/app.mjs';
|
|
2
|
+
import { Lodash as _ } from './Lodash.mjs';
|
|
3
|
+
export class Storage {
|
|
4
|
+
static data = null;
|
|
5
|
+
static dataFile = 'box.dat';
|
|
6
|
+
static #nameRegex = /^@(?<key>[^.]+)(?:\.(?<path>.*))?$/;
|
|
7
|
+
static getItem(keyName, defaultValue = null) {
|
|
8
|
+
let keyValue1 = defaultValue;
|
|
9
|
+
switch(keyName.startsWith('@')){
|
|
10
|
+
case true:
|
|
11
|
+
{
|
|
12
|
+
const { key, path } = keyName.match(Storage.#nameRegex)?.groups;
|
|
13
|
+
keyName = key;
|
|
14
|
+
let value = Storage.getItem(keyName, {});
|
|
15
|
+
if ('object' != typeof value) value = {};
|
|
16
|
+
keyValue1 = _.get(value, path);
|
|
17
|
+
try {
|
|
18
|
+
keyValue1 = JSON.parse(keyValue1);
|
|
19
|
+
} catch (e) {}
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
default:
|
|
23
|
+
switch($app){
|
|
24
|
+
case 'Surge':
|
|
25
|
+
case 'Loon':
|
|
26
|
+
case 'Stash':
|
|
27
|
+
case 'Egern':
|
|
28
|
+
case 'Shadowrocket':
|
|
29
|
+
keyValue1 = $persistentStore.read(keyName);
|
|
30
|
+
break;
|
|
31
|
+
case 'Quantumult X':
|
|
32
|
+
keyValue1 = $prefs.valueForKey(keyName);
|
|
33
|
+
break;
|
|
34
|
+
case 'Node.js':
|
|
35
|
+
Storage.data = Storage.#loaddata(Storage.dataFile);
|
|
36
|
+
keyValue1 = Storage.data?.[keyName];
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
keyValue1 = Storage.data?.[keyName] || null;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
keyValue1 = JSON.parse(keyValue1);
|
|
44
|
+
} catch (e) {}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return keyValue1 ?? defaultValue;
|
|
48
|
+
}
|
|
49
|
+
static setItem(keyName = new String(), keyValue1 = new String()) {
|
|
50
|
+
let result = false;
|
|
51
|
+
switch(typeof keyValue1){
|
|
52
|
+
case 'object':
|
|
53
|
+
keyValue1 = JSON.stringify(keyValue1);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
keyValue1 = String(keyValue1);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
switch(keyName.startsWith('@')){
|
|
60
|
+
case true:
|
|
61
|
+
{
|
|
62
|
+
const { key, path } = keyName.match(Storage.#nameRegex)?.groups;
|
|
63
|
+
keyName = key;
|
|
64
|
+
let value = Storage.getItem(keyName, {});
|
|
65
|
+
if ('object' != typeof value) value = {};
|
|
66
|
+
_.set(value, path, keyValue1);
|
|
67
|
+
result = Storage.setItem(keyName, value);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
switch($app){
|
|
72
|
+
case 'Surge':
|
|
73
|
+
case 'Loon':
|
|
74
|
+
case 'Stash':
|
|
75
|
+
case 'Egern':
|
|
76
|
+
case 'Shadowrocket':
|
|
77
|
+
result = $persistentStore.write(keyValue1, keyName);
|
|
78
|
+
break;
|
|
79
|
+
case 'Quantumult X':
|
|
80
|
+
result = $prefs.setValueForKey(keyValue1, keyName);
|
|
81
|
+
break;
|
|
82
|
+
case 'Node.js':
|
|
83
|
+
Storage.data = Storage.#loaddata(Storage.dataFile);
|
|
84
|
+
Storage.data[keyName] = keyValue1;
|
|
85
|
+
Storage.#writedata(Storage.dataFile);
|
|
86
|
+
result = true;
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
result = Storage.data?.[keyName] || null;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
static removeItem(keyName) {
|
|
97
|
+
let result = false;
|
|
98
|
+
switch(keyName.startsWith('@')){
|
|
99
|
+
case true:
|
|
100
|
+
{
|
|
101
|
+
const { key, path } = keyName.match(Storage.#nameRegex)?.groups;
|
|
102
|
+
keyName = key;
|
|
103
|
+
let value = Storage.getItem(keyName);
|
|
104
|
+
if ('object' != typeof value) value = {};
|
|
105
|
+
keyValue = _.unset(value, path);
|
|
106
|
+
result = Storage.setItem(keyName, value);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
switch($app){
|
|
111
|
+
case 'Surge':
|
|
112
|
+
case 'Loon':
|
|
113
|
+
case 'Stash':
|
|
114
|
+
case 'Egern':
|
|
115
|
+
case 'Shadowrocket':
|
|
116
|
+
result = false;
|
|
117
|
+
break;
|
|
118
|
+
case 'Quantumult X':
|
|
119
|
+
result = $prefs.removeValueForKey(keyName);
|
|
120
|
+
break;
|
|
121
|
+
case 'Node.js':
|
|
122
|
+
result = false;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
result = false;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
static clear() {
|
|
133
|
+
let result = false;
|
|
134
|
+
switch($app){
|
|
135
|
+
case 'Surge':
|
|
136
|
+
case 'Loon':
|
|
137
|
+
case 'Stash':
|
|
138
|
+
case 'Egern':
|
|
139
|
+
case 'Shadowrocket':
|
|
140
|
+
result = false;
|
|
141
|
+
break;
|
|
142
|
+
case 'Quantumult X':
|
|
143
|
+
result = $prefs.removeAllValues();
|
|
144
|
+
break;
|
|
145
|
+
case 'Node.js':
|
|
146
|
+
result = false;
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
result = false;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
static #loaddata = (dataFile)=>{
|
|
155
|
+
if ('Node.js' !== $app) return {};
|
|
156
|
+
{
|
|
157
|
+
this.fs = this.fs ? this.fs : require('node:fs');
|
|
158
|
+
this.path = this.path ? this.path : require('node:path');
|
|
159
|
+
const curDirDataFilePath = this.path.resolve(dataFile);
|
|
160
|
+
const rootDirDataFilePath = this.path.resolve(process.cwd(), dataFile);
|
|
161
|
+
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath);
|
|
162
|
+
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath);
|
|
163
|
+
if (!isCurDirDataFile && !isRootDirDataFile) return {};
|
|
164
|
+
{
|
|
165
|
+
const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath;
|
|
166
|
+
try {
|
|
167
|
+
return JSON.parse(this.fs.readFileSync(datPath));
|
|
168
|
+
} catch (e) {
|
|
169
|
+
return {};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
static #writedata = (dataFile = this.dataFile)=>{
|
|
175
|
+
if ('Node.js' === $app) {
|
|
176
|
+
this.fs = this.fs ? this.fs : require('node:fs');
|
|
177
|
+
this.path = this.path ? this.path : require('node:path');
|
|
178
|
+
const curDirDataFilePath = this.path.resolve(dataFile);
|
|
179
|
+
const rootDirDataFilePath = this.path.resolve(process.cwd(), dataFile);
|
|
180
|
+
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath);
|
|
181
|
+
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath);
|
|
182
|
+
const jsondata = JSON.stringify(this.data);
|
|
183
|
+
if (isCurDirDataFile) this.fs.writeFileSync(curDirDataFilePath, jsondata);
|
|
184
|
+
else if (isRootDirDataFile) this.fs.writeFileSync(rootDirDataFilePath, jsondata);
|
|
185
|
+
else this.fs.writeFileSync(curDirDataFilePath, jsondata);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getNodeFetch: () => Promise<{ fetch: typeof import('node-fetch').default }>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const getNodeFetch = ()=>{
|
|
2
|
+
const nodeFetch = globalThis.fetch ? globalThis.fetch : require('node-fetch');
|
|
3
|
+
const fetchCookie = globalThis.fetchCookie ? globalThis.fetchCookie : require('fetch-cookie').default;
|
|
4
|
+
const fetch = fetchCookie(nodeFetch);
|
|
5
|
+
return {
|
|
6
|
+
fetch
|
|
7
|
+
};
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__Lodash_mjs__ from "./Lodash.mjs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__lib_app_mjs__ from "../lib/app.mjs";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__StatusTexts_mjs__ from "./StatusTexts.mjs";
|
|
4
4
|
const binaryMimeTypes = [
|
|
5
5
|
'application/protobuf',
|
|
6
6
|
'application/x-protobuf',
|
|
@@ -38,9 +38,9 @@ async function fetch_rslib_entry_fetch(resource, options = {
|
|
|
38
38
|
params.timeout = Number.parseInt(params.timeout.toString(), 10);
|
|
39
39
|
if (params.timeout > 500) params.timeout = Math.round(params.timeout / 1000);
|
|
40
40
|
}
|
|
41
|
-
if ('Quantumult X' ===
|
|
42
|
-
if (params.policy) (0,
|
|
43
|
-
if ('boolean' == typeof params['auto-redirect']) (0,
|
|
41
|
+
if ('Quantumult X' === __WEBPACK_EXTERNAL_MODULE__lib_app_mjs__.$app) {
|
|
42
|
+
if (params.policy) (0, __WEBPACK_EXTERNAL_MODULE__Lodash_mjs__.set)(params, 'opts.policy', params.policy);
|
|
43
|
+
if ('boolean' == typeof params['auto-redirect']) (0, __WEBPACK_EXTERNAL_MODULE__Lodash_mjs__.set)(params, 'opts.redirection', params['auto-redirect']);
|
|
44
44
|
if (params.body instanceof ArrayBuffer) {
|
|
45
45
|
params.bodyBytes = params.body;
|
|
46
46
|
params.body = void 0;
|
|
@@ -53,7 +53,7 @@ async function fetch_rslib_entry_fetch(resource, options = {
|
|
|
53
53
|
var _split, _this, _response_headers, _response_headers1;
|
|
54
54
|
response.ok = /^2\d\d$/.test(response.statusCode);
|
|
55
55
|
response.status = response.statusCode;
|
|
56
|
-
response.statusText =
|
|
56
|
+
response.statusText = __WEBPACK_EXTERNAL_MODULE__StatusTexts_mjs__.StatusTexts[response.status];
|
|
57
57
|
if (binaryMimeTypes.includes(null === (_this = (null === (_response_headers = response.headers) || void 0 === _response_headers ? void 0 : _response_headers['Content-Type']) ?? (null === (_response_headers1 = response.headers) || void 0 === _response_headers1 ? void 0 : _response_headers1['content-type'])) || void 0 === _this ? void 0 : null === (_split = _this.split(';')) || void 0 === _split ? void 0 : _split[0])) response.body = response.bodyBytes;
|
|
58
58
|
response.bodyBytes = void 0;
|
|
59
59
|
return response;
|
|
@@ -65,10 +65,8 @@ async function fetch_rslib_entry_fetch(resource, options = {
|
|
|
65
65
|
})
|
|
66
66
|
]);
|
|
67
67
|
}
|
|
68
|
-
if ('Node.js' ===
|
|
69
|
-
const
|
|
70
|
-
const fetchCookie = globalThis.fetchCookie ? globalThis.fetchCookie : await import("fetch-cookie").then((module)=>module.default);
|
|
71
|
-
const fetch = fetchCookie(nodeFetch);
|
|
68
|
+
if ('Node.js' === __WEBPACK_EXTERNAL_MODULE__lib_app_mjs__.$app) {
|
|
69
|
+
const fetch = await import("./fetch-node.mjs").then((module)=>module.getNodeFetch().then((module)=>module.fetch));
|
|
72
70
|
params.timeout = (params.timeout ?? 5) * 1000;
|
|
73
71
|
params.redirect = params.redirection ? 'follow' : 'manual';
|
|
74
72
|
const { url, ...options } = params;
|
|
@@ -110,16 +108,16 @@ async function fetch_rslib_entry_fetch(resource, options = {
|
|
|
110
108
|
})
|
|
111
109
|
]);
|
|
112
110
|
}
|
|
113
|
-
if ('Loon' ===
|
|
114
|
-
if (params.policy) switch(
|
|
111
|
+
if ('Loon' === __WEBPACK_EXTERNAL_MODULE__lib_app_mjs__.$app) params.timeout *= 1000;
|
|
112
|
+
if (params.policy) switch(__WEBPACK_EXTERNAL_MODULE__lib_app_mjs__.$app){
|
|
115
113
|
case 'Loon':
|
|
116
114
|
params.node = params.policy;
|
|
117
115
|
break;
|
|
118
116
|
case 'Stash':
|
|
119
|
-
(0,
|
|
117
|
+
(0, __WEBPACK_EXTERNAL_MODULE__Lodash_mjs__.set)(params, 'headers.X-Stash-Selected-Proxy', encodeURI(params.policy));
|
|
120
118
|
break;
|
|
121
119
|
case 'Shadowrocket':
|
|
122
|
-
(0,
|
|
120
|
+
(0, __WEBPACK_EXTERNAL_MODULE__Lodash_mjs__.set)(params, 'headers.X-Surge-Proxy', params.policy);
|
|
123
121
|
break;
|
|
124
122
|
default:
|
|
125
123
|
break;
|
|
@@ -136,7 +134,7 @@ async function fetch_rslib_entry_fetch(resource, options = {
|
|
|
136
134
|
else {
|
|
137
135
|
response.ok = /^2\d\d$/.test(response.status);
|
|
138
136
|
response.statusCode = response.status;
|
|
139
|
-
response.statusText =
|
|
137
|
+
response.statusText = __WEBPACK_EXTERNAL_MODULE__StatusTexts_mjs__.StatusTexts[response.status];
|
|
140
138
|
if (body) {
|
|
141
139
|
response.body = body;
|
|
142
140
|
if (params['binary-mode']) response.bodyBytes = body;
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsnanocat/util",
|
|
3
3
|
"description": "Pure JS's util module for well-known iOS network tools",
|
|
4
|
-
"type": "module",
|
|
5
4
|
"author": "VirgilClyne <Virgil@nanocat.me>",
|
|
6
5
|
"homepage": "https://NSNanoCat.github.io/util",
|
|
7
6
|
"keywords": [
|
|
@@ -14,29 +13,26 @@
|
|
|
14
13
|
],
|
|
15
14
|
"license": "Apache-2.0",
|
|
16
15
|
"bugs": "https://github.com/NSNanoCat/util/issues",
|
|
17
|
-
"main": "./dist/index.
|
|
18
|
-
"module": "./dist/index.
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.mjs",
|
|
19
18
|
"types": "./dist/index.d.ts",
|
|
20
19
|
"exports": {
|
|
21
20
|
".": {
|
|
22
21
|
"types": "./dist/index.d.ts",
|
|
23
|
-
"import": "./dist/index.
|
|
24
|
-
"require": "./dist/index.
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.js"
|
|
25
24
|
},
|
|
26
25
|
"./getStorage": {
|
|
27
26
|
"types": "./dist/getStorage.d.ts",
|
|
28
|
-
"import": "./dist/getStorage.
|
|
29
|
-
"require": "./dist/getStorage.cjs"
|
|
27
|
+
"import": "./dist/getStorage.mjs"
|
|
30
28
|
},
|
|
31
29
|
"./polyfill/**": {
|
|
32
30
|
"types": "./dist/polyfill/**.d.ts",
|
|
33
|
-
"import": "./dist/polyfill/**.
|
|
34
|
-
"require": "./dist/polyfill/**.cjs"
|
|
31
|
+
"import": "./dist/polyfill/**.mjs"
|
|
35
32
|
},
|
|
36
33
|
"./lib/**": {
|
|
37
34
|
"types": "./dist/lib/**.d.ts",
|
|
38
|
-
"import": "./dist/lib/**.
|
|
39
|
-
"require": "./dist/lib/**.cjs"
|
|
35
|
+
"import": "./dist/lib/**.mjs"
|
|
40
36
|
}
|
|
41
37
|
},
|
|
42
38
|
"scripts": {
|
|
@@ -68,5 +64,5 @@
|
|
|
68
64
|
"fetch-cookie": "^3.1.0",
|
|
69
65
|
"node-fetch": "^3.3.2"
|
|
70
66
|
},
|
|
71
|
-
"version": "0.0.0-preview-
|
|
67
|
+
"version": "0.0.0-preview-b0f521c"
|
|
72
68
|
}
|
package/dist/env.d.cjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
var __webpack_exports__ = {};
|
|
2
|
-
var __webpack_export_target__ = exports;
|
|
3
|
-
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
4
|
-
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
package/dist/env.d.js
DELETED
|
File without changes
|