amos-tool 1.4.7 → 1.4.10
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/.prettierignore +2 -2
- package/.prettierrc +50 -50
- package/README.md +3 -0
- package/apis/objectPath.md +129 -129
- package/docs/Logger.html +160 -2
- package/docs/global.html +529 -65
- package/docs/index.html +5 -2
- package/index.d.ts +11 -2
- package/index.js +3 -3
- package/lib/_browser.js +10 -8
- package/lib/_clone.js +68 -57
- package/lib/_cookie.js +50 -47
- package/lib/_deepCopy.js +14 -19
- package/lib/_deepEqual.js +7 -8
- package/lib/_fastDeepEqual.js +26 -34
- package/lib/_flashSupport.js +13 -10
- package/lib/_forOwn.js +8 -7
- package/lib/_funcThrottle.js +16 -15
- package/lib/_isnode.js +2 -1
- package/lib/_list.js +74 -79
- package/lib/_object.assign.js +19 -19
- package/lib/_object.entries.js +8 -7
- package/lib/_object.values.js +8 -7
- package/lib/_omit.js +12 -11
- package/lib/_parseJson.js +7 -6
- package/lib/_pick.js +8 -7
- package/lib/_queue.js +24 -21
- package/lib/_shallowCopy.js +24 -23
- package/lib/_stringify.js +13 -10
- package/lib/_supportWs.js +5 -5
- package/lib/_trim.js +5 -4
- package/lib/_typeOfList.js +22 -21
- package/lib/_uuids.js +30 -35
- package/lib/amostool.js +4 -66
- package/lib/array2tree.js +9 -9
- package/lib/arrayFilter.js +18 -19
- package/lib/arrayUtils.js +10 -8
- package/lib/browser/Cookie.js +35 -36
- package/lib/browser/indexDB.js +72 -71
- package/lib/browserSupport.js +76 -71
- package/lib/completeUnit.js +7 -4
- package/lib/consts.js +2 -1
- package/lib/dom/canvas2img.js +61 -72
- package/lib/dom/canvasTools.js +11 -16
- package/lib/dom/downloadFile.js +17 -12
- package/lib/dom/eventHelper.js +8 -6
- package/lib/dom/fileBlob.js +14 -14
- package/lib/dom/fileSaveAs.js +54 -61
- package/lib/dom/getFontSize.js +7 -10
- package/lib/dom/minfyImg.js +27 -24
- package/lib/encrypt/_base64.js +32 -25
- package/lib/encrypt/_md5.js +68 -31
- package/lib/encrypt/des.js +430 -366
- package/lib/extra/_common.js +120 -161
- package/lib/extra/filterNull.js +5 -4
- package/lib/extra/find.js +10 -11
- package/lib/extra/index.js +4 -3
- package/lib/extra/memo.js +18 -0
- package/lib/extra/pathToTree.js +49 -36
- package/lib/extra/pwdStrength.js +4 -2
- package/lib/extra/sortBy.js +28 -30
- package/lib/flat.js +9 -13
- package/lib/locationParams.js +93 -95
- package/lib/log.js +23 -26
- package/lib/math/_keyColor.js +3 -1
- package/lib/math/addition.js +9 -7
- package/lib/math/amountCase.js +8 -12
- package/lib/math/coinFormat.js +6 -4
- package/lib/math/colorUtil.js +91 -94
- package/lib/math/dateTime.js +79 -97
- package/lib/math/operations.js +33 -37
- package/lib/math/pwdStrength.js +4 -2
- package/lib/math/randomColor.js +17 -5
- package/lib/math/subtraction.js +10 -9
- package/lib/merged.js +9 -9
- package/lib/objectPath.js +81 -82
- package/lib/parseText.js +8 -7
- package/lib/png/Identicon.js +32 -28
- package/lib/png/pnglib.js +59 -34
- package/lib/png/randomPic.js +8 -14
- package/lib/positionFactory.js +28 -28
- package/lib/pwdPolicy.js +27 -31
- package/lib/qs/_assign.js +7 -5
- package/lib/qs/_merge.js +20 -23
- package/lib/qs/_tools.js +3 -2
- package/lib/qs/formats.js +6 -5
- package/lib/qs/index.js +4 -4
- package/lib/qs/parse.js +56 -51
- package/lib/qs/stringify.js +54 -69
- package/lib/qs/utils.js +70 -83
- package/lib/random.js +5 -4
- package/lib/shallowEqual.js +25 -29
- package/lib/store.js +93 -95
- package/lib/strUtils.js +52 -43
- package/lib/tableFilter.js +178 -169
- package/lib/throttleDebounce.js +18 -22
- package/lib/url/encodeUrl.js +5 -4
- package/lib/url/restfulUrl.js +8 -7
- package/lib/utils.js +170 -222
- package/lib/xss/htmlEncode.js +3 -2
- package/lib/xss/implementEncode.js +36 -37
- package/lib/xss/index.js +4 -3
- package/package.json +4 -4
package/lib/_uuids.js
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"d+": t.getDate(),
|
|
12
|
-
"h+": t.getHours(),
|
|
13
|
-
"m+": t.getMinutes(),
|
|
14
|
-
"s+": t.getSeconds(),
|
|
15
|
-
S: t.getMilliseconds()
|
|
16
|
-
};
|
|
17
|
-
for (x in /(y+)/.test(e) && (e = e.replace(RegExp.$1, (t.getFullYear() + "").substr(4 - RegExp.$1.length))), n) new RegExp("(" + x + ")").test(e) && (e = e.replace(RegExp.$1, 1 == RegExp.$1.length ? n[x] : ("00" + n[x]).substr(("" + n[x]).length)));
|
|
18
|
-
return e
|
|
2
|
+
|
|
3
|
+
var CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), now = +new Date, index = 0, longtimeIndex = 0, formatDate = function() {
|
|
4
|
+
var x = "yyyyMMddhhmm", e = new Date, t = {
|
|
5
|
+
"M+": e.getMonth() + 1,
|
|
6
|
+
"d+": e.getDate(),
|
|
7
|
+
"h+": e.getHours(),
|
|
8
|
+
"m+": e.getMinutes(),
|
|
9
|
+
"s+": e.getSeconds(),
|
|
10
|
+
S: e.getMilliseconds()
|
|
19
11
|
};
|
|
12
|
+
for (var n in /(y+)/.test(x) && (x = x.replace(RegExp.$1, (e.getFullYear() + "").substr(4 - RegExp.$1.length))),
|
|
13
|
+
t) new RegExp("(" + n + ")").test(x) && (x = x.replace(RegExp.$1, 1 == RegExp.$1.length ? t[n] : ("00" + t[n]).substr(("" + t[n]).length)));
|
|
14
|
+
return x;
|
|
15
|
+
};
|
|
16
|
+
|
|
20
17
|
module.exports = {
|
|
21
18
|
uuid: function(x, e) {
|
|
22
|
-
var t, n, r = CHARS,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
else
|
|
27
|
-
for (o[8] = o[13] = o[18] = o[23] = "-", o[14] = "4", t = 0; t < 36; t++) o[t] || (n = 0 | 16 * Math.random(), o[t] = r[19 == t ? 3 & n | 8 : n]);
|
|
28
|
-
return o.join("")
|
|
19
|
+
var t, n, r = CHARS, o = [];
|
|
20
|
+
if (e = e || r.length, x) for (t = 0; t < x; t++) o[t] = r[0 | Math.random() * e]; else for (o[8] = o[13] = o[18] = o[23] = "-",
|
|
21
|
+
o[14] = "4", t = 0; t < 36; t++) o[t] || (n = 0 | 16 * Math.random(), o[t] = r[19 == t ? 3 & n | 8 : n]);
|
|
22
|
+
return o.join("");
|
|
29
23
|
},
|
|
30
24
|
uuidFast: function() {
|
|
31
|
-
for (var x, e = CHARS, t = new Array(36), n = 0, r = 0; r < 36; r++) 8 == r || 13 == r || 18 == r || 23 == r ? t[r] = "-" : 14 == r ? t[r] = "4" : (
|
|
32
|
-
|
|
25
|
+
for (var x, e = CHARS, t = new Array(36), n = 0, r = 0; r < 36; r++) 8 == r || 13 == r || 18 == r || 23 == r ? t[r] = "-" : 14 == r ? t[r] = "4" : (n <= 2 && (n = 33554432 + 16777216 * Math.random() | 0),
|
|
26
|
+
x = 15 & n, n >>= 4, t[r] = e[19 == r ? 3 & x | 8 : x]);
|
|
27
|
+
return t.join("");
|
|
33
28
|
},
|
|
34
29
|
uuidCompact: function() {
|
|
35
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(x) {
|
|
30
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function(x) {
|
|
36
31
|
var e = 16 * Math.random() | 0;
|
|
37
|
-
return ("x" == x ? e : 3 & e | 8).toString(16)
|
|
38
|
-
})
|
|
32
|
+
return ("x" == x ? e : 3 & e | 8).toString(16);
|
|
33
|
+
}));
|
|
39
34
|
},
|
|
40
35
|
timeUUID: function(x) {
|
|
41
|
-
return
|
|
36
|
+
return x || (x = "amos-timeuuid"), x + "-" + now + "-" + ++index;
|
|
42
37
|
},
|
|
43
38
|
longTimeUUID: function(x) {
|
|
44
|
-
return
|
|
39
|
+
return x || (x = "longtime"), x + "-" + formatDate() + "-" + ++longtimeIndex;
|
|
45
40
|
},
|
|
46
41
|
otherUUID: function(x) {
|
|
47
|
-
return (x = x || "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx").replace(/[xy]/g, function(x) {
|
|
42
|
+
return (x = x || "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx").replace(/[xy]/g, (function(x) {
|
|
48
43
|
var e = 16 * Math.random() | 0;
|
|
49
|
-
return ("x" == x ? e : 3 & e | 8).toString(16)
|
|
50
|
-
}).replace(/\-/g, "")
|
|
44
|
+
return ("x" == x ? e : 3 & e | 8).toString(16);
|
|
45
|
+
})).replace(/\-/g, "");
|
|
51
46
|
}
|
|
52
|
-
};
|
|
47
|
+
};
|
package/lib/amostool.js
CHANGED
|
@@ -1,69 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Browser = require("./_browser"),
|
|
6
|
-
cloneTools = require("./_clone"),
|
|
7
|
-
amosCookie = require("./_cookie"),
|
|
8
|
-
deepCopy = require("./_deepCopy"),
|
|
9
|
-
deepEqual = require("./_deepEqual"),
|
|
10
|
-
_fastDeepEqual = require("./_fastDeepEqual"),
|
|
11
|
-
funcThrottle = require("./_funcThrottle"),
|
|
12
|
-
isNode = require("./_isnode"),
|
|
13
|
-
List = require("./_list"),
|
|
14
|
-
_objectAssign = require("./_object.assign"),
|
|
15
|
-
_objectEntries = require("./_object.entries"),
|
|
16
|
-
_objectValues = require("./_object.values"),
|
|
17
|
-
omit = require("./_omit"),
|
|
18
|
-
pick = require("./_pick"),
|
|
19
|
-
parseJson = require("./_parseJson"),
|
|
20
|
-
Queue = require("./_queue"),
|
|
21
|
-
shallowCopy = require("./_shallowCopy"),
|
|
22
|
-
stringify = require("./_stringify"),
|
|
23
|
-
supportWs = require("./_supportWs"),
|
|
24
|
-
trim = require("./_trim"),
|
|
25
|
-
UUID = require("./_uuids"),
|
|
26
|
-
array2tree = require("./array2tree"),
|
|
27
|
-
arrayFilter = require("./arrayFilter"),
|
|
28
|
-
arrayUtils = require("./arrayUtils"),
|
|
29
|
-
browserSupport = require("./browserSupport"),
|
|
30
|
-
completeUnit = require("./completeUnit"),
|
|
31
|
-
consts = require("./consts"),
|
|
32
|
-
flat = require("./flat"),
|
|
33
|
-
LocationParam = require("./locationParams"),
|
|
34
|
-
Log = require("./log"),
|
|
35
|
-
merged = require("./merged"),
|
|
36
|
-
objectPath = require("./objectPath"),
|
|
37
|
-
parseText = require("./parseText"),
|
|
38
|
-
pwdPolicy = require("./pwdPolicy"),
|
|
39
|
-
random = require("./random"),
|
|
40
|
-
shallowEqual = require("./shallowEqual"),
|
|
41
|
-
Store = require("./store"),
|
|
42
|
-
strUtils = require("./strUtils"),
|
|
43
|
-
tableFilter = require("./tableFilter"),
|
|
44
|
-
utils = require("./utils"),
|
|
45
|
-
canvas2img = require("./dom/canvas2img"),
|
|
46
|
-
canvasTools = require("./dom/canvasTools"),
|
|
47
|
-
downloadFile = require("./dom/downloadFile"),
|
|
48
|
-
eventHelper = require("./dom/eventHelper"),
|
|
49
|
-
fileBlob = require("./dom/fileBlob"),
|
|
50
|
-
fileSaveAs = require("./dom/fileSaveAs"),
|
|
51
|
-
getFontSize = require("./dom/getFontSize"),
|
|
52
|
-
minfyImg = require("./dom/minfyImg"),
|
|
53
|
-
addition = require("./math/addition"),
|
|
54
|
-
amountCase = require("./math/amountCase"),
|
|
55
|
-
coinFormat = require("./math/coinFormat"),
|
|
56
|
-
colorUtil = require("./math/colorUtil"),
|
|
57
|
-
dateTime = require("./math/dateTime"),
|
|
58
|
-
pwdStrength = require("./math/pwdStrength"),
|
|
59
|
-
randomColor = require("./math/randomColor"),
|
|
60
|
-
subtraction = require("./math/subtraction"),
|
|
61
|
-
qs = require("./qs"),
|
|
62
|
-
encodeUrl = require("./url/encodeUrl"),
|
|
63
|
-
restfulUrl = require("./url/restfulUrl"),
|
|
64
|
-
positionFactory = require("./positionFactory"),
|
|
65
|
-
throttleDebounce = require("./throttleDebounce"),
|
|
66
|
-
checkFlash = require("./_flashSupport");
|
|
2
|
+
|
|
3
|
+
var Base64 = require("./encrypt/_base64"), MD5 = require("./encrypt/_md5"), DES = require("./encrypt/des"), Browser = require("./_browser"), cloneTools = require("./_clone"), amosCookie = require("./_cookie"), deepCopy = require("./_deepCopy"), deepEqual = require("./_deepEqual"), _fastDeepEqual = require("./_fastDeepEqual"), funcThrottle = require("./_funcThrottle"), isNode = require("./_isnode"), List = require("./_list"), _objectAssign = require("./_object.assign"), _objectEntries = require("./_object.entries"), _objectValues = require("./_object.values"), omit = require("./_omit"), pick = require("./_pick"), parseJson = require("./_parseJson"), Queue = require("./_queue"), shallowCopy = require("./_shallowCopy"), stringify = require("./_stringify"), supportWs = require("./_supportWs"), trim = require("./_trim"), UUID = require("./_uuids"), array2tree = require("./array2tree"), arrayFilter = require("./arrayFilter"), arrayUtils = require("./arrayUtils"), browserSupport = require("./browserSupport"), completeUnit = require("./completeUnit"), consts = require("./consts"), flat = require("./flat"), LocationParam = require("./locationParams"), Log = require("./log"), merged = require("./merged"), objectPath = require("./objectPath"), parseText = require("./parseText"), pwdPolicy = require("./pwdPolicy"), random = require("./random"), shallowEqual = require("./shallowEqual"), Store = require("./store"), strUtils = require("./strUtils"), tableFilter = require("./tableFilter"), utils = require("./utils"), canvas2img = require("./dom/canvas2img"), canvasTools = require("./dom/canvasTools"), downloadFile = require("./dom/downloadFile"), eventHelper = require("./dom/eventHelper"), fileBlob = require("./dom/fileBlob"), fileSaveAs = require("./dom/fileSaveAs"), getFontSize = require("./dom/getFontSize"), minfyImg = require("./dom/minfyImg"), addition = require("./math/addition"), amountCase = require("./math/amountCase"), coinFormat = require("./math/coinFormat"), colorUtil = require("./math/colorUtil"), dateTime = require("./math/dateTime"), pwdStrength = require("./math/pwdStrength"), randomColor = require("./math/randomColor"), subtraction = require("./math/subtraction"), qs = require("./qs"), encodeUrl = require("./url/encodeUrl"), restfulUrl = require("./url/restfulUrl"), positionFactory = require("./positionFactory"), throttleDebounce = require("./throttleDebounce"), checkFlash = require("./_flashSupport");
|
|
4
|
+
|
|
67
5
|
module.exports = {
|
|
68
6
|
Base64: Base64,
|
|
69
7
|
MD5: MD5,
|
|
@@ -131,4 +69,4 @@ module.exports = {
|
|
|
131
69
|
positionFactory: positionFactory,
|
|
132
70
|
throttleDebounce: throttleDebounce,
|
|
133
71
|
checkFlash: checkFlash
|
|
134
|
-
};
|
|
72
|
+
};
|
package/lib/array2tree.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
function array2tree(e, r, n) {
|
|
4
4
|
(n = n || {}).childrenKeyName = n.childrenKeyName || "children";
|
|
5
|
-
var t, i = e || [],
|
|
6
|
-
a = [],
|
|
7
|
-
l = 0;
|
|
5
|
+
var t, i = e || [], a = [], l = 0;
|
|
8
6
|
do {
|
|
9
|
-
if (!(t = i.filter(function(e) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
if (!(t = i.filter((function(e) {
|
|
8
|
+
return r(e, l);
|
|
9
|
+
}))[0])) break;
|
|
10
|
+
a.push(t), i = t[n.childrenKeyName] || [], l += 1;
|
|
11
|
+
} while (i.length > 0);
|
|
12
|
+
return a;
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
module.exports = array2tree;
|
package/lib/arrayFilter.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
var _utils = require("./utils");
|
|
3
4
|
|
|
4
5
|
function arrayFilter(r, e) {
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
e && _utils.isArray(e) ? i(e) : -1 < r[t].indexOf(a) && l.push(r)
|
|
13
|
-
})
|
|
14
|
-
}(r || []), l
|
|
6
|
+
var i = (e = e || {}).key || "", a = e.value || "", t = e.childrenKey || "children", n = [];
|
|
7
|
+
return function r(e) {
|
|
8
|
+
e.forEach((function(e) {
|
|
9
|
+
var l = e[t];
|
|
10
|
+
l && _utils.isArray(l) ? r(l) : e[i].indexOf(a) > -1 && n.push(e);
|
|
11
|
+
}));
|
|
12
|
+
}(r || []), n;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
function arrayTreeFilter(r, e, i) {
|
|
18
16
|
(i = i || {}).childrenKeyName = i.childrenKeyName || "children";
|
|
19
|
-
var
|
|
20
|
-
a = [],
|
|
21
|
-
n = 0;
|
|
17
|
+
var a = r || [], t = [], n = 0;
|
|
22
18
|
do {
|
|
23
|
-
var l =
|
|
24
|
-
return e(r, n)
|
|
25
|
-
})[0]
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
var l = a.filter((function(r) {
|
|
20
|
+
return e(r, n);
|
|
21
|
+
}))[0];
|
|
22
|
+
if (!l) break;
|
|
23
|
+
t.push(l), a = l[i.childrenKeyName] || [], n += 1;
|
|
24
|
+
} while (a.length > 0);
|
|
25
|
+
return t;
|
|
28
26
|
}
|
|
29
|
-
|
|
27
|
+
|
|
28
|
+
module.exports = arrayFilter, module.exports.arrayTreeFilter = arrayTreeFilter;
|
package/lib/arrayUtils.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
var deepCopy = require("./_deepCopy");
|
|
4
|
+
|
|
3
5
|
module.exports = {
|
|
4
6
|
arrayIntersection: function() {
|
|
5
|
-
if (
|
|
7
|
+
if (arguments.length > 0) {
|
|
6
8
|
for (var r = deepCopy(arguments[0]), e = 1; e < arguments.length; e++) {
|
|
7
9
|
var t = arguments[e];
|
|
8
|
-
Array.isArray(t) || console.error(t + "不是数组,不能求交集"), r = r.filter(function(r, e) {
|
|
9
|
-
return
|
|
10
|
-
})
|
|
10
|
+
Array.isArray(t) || console.error(t + "不是数组,不能求交集"), r = r.filter((function(r, e) {
|
|
11
|
+
return t.indexOf(r) >= 0;
|
|
12
|
+
}));
|
|
11
13
|
}
|
|
12
|
-
return r
|
|
14
|
+
return r;
|
|
13
15
|
}
|
|
14
|
-
return []
|
|
16
|
+
return [];
|
|
15
17
|
},
|
|
16
18
|
arrayToObject: function(r, e) {
|
|
17
19
|
for (var t = e && e.plainObjects ? Object.create(null) : {}, n = 0; n < r.length; ++n) void 0 !== r[n] && (t[n] = r[n]);
|
|
18
|
-
return t
|
|
20
|
+
return t;
|
|
19
21
|
}
|
|
20
|
-
};
|
|
22
|
+
};
|
package/lib/browser/Cookie.js
CHANGED
|
@@ -2,61 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
function extend() {
|
|
4
4
|
for (var e = 0, t = {}; e < arguments.length; e++) {
|
|
5
|
-
var n
|
|
6
|
-
for (
|
|
5
|
+
var n = arguments[e];
|
|
6
|
+
for (var r in n) t[r] = n[r];
|
|
7
7
|
}
|
|
8
|
-
return t
|
|
8
|
+
return t;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function decode(e) {
|
|
12
|
-
return e.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent)
|
|
12
|
+
return e.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function init(
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function n(e, t, n) {
|
|
15
|
+
function init(e) {
|
|
16
|
+
function t() {}
|
|
17
|
+
function n(t, n, r) {
|
|
19
18
|
if ("undefined" != typeof document) {
|
|
20
|
-
"number" == typeof(
|
|
19
|
+
"number" == typeof (r = extend({
|
|
21
20
|
path: "/"
|
|
22
|
-
}, api.defaults,
|
|
21
|
+
}, api.defaults, r)).expires && (r.expires = new Date(1 * new Date + 864e5 * r.expires)),
|
|
22
|
+
r.expires = r.expires ? r.expires.toUTCString() : "";
|
|
23
23
|
try {
|
|
24
|
-
var
|
|
25
|
-
/^[\{\[]/.test(
|
|
24
|
+
var o = JSON.stringify(n);
|
|
25
|
+
/^[\{\[]/.test(o) && (n = o);
|
|
26
26
|
} catch (e) {}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
n = e.write ? e.write(n, t) : encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent),
|
|
28
|
+
t = encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
|
|
29
|
+
var i = "";
|
|
30
|
+
for (var c in r) r[c] && (i += "; " + c, !0 !== r[c] && (i += "=" + r[c].split(";")[0]));
|
|
31
|
+
return document.cookie = t + "=" + n + i;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
function t(e, t) {
|
|
34
|
+
function r(t, n) {
|
|
35
35
|
if ("undefined" != typeof document) {
|
|
36
|
-
for (var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
t || '"' !== c.charAt(0) || (c = c.slice(1, -1));
|
|
36
|
+
for (var r = {}, o = document.cookie ? document.cookie.split("; ") : [], i = 0; i < o.length; i++) {
|
|
37
|
+
var c = o[i].split("="), d = c.slice(1).join("=");
|
|
38
|
+
n || '"' !== d.charAt(0) || (d = d.slice(1, -1));
|
|
40
39
|
try {
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
c = JSON.parse(c)
|
|
40
|
+
var u = decode(c[0]);
|
|
41
|
+
if (d = (e.read || e)(d, u) || decode(d), n) try {
|
|
42
|
+
d = JSON.parse(d);
|
|
45
43
|
} catch (e) {}
|
|
46
|
-
if (
|
|
44
|
+
if (r[u] = d, t === u) break;
|
|
47
45
|
} catch (e) {}
|
|
48
46
|
}
|
|
49
|
-
return
|
|
47
|
+
return t ? r[t] : r;
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
return
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
return
|
|
56
|
-
},
|
|
50
|
+
return t.set = n, t.get = function(e) {
|
|
51
|
+
return r(e, !1);
|
|
52
|
+
}, t.getJSON = function(e) {
|
|
53
|
+
return r(e, !0);
|
|
54
|
+
}, t.remove = function(e, t) {
|
|
57
55
|
n(e, "", extend(t, {
|
|
58
56
|
expires: -1
|
|
59
|
-
}))
|
|
60
|
-
},
|
|
57
|
+
}));
|
|
58
|
+
}, t.defaults = {}, t.withConverter = init, t;
|
|
61
59
|
}
|
|
62
|
-
|
|
60
|
+
|
|
61
|
+
module.exports = init((function() {}));
|
package/lib/browser/indexDB.js
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: !0
|
|
5
7
|
}), exports.default = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), InvalidStorageDB = function() {
|
|
10
|
+
function e() {
|
|
11
|
+
(0, _classCallCheck2.default)(this, e);
|
|
12
|
+
}
|
|
13
|
+
return (0, _createClass2.default)(e, [ {
|
|
14
|
+
key: "init",
|
|
15
|
+
value: function() {}
|
|
16
|
+
}, {
|
|
17
|
+
key: "get",
|
|
18
|
+
value: function() {}
|
|
19
|
+
}, {
|
|
20
|
+
key: "set",
|
|
21
|
+
value: function() {}
|
|
22
|
+
}, {
|
|
23
|
+
key: "clear",
|
|
24
|
+
value: function() {}
|
|
25
|
+
} ]), e;
|
|
26
|
+
}(), StorageDB = function() {
|
|
27
|
+
function e(t) {
|
|
28
|
+
(0, _classCallCheck2.default)(this, e);
|
|
29
|
+
var a = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
30
|
+
if (void 0 === a) return console.warn("Storage: IndexedDB not available."), new InvalidStorageDB;
|
|
31
|
+
this._name = t.name || "amostool-db", this.version = t.version || 1, this.storeName = t.storeName || "item",
|
|
32
|
+
this.database, this.indexedDB = a, this.performance = window.performance || {
|
|
33
|
+
now: function() {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return (0, _createClass2.default)(e, [ {
|
|
37
|
+
key: "init",
|
|
38
|
+
value: function(e) {
|
|
39
|
+
var t = this, a = t.storeName, n = t.indexedDB.open(t._name, t.version);
|
|
40
|
+
n.onupgradeneeded = function(e) {
|
|
41
|
+
var t = e.target.result;
|
|
42
|
+
!1 === t.objectStoreNames.contains(a) && t.createObjectStore(a);
|
|
43
|
+
}, n.onsuccess = function(a) {
|
|
44
|
+
t.database = a.target.result, e && e();
|
|
45
|
+
}, n.onerror = function(e) {
|
|
46
|
+
console.error("IndexedDB", e);
|
|
47
|
+
};
|
|
11
48
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
key: "set",
|
|
20
|
-
value: function() {}
|
|
21
|
-
}, {
|
|
22
|
-
key: "clear",
|
|
23
|
-
value: function() {}
|
|
24
|
-
}]), e
|
|
25
|
-
}(),
|
|
26
|
-
StorageDB = function() {
|
|
27
|
-
function a(e) {
|
|
28
|
-
(0, _classCallCheck2.default)(this, a);
|
|
29
|
-
var t = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
30
|
-
if (void 0 === t) return console.warn("Storage: IndexedDB not available."), new InvalidStorageDB;
|
|
31
|
-
this._name = e.name || "amostool-db", this.version = e.version || 1, this.storeName = e.storeName || "item", this.database, this.indexedDB = t, this.performance = window.performance || {
|
|
32
|
-
now: function() {}
|
|
33
|
-
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "get",
|
|
51
|
+
value: function(e) {
|
|
52
|
+
var t = this.storeName;
|
|
53
|
+
this.database.transaction([ t ], "readwrite").objectStore(t).get(0).onsuccess = function(t) {
|
|
54
|
+
e && e(t.target.result);
|
|
55
|
+
};
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var e = this.storeName;
|
|
54
|
-
this.database.transaction([e], "readwrite").objectStore(e).get(0).onsuccess = function(e) {
|
|
55
|
-
t && t(e.target.result)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "set",
|
|
60
|
-
value: function(e, t) {
|
|
61
|
-
var a = this,
|
|
62
|
-
n = a.performance.now(),
|
|
63
|
-
o = a.storeName;
|
|
64
|
-
a.database.transaction([o], "readwrite").objectStore(o).put(e, 0).onsuccess = function(e) {
|
|
65
|
-
console.log("[".concat(/\d\d\:\d\d\:\d\d/.exec(new Date)[0], "]"), "Saved item to IndexedDB. ".concat((a.performance.now() - n).toFixed(2), "ms")), t && t(e.target.result)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "clear",
|
|
70
|
-
value: function() {
|
|
71
|
-
var e, t = this;
|
|
72
|
-
void 0 !== t.database && (e = t.storeName, t.database.transaction([e], "readwrite").objectStore(e).clear().onsuccess = function(e) {
|
|
73
|
-
console.log("[".concat(/\d\d\:\d\d\:\d\d/.exec(new Date)[0], "]"), "Cleared IndexedDB.")
|
|
74
|
-
})
|
|
57
|
+
}, {
|
|
58
|
+
key: "set",
|
|
59
|
+
value: function(e, t) {
|
|
60
|
+
var a = this, n = a.performance.now(), r = a.storeName;
|
|
61
|
+
a.database.transaction([ r ], "readwrite").objectStore(r).put(e, 0).onsuccess = function(e) {
|
|
62
|
+
console.log("[".concat(/\d\d\:\d\d\:\d\d/.exec(new Date)[0], "]"), "Saved item to IndexedDB. ".concat((a.performance.now() - n).toFixed(2), "ms")),
|
|
63
|
+
t && t(e.target.result);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "clear",
|
|
68
|
+
value: function() {
|
|
69
|
+
var e = this;
|
|
70
|
+
if (void 0 !== e.database) {
|
|
71
|
+
var t = e.storeName;
|
|
72
|
+
e.database.transaction([ t ], "readwrite").objectStore(t).clear().onsuccess = function(e) {
|
|
73
|
+
console.log("[".concat(/\d\d\:\d\d\:\d\d/.exec(new Date)[0], "]"), "Cleared IndexedDB.");
|
|
74
|
+
};
|
|
75
75
|
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
}
|
|
77
|
+
} ]), e;
|
|
78
|
+
}(), _default = StorageDB;
|
|
79
|
+
|
|
80
|
+
exports.default = _default;
|