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