@whitesev/utils 1.1.2 → 1.1.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 +93 -18
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +93 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +93 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +93 -18
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +93 -18
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +93 -18
- package/dist/index.umd.js.map +1 -1
- package/dist/src/ColorConversion.d.ts +0 -1
- package/dist/src/GBKEncoder.d.ts +1 -1
- package/dist/src/UtilsGMCookie.d.ts +33 -2
- package/package.json +1 -1
- package/src/ColorConversion.ts +0 -1
- package/src/GBKEncoder.ts +16 -14
- package/src/UtilsGMCookie.ts +93 -11
package/dist/index.system.js
CHANGED
|
@@ -4,7 +4,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
4
4
|
execute: (function () {
|
|
5
5
|
|
|
6
6
|
class ColorConversion {
|
|
7
|
-
constructor() { }
|
|
8
7
|
/**
|
|
9
8
|
* 判断是否是16进制颜色
|
|
10
9
|
* @param str
|
|
@@ -200,25 +199,23 @@ System.register('Utils', [], (function (exports) {
|
|
|
200
199
|
}
|
|
201
200
|
/**
|
|
202
201
|
* 解码
|
|
203
|
-
* @param
|
|
202
|
+
* @param str
|
|
204
203
|
*/
|
|
205
204
|
decode(str) {
|
|
206
205
|
var GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
207
206
|
var UTFMatcher = /%[0-9A-F]{2}/;
|
|
208
|
-
var
|
|
207
|
+
var utf = true;
|
|
208
|
+
let that = this;
|
|
209
209
|
while (utf) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (gbk && gbk in G2Uhash) {
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
str = str.replace(gbk, String.fromCharCode("0x" + G2Uhash[gbk]));
|
|
210
|
+
let gbkMatch = str.match(GBKMatcher);
|
|
211
|
+
let utfMatch = str.match(UTFMatcher);
|
|
212
|
+
utf = Boolean(utfMatch);
|
|
213
|
+
if (gbkMatch && gbkMatch in that.#G2Uhash) {
|
|
214
|
+
str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
|
|
218
215
|
}
|
|
219
216
|
else {
|
|
220
217
|
// @ts-ignore
|
|
221
|
-
str = str.replace(
|
|
218
|
+
str = str.replace(utfMatch, decodeURIComponent(utfMatch));
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
221
|
return str;
|
|
@@ -265,17 +262,51 @@ System.register('Utils', [], (function (exports) {
|
|
|
265
262
|
|
|
266
263
|
class UtilsGMCookie {
|
|
267
264
|
/**
|
|
268
|
-
*
|
|
265
|
+
* 获取单个cookie
|
|
266
|
+
* @param cookieName cookie名
|
|
267
|
+
*/
|
|
268
|
+
get(cookieName) {
|
|
269
|
+
if (typeof cookieName !== "string") {
|
|
270
|
+
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
271
|
+
}
|
|
272
|
+
let cookies = document.cookie.split(";");
|
|
273
|
+
let findCookie = cookies.find((item) => {
|
|
274
|
+
item = item.trimStart();
|
|
275
|
+
let itemName = item.split("=")[0];
|
|
276
|
+
let itemValue = item.replace(new RegExp("^" + itemName + "="), "");
|
|
277
|
+
if (itemName === cookieName) {
|
|
278
|
+
return itemValue;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
if (findCookie) {
|
|
282
|
+
return {
|
|
283
|
+
domain: globalThis.location.hostname,
|
|
284
|
+
expirationDate: null,
|
|
285
|
+
hostOnly: true,
|
|
286
|
+
httpOnly: false,
|
|
287
|
+
name: cookieName,
|
|
288
|
+
path: "/",
|
|
289
|
+
sameSite: "unspecified",
|
|
290
|
+
secure: true,
|
|
291
|
+
session: false,
|
|
292
|
+
value: findCookie,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 获取多组Cookie
|
|
269
298
|
* @param paramDetails
|
|
270
299
|
* @param callback
|
|
271
300
|
* + cookies object[]
|
|
272
301
|
* + error string|undefined
|
|
273
302
|
**/
|
|
274
|
-
list(paramDetails
|
|
303
|
+
list(paramDetails, callback) {
|
|
304
|
+
if (paramDetails == null) {
|
|
305
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
306
|
+
}
|
|
275
307
|
let resultData = [];
|
|
276
308
|
try {
|
|
277
309
|
let details = {
|
|
278
|
-
// @ts-ignore
|
|
279
310
|
url: globalThis.location.href,
|
|
280
311
|
domain: globalThis.location.hostname,
|
|
281
312
|
name: "",
|
|
@@ -303,14 +334,58 @@ System.register('Utils', [], (function (exports) {
|
|
|
303
334
|
session: false,
|
|
304
335
|
value: itemValue,
|
|
305
336
|
});
|
|
306
|
-
return;
|
|
307
337
|
}
|
|
308
338
|
});
|
|
309
|
-
callback
|
|
339
|
+
if (typeof callback === "function") {
|
|
340
|
+
callback(resultData);
|
|
341
|
+
}
|
|
310
342
|
}
|
|
311
343
|
catch (error) {
|
|
312
|
-
|
|
344
|
+
if (typeof callback === "function") {
|
|
345
|
+
callback(resultData, error);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* 获取多组Cookie
|
|
351
|
+
* @param paramDetails
|
|
352
|
+
**/
|
|
353
|
+
getList(paramDetails) {
|
|
354
|
+
if (paramDetails == null) {
|
|
355
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
313
356
|
}
|
|
357
|
+
let resultData = [];
|
|
358
|
+
let details = {
|
|
359
|
+
url: globalThis.location.href,
|
|
360
|
+
domain: globalThis.location.hostname,
|
|
361
|
+
name: "",
|
|
362
|
+
path: "/",
|
|
363
|
+
};
|
|
364
|
+
details = utils.assign(details, paramDetails);
|
|
365
|
+
let cookies = document.cookie.split(";");
|
|
366
|
+
cookies.forEach((item) => {
|
|
367
|
+
item = item.trimStart();
|
|
368
|
+
let itemName = item.split("=")[0];
|
|
369
|
+
let itemValue = item.replace(new RegExp("^" + itemName + "="), "");
|
|
370
|
+
let nameRegexp = details.name instanceof RegExp
|
|
371
|
+
? details.name
|
|
372
|
+
: new RegExp("^" + details.name, "g");
|
|
373
|
+
if (itemName.match(nameRegexp)) {
|
|
374
|
+
resultData.push({
|
|
375
|
+
domain: globalThis.location.hostname,
|
|
376
|
+
expirationDate: null,
|
|
377
|
+
hostOnly: true,
|
|
378
|
+
httpOnly: false,
|
|
379
|
+
name: itemName,
|
|
380
|
+
path: "/",
|
|
381
|
+
sameSite: "unspecified",
|
|
382
|
+
secure: true,
|
|
383
|
+
session: false,
|
|
384
|
+
value: itemValue,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
return resultData;
|
|
314
389
|
}
|
|
315
390
|
/**
|
|
316
391
|
* 设置Cookie
|