@whitesev/utils 2.3.2 → 2.3.4
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/index.amd.js +68 -44
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +68 -44
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +68 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +68 -44
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +68 -44
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +68 -44
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +62 -12
- package/dist/types/src/Log.d.ts +28 -30
- package/dist/types/src/VueObject.d.ts +4 -4
- package/package.json +1 -1
- package/src/Httpx.ts +117 -38
- package/src/Log.ts +72 -60
- package/src/Utils.ts +1 -1
- package/src/VueObject.ts +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1753,6 +1753,8 @@ class Httpx {
|
|
|
1753
1753
|
data: details.data || this.context.#defaultDetails.data,
|
|
1754
1754
|
redirect: details.redirect || this.context.#defaultDetails.redirect,
|
|
1755
1755
|
cookie: details.cookie || this.context.#defaultDetails.cookie,
|
|
1756
|
+
cookiePartition: details.cookiePartition ||
|
|
1757
|
+
this.context.#defaultDetails.cookiePartition,
|
|
1756
1758
|
binary: details.binary || this.context.#defaultDetails.binary,
|
|
1757
1759
|
nocache: details.nocache || this.context.#defaultDetails.nocache,
|
|
1758
1760
|
revalidate: details.revalidate || this.context.#defaultDetails.revalidate,
|
|
@@ -1854,6 +1856,15 @@ class Httpx {
|
|
|
1854
1856
|
else {
|
|
1855
1857
|
result.fetchInit = details.fetchInit;
|
|
1856
1858
|
}
|
|
1859
|
+
// 处理新的cookiePartition
|
|
1860
|
+
if (typeof result.cookiePartition === "object" &&
|
|
1861
|
+
result.cookiePartition != null) {
|
|
1862
|
+
if (Reflect.has(result.cookiePartition, "topLevelSite") &&
|
|
1863
|
+
typeof result.cookiePartition.topLevelSite !== "string") {
|
|
1864
|
+
// topLevelSite必须是字符串
|
|
1865
|
+
Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1857
1868
|
return result;
|
|
1858
1869
|
},
|
|
1859
1870
|
/**
|
|
@@ -2343,6 +2354,7 @@ class Httpx {
|
|
|
2343
2354
|
data: void 0,
|
|
2344
2355
|
redirect: void 0,
|
|
2345
2356
|
cookie: void 0,
|
|
2357
|
+
cookiePartition: void 0,
|
|
2346
2358
|
binary: void 0,
|
|
2347
2359
|
nocache: void 0,
|
|
2348
2360
|
revalidate: void 0,
|
|
@@ -3102,6 +3114,9 @@ class Log {
|
|
|
3102
3114
|
autoClearConsole: false,
|
|
3103
3115
|
logMaxCount: 999,
|
|
3104
3116
|
};
|
|
3117
|
+
/**
|
|
3118
|
+
* 颜色配置
|
|
3119
|
+
*/
|
|
3105
3120
|
#msgColorDetails = [
|
|
3106
3121
|
"font-weight: bold; color: cornflowerblue",
|
|
3107
3122
|
"font-weight: bold; color: cornflowerblue",
|
|
@@ -3109,16 +3124,16 @@ class Log {
|
|
|
3109
3124
|
"font-weight: bold; color: cornflowerblue",
|
|
3110
3125
|
];
|
|
3111
3126
|
/**
|
|
3112
|
-
* @param
|
|
3127
|
+
* @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
|
|
3113
3128
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
3114
3129
|
*/
|
|
3115
|
-
constructor(
|
|
3116
|
-
if (typeof
|
|
3117
|
-
this.tag =
|
|
3130
|
+
constructor(__GM_info, console = window.console) {
|
|
3131
|
+
if (typeof __GM_info === "string") {
|
|
3132
|
+
this.tag = __GM_info;
|
|
3118
3133
|
}
|
|
3119
|
-
else if (typeof
|
|
3120
|
-
typeof
|
|
3121
|
-
this.tag =
|
|
3134
|
+
else if (typeof __GM_info === "object" &&
|
|
3135
|
+
typeof __GM_info?.script?.name === "string") {
|
|
3136
|
+
this.tag = __GM_info.script.name;
|
|
3122
3137
|
}
|
|
3123
3138
|
this.#console = console;
|
|
3124
3139
|
}
|
|
@@ -3193,24 +3208,33 @@ class Log {
|
|
|
3193
3208
|
let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
|
|
3194
3209
|
let tagName = this.tag;
|
|
3195
3210
|
let that = this;
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3211
|
+
/** tag的html输出格式 */
|
|
3212
|
+
let tagNameHTML = `%c[${tagName}%c`;
|
|
3213
|
+
/** 调用的函数名的html输出格式 */
|
|
3214
|
+
let callerNameHTML = `%c${callerName}%c]%c`;
|
|
3215
|
+
callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
|
|
3216
|
+
/**
|
|
3217
|
+
* 输出消息到控制台
|
|
3218
|
+
* @param message
|
|
3219
|
+
*/
|
|
3220
|
+
function consoleMsg(message) {
|
|
3221
|
+
if (typeof message === "string") {
|
|
3222
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3199
3223
|
}
|
|
3200
|
-
else if (typeof
|
|
3201
|
-
that.#console.log(
|
|
3224
|
+
else if (typeof message === "number") {
|
|
3225
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3202
3226
|
}
|
|
3203
|
-
else if (typeof
|
|
3204
|
-
that.#console.log(
|
|
3227
|
+
else if (typeof message === "object") {
|
|
3228
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3205
3229
|
}
|
|
3206
3230
|
else {
|
|
3207
|
-
that.#console.log(
|
|
3231
|
+
that.#console.log(message);
|
|
3208
3232
|
}
|
|
3209
3233
|
}
|
|
3210
3234
|
if (Array.isArray(msg)) {
|
|
3211
|
-
msg.
|
|
3212
|
-
consoleMsg(
|
|
3213
|
-
}
|
|
3235
|
+
for (let index = 0; index < msg.length; index++) {
|
|
3236
|
+
consoleMsg(msg[index]);
|
|
3237
|
+
}
|
|
3214
3238
|
}
|
|
3215
3239
|
else {
|
|
3216
3240
|
consoleMsg(msg);
|
|
@@ -3222,67 +3246,67 @@ class Log {
|
|
|
3222
3246
|
}
|
|
3223
3247
|
/**
|
|
3224
3248
|
* 控制台-普通输出
|
|
3225
|
-
* @param
|
|
3226
|
-
* @
|
|
3227
|
-
*
|
|
3249
|
+
* @param args 需要输出的内容
|
|
3250
|
+
* @example
|
|
3251
|
+
* log.info("输出信息","输出信息2","输出信息3","输出")
|
|
3228
3252
|
*/
|
|
3229
|
-
info(
|
|
3253
|
+
info(...args) {
|
|
3230
3254
|
if (this.#disable)
|
|
3231
3255
|
return;
|
|
3232
|
-
this.printContent
|
|
3256
|
+
this.printContent(args, this.#details.infoColor);
|
|
3233
3257
|
}
|
|
3234
3258
|
/**
|
|
3235
3259
|
* 控制台-警告输出
|
|
3236
|
-
* @param
|
|
3237
|
-
* @
|
|
3238
|
-
*
|
|
3260
|
+
* @param args 需要输出的内容
|
|
3261
|
+
* @example
|
|
3262
|
+
* log.warn("输出警告","输出警告2","输出警告3","输出警告4")
|
|
3239
3263
|
*/
|
|
3240
|
-
warn(
|
|
3264
|
+
warn(...args) {
|
|
3241
3265
|
if (this.#disable)
|
|
3242
3266
|
return;
|
|
3243
|
-
this.printContent
|
|
3267
|
+
this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
|
|
3244
3268
|
}
|
|
3245
3269
|
/**
|
|
3246
3270
|
* 控制台-错误输出
|
|
3247
|
-
* @param
|
|
3248
|
-
* @
|
|
3249
|
-
*
|
|
3271
|
+
* @param args 需要输出的内容
|
|
3272
|
+
* @example
|
|
3273
|
+
* log.error("输出错误","输出错误2","输出错误3","输出错误4")
|
|
3250
3274
|
*/
|
|
3251
|
-
error(
|
|
3275
|
+
error(...args) {
|
|
3252
3276
|
if (this.#disable)
|
|
3253
3277
|
return;
|
|
3254
|
-
this.printContent
|
|
3278
|
+
this.printContent(args, this.#details.errorColor);
|
|
3255
3279
|
}
|
|
3256
3280
|
/**
|
|
3257
3281
|
* 控制台-成功输出
|
|
3258
|
-
* @param
|
|
3259
|
-
* @
|
|
3260
|
-
*
|
|
3282
|
+
* @param args 需要输出的内容
|
|
3283
|
+
* @example
|
|
3284
|
+
* log.success("输出成功")
|
|
3261
3285
|
*/
|
|
3262
|
-
success(
|
|
3286
|
+
success(...args) {
|
|
3263
3287
|
if (this.#disable)
|
|
3264
3288
|
return;
|
|
3265
|
-
this.printContent
|
|
3289
|
+
this.printContent(args, this.#details.successColor);
|
|
3266
3290
|
}
|
|
3267
3291
|
/**
|
|
3268
3292
|
* 控制台-输出表格
|
|
3269
|
-
* @param msg
|
|
3270
|
-
* @param color 输出的颜色
|
|
3271
|
-
* @param otherStyle 其它CSS
|
|
3293
|
+
* @param msg 需要输出的内容
|
|
3272
3294
|
* @example
|
|
3273
3295
|
* log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
|
|
3274
3296
|
*/
|
|
3275
|
-
table(msg
|
|
3297
|
+
table(msg) {
|
|
3276
3298
|
if (this.#disable)
|
|
3277
3299
|
return;
|
|
3278
3300
|
this.checkClearConsole();
|
|
3279
3301
|
let stack = new Error().stack.split("\n");
|
|
3280
3302
|
stack.splice(0, 1);
|
|
3281
3303
|
let errorStackParse = this.parseErrorStack(stack);
|
|
3304
|
+
/** 堆栈函数名 */
|
|
3282
3305
|
let stackFunctionName = errorStackParse.name;
|
|
3306
|
+
/** 堆栈位置 */
|
|
3283
3307
|
let stackFunctionNamePosition = errorStackParse.position;
|
|
3284
3308
|
let callerName = stackFunctionName;
|
|
3285
|
-
this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${
|
|
3309
|
+
this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${this.#details.infoColor};`);
|
|
3286
3310
|
this.#console.table(msg);
|
|
3287
3311
|
if (this.#details.debug) {
|
|
3288
3312
|
this.#console.log(stackFunctionNamePosition);
|
|
@@ -3926,7 +3950,7 @@ class Utils {
|
|
|
3926
3950
|
this.windowApi = new WindowApi(option);
|
|
3927
3951
|
}
|
|
3928
3952
|
/** 版本号 */
|
|
3929
|
-
version = "2024.9.
|
|
3953
|
+
version = "2024.9.28";
|
|
3930
3954
|
addStyle(cssText) {
|
|
3931
3955
|
if (typeof cssText !== "string") {
|
|
3932
3956
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|