util-helpers 4.20.1 → 4.20.2
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/util-helpers.js +34 -30
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/ajax.js +4 -2
- package/esm/calculateCursorPosition.js +2 -2
- package/esm/download.js +3 -2
- package/esm/filterTree.js +3 -3
- package/esm/findTreeNode.js +3 -3
- package/esm/findTreeNodes.js +3 -3
- package/esm/findTreeSelect.js +3 -3
- package/esm/index.js +1 -1
- package/esm/listToTree.js +2 -2
- package/esm/loadImage.js +4 -3
- package/esm/loadImageWithBlob.js +4 -3
- package/esm/loadScript.js +2 -1
- package/esm/transformFieldNames.js +5 -4
- package/esm/treeToList.js +3 -3
- package/esm/utils/native.js +5 -0
- package/lib/VERSION.js +1 -1
- package/lib/ajax.js +4 -2
- package/lib/calculateCursorPosition.js +1 -1
- package/lib/download.js +3 -2
- package/lib/filterTree.js +2 -2
- package/lib/findTreeNode.js +2 -2
- package/lib/findTreeNodes.js +2 -2
- package/lib/findTreeSelect.js +2 -2
- package/lib/index.js +1 -1
- package/lib/listToTree.js +1 -1
- package/lib/loadImage.js +4 -3
- package/lib/loadImageWithBlob.js +4 -3
- package/lib/loadScript.js +2 -1
- package/lib/transformFieldNames.js +4 -3
- package/lib/treeToList.js +2 -2
- package/lib/utils/native.js +5 -0
- package/package.json +2 -2
- package/types/utils/native.d.ts +6 -0
package/esm/VERSION.js
CHANGED
package/esm/ajax.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { objectKeys } from './utils/native.js';
|
|
2
|
+
|
|
1
3
|
function ajax(url, options) {
|
|
2
4
|
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
3
5
|
return new Promise(function (resolve, reject) {
|
|
@@ -14,7 +16,7 @@ function ajax(url, options) {
|
|
|
14
16
|
xhr.responseType = responseType;
|
|
15
17
|
}
|
|
16
18
|
if (typeof headers === 'object') {
|
|
17
|
-
|
|
19
|
+
objectKeys(headers).map(function (item) {
|
|
18
20
|
xhr.setRequestHeader(item, headers[item]);
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -39,7 +41,7 @@ function ajax(url, options) {
|
|
|
39
41
|
load: wrapSuccess(onLoad),
|
|
40
42
|
loadend: onLoadEnd
|
|
41
43
|
};
|
|
42
|
-
var eventKeys =
|
|
44
|
+
var eventKeys = objectKeys(events);
|
|
43
45
|
eventKeys.map(function (item) {
|
|
44
46
|
var func = events[item];
|
|
45
47
|
if (func) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { toString } from 'ut2';
|
|
1
|
+
import { toString, isArray } from 'ut2';
|
|
2
2
|
|
|
3
3
|
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, options) {
|
|
4
4
|
if (options === void 0) { options = {}; }
|
|
5
5
|
var _a = options.placeholderChar, placeholderChar = _a === void 0 ? ' ' : _a, _b = options.maskReg, maskReg = _b === void 0 ? /\D/g : _b, type = options.type;
|
|
6
6
|
var realCtrlValue = toString(prevCtrlValue);
|
|
7
7
|
var realRawValue = toString(rawValue);
|
|
8
|
-
var placeholderChars =
|
|
8
|
+
var placeholderChars = isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
9
9
|
var editLength = realRawValue.length - realCtrlValue.length;
|
|
10
10
|
var isAddition = editLength > 0;
|
|
11
11
|
var pos = prevPos;
|
package/esm/download.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isBlob, isPromiseLike } from 'ut2';
|
|
|
3
3
|
import dataURLToBlob from './dataURLToBlob.js';
|
|
4
4
|
import isUrl from './isUrl.js';
|
|
5
5
|
import ajax from './ajax.js';
|
|
6
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
6
7
|
|
|
7
8
|
function saver(blobUrl, fileName) {
|
|
8
9
|
if (fileName === void 0) { fileName = ''; }
|
|
@@ -76,9 +77,9 @@ function download(data, options) {
|
|
|
76
77
|
navigator.msSaveBlob(payload, fileName || 'download');
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
|
-
url =
|
|
80
|
+
url = createObjectURL(payload);
|
|
80
81
|
saver(url, fileName);
|
|
81
|
-
|
|
82
|
+
revokeObjectURL(url);
|
|
82
83
|
}
|
|
83
84
|
return [2, Promise.resolve()];
|
|
84
85
|
}
|
package/esm/filterTree.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
5
5
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
6
6
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
7
7
|
var result = [];
|
|
8
|
-
if (!
|
|
8
|
+
if (!isArray(tree)) {
|
|
9
9
|
return result;
|
|
10
10
|
}
|
|
11
11
|
tree.forEach(function (item) {
|
|
@@ -16,7 +16,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
16
16
|
if (predicate(newItem)) {
|
|
17
17
|
if (isObject(newItem)) {
|
|
18
18
|
var childs = newItem[childrenField];
|
|
19
|
-
if (
|
|
19
|
+
if (isArray(childs) && childs.length > 0) {
|
|
20
20
|
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
21
21
|
}
|
|
22
22
|
}
|
package/esm/findTreeNode.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function findTreeNode(tree, predicate, childrenField) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
7
|
var stack = [];
|
|
8
8
|
var node;
|
|
9
|
-
if (!
|
|
9
|
+
if (!isArray(tree)) {
|
|
10
10
|
return node;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -21,7 +21,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
21
21
|
}
|
|
22
22
|
if (isObject(temp)) {
|
|
23
23
|
var childs = temp[childrenField];
|
|
24
|
-
if (
|
|
24
|
+
if (isArray(childs) && childs.length > 0) {
|
|
25
25
|
childs.forEach(function (c) {
|
|
26
26
|
stack.push(c);
|
|
27
27
|
});
|
package/esm/findTreeNodes.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function findTreeNodes(tree, predicate, childrenField) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
7
|
var stack = [];
|
|
8
8
|
var nodes = [];
|
|
9
|
-
if (!
|
|
9
|
+
if (!isArray(tree)) {
|
|
10
10
|
return nodes;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -20,7 +20,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
20
20
|
}
|
|
21
21
|
if (isObject(temp)) {
|
|
22
22
|
var childs = temp[childrenField];
|
|
23
|
-
if (
|
|
23
|
+
if (isArray(childs) && childs.length > 0) {
|
|
24
24
|
childs.forEach(function (c) {
|
|
25
25
|
stack.push(c);
|
|
26
26
|
});
|
package/esm/findTreeSelect.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (path === void 0) { path = []; }
|
|
7
|
-
if (!
|
|
7
|
+
if (!isArray(tree)) {
|
|
8
8
|
return [];
|
|
9
9
|
}
|
|
10
10
|
try {
|
|
@@ -16,7 +16,7 @@ function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
|
16
16
|
}
|
|
17
17
|
if (isObject(item)) {
|
|
18
18
|
var childs = item[childrenField];
|
|
19
|
-
if (
|
|
19
|
+
if (isArray(childs) && childs.length > 0) {
|
|
20
20
|
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
21
21
|
if (findChildren.length > 0) {
|
|
22
22
|
return findChildren;
|
package/esm/index.js
CHANGED
package/esm/listToTree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function processEmptyChildren(arr, options) {
|
|
5
5
|
var _a = options.childrenField, childrenField = _a === void 0 ? 'children' : _a, _b = options.emptyChildrenValue, emptyChildrenValue = _b === void 0 ? 'none' : _b;
|
|
@@ -22,7 +22,7 @@ function listToTree(list, options) {
|
|
|
22
22
|
var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
|
|
23
23
|
var tree = [];
|
|
24
24
|
var record = {};
|
|
25
|
-
if (!
|
|
25
|
+
if (!isArray(list)) {
|
|
26
26
|
return tree;
|
|
27
27
|
}
|
|
28
28
|
list.forEach(function (item) {
|
package/esm/loadImage.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBlob } from 'ut2';
|
|
2
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
2
3
|
|
|
3
4
|
var cacheImage;
|
|
4
5
|
var cacheResult;
|
|
@@ -10,14 +11,14 @@ function loadImage(img, useCache) {
|
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
12
13
|
var imgIsBlob_1 = isBlob(img);
|
|
13
|
-
var url_1 = imgIsBlob_1 ?
|
|
14
|
+
var url_1 = imgIsBlob_1 ? createObjectURL(img) : img;
|
|
14
15
|
var image_1 = new Image();
|
|
15
16
|
if (!imgIsBlob_1) {
|
|
16
17
|
image_1.crossOrigin = 'anonymous';
|
|
17
18
|
}
|
|
18
19
|
image_1.onload = function () {
|
|
19
20
|
if (imgIsBlob_1) {
|
|
20
|
-
|
|
21
|
+
revokeObjectURL(url_1);
|
|
21
22
|
}
|
|
22
23
|
if (useCache) {
|
|
23
24
|
cacheImage = img;
|
|
@@ -27,7 +28,7 @@ function loadImage(img, useCache) {
|
|
|
27
28
|
};
|
|
28
29
|
image_1.onerror = function (err) {
|
|
29
30
|
if (imgIsBlob_1) {
|
|
30
|
-
|
|
31
|
+
revokeObjectURL(url_1);
|
|
31
32
|
}
|
|
32
33
|
console.error("[loadImage] The image load failed, '".concat(img, "'."));
|
|
33
34
|
reject(err);
|
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBlob } from 'ut2';
|
|
2
2
|
import ajax from './ajax.js';
|
|
3
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
3
4
|
|
|
4
5
|
var SuccessResponseStatus = [200, 304];
|
|
5
6
|
function getBlob(img) {
|
|
@@ -33,10 +34,10 @@ function loadImageWithBlob(img, useCache) {
|
|
|
33
34
|
else {
|
|
34
35
|
getBlob(img)
|
|
35
36
|
.then(function (blob) {
|
|
36
|
-
var url =
|
|
37
|
+
var url = createObjectURL(blob);
|
|
37
38
|
var image = new Image();
|
|
38
39
|
image.onload = function () {
|
|
39
|
-
|
|
40
|
+
revokeObjectURL(url);
|
|
40
41
|
var result = { blob: blob, image: image };
|
|
41
42
|
if (useCache) {
|
|
42
43
|
cacheImage = img;
|
|
@@ -45,7 +46,7 @@ function loadImageWithBlob(img, useCache) {
|
|
|
45
46
|
resolve(result);
|
|
46
47
|
};
|
|
47
48
|
image.onerror = function (err) {
|
|
48
|
-
|
|
49
|
+
revokeObjectURL(url);
|
|
49
50
|
console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
|
|
50
51
|
reject(err);
|
|
51
52
|
};
|
package/esm/loadScript.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import { objectKeys } from './utils/native.js';
|
|
2
3
|
|
|
3
4
|
function loadScript(src, options) {
|
|
4
5
|
return new Promise(function (resolve, reject) {
|
|
@@ -13,7 +14,7 @@ function loadScript(src, options) {
|
|
|
13
14
|
script[key] = props[key];
|
|
14
15
|
}
|
|
15
16
|
if (typeof attrs === 'object') {
|
|
16
|
-
|
|
17
|
+
objectKeys(attrs).forEach(function (key) {
|
|
17
18
|
script.setAttribute(key, attrs[key]);
|
|
18
19
|
});
|
|
19
20
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
|
+
import { objectKeys } from './utils/native.js';
|
|
3
4
|
|
|
4
5
|
function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
5
6
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
6
|
-
if (!
|
|
7
|
+
if (!isArray(data)) {
|
|
7
8
|
return data;
|
|
8
9
|
}
|
|
9
10
|
if (data.length <= 0) {
|
|
@@ -16,10 +17,10 @@ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
|
16
17
|
}
|
|
17
18
|
var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
|
|
18
19
|
var delKeys = [];
|
|
19
|
-
if (childrenField &&
|
|
20
|
+
if (childrenField && isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
20
21
|
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
objectKeys(fieldNames).forEach(function (newKey) {
|
|
23
24
|
var oldKey = fieldNames[newKey];
|
|
24
25
|
if (oldKey in newItem) {
|
|
25
26
|
newItem[newKey] = newItem[oldKey];
|
package/esm/treeToList.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function treeToList(tree, childrenField) {
|
|
5
5
|
var list = [];
|
|
6
|
-
if (!
|
|
6
|
+
if (!isArray(tree)) {
|
|
7
7
|
return list;
|
|
8
8
|
}
|
|
9
9
|
function recusion(arr) {
|
|
@@ -12,7 +12,7 @@ function treeToList(tree, childrenField) {
|
|
|
12
12
|
var newItem = __assign({}, item);
|
|
13
13
|
list.push(newItem);
|
|
14
14
|
if (newItem[childrenField]) {
|
|
15
|
-
if (
|
|
15
|
+
if (isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
16
16
|
recusion(newItem[childrenField]);
|
|
17
17
|
}
|
|
18
18
|
delete newItem[childrenField];
|
package/lib/VERSION.js
CHANGED
package/lib/ajax.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var native = require('./utils/native.js');
|
|
4
|
+
|
|
3
5
|
function ajax(url, options) {
|
|
4
6
|
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
5
7
|
return new Promise(function (resolve, reject) {
|
|
@@ -16,7 +18,7 @@ function ajax(url, options) {
|
|
|
16
18
|
xhr.responseType = responseType;
|
|
17
19
|
}
|
|
18
20
|
if (typeof headers === 'object') {
|
|
19
|
-
|
|
21
|
+
native.objectKeys(headers).map(function (item) {
|
|
20
22
|
xhr.setRequestHeader(item, headers[item]);
|
|
21
23
|
});
|
|
22
24
|
}
|
|
@@ -41,7 +43,7 @@ function ajax(url, options) {
|
|
|
41
43
|
load: wrapSuccess(onLoad),
|
|
42
44
|
loadend: onLoadEnd
|
|
43
45
|
};
|
|
44
|
-
var eventKeys =
|
|
46
|
+
var eventKeys = native.objectKeys(events);
|
|
45
47
|
eventKeys.map(function (item) {
|
|
46
48
|
var func = events[item];
|
|
47
49
|
if (func) {
|
|
@@ -7,7 +7,7 @@ function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, op
|
|
|
7
7
|
var _a = options.placeholderChar, placeholderChar = _a === void 0 ? ' ' : _a, _b = options.maskReg, maskReg = _b === void 0 ? /\D/g : _b, type = options.type;
|
|
8
8
|
var realCtrlValue = ut2.toString(prevCtrlValue);
|
|
9
9
|
var realRawValue = ut2.toString(rawValue);
|
|
10
|
-
var placeholderChars =
|
|
10
|
+
var placeholderChars = ut2.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
11
11
|
var editLength = realRawValue.length - realCtrlValue.length;
|
|
12
12
|
var isAddition = editLength > 0;
|
|
13
13
|
var pos = prevPos;
|
package/lib/download.js
CHANGED
|
@@ -5,6 +5,7 @@ var ut2 = require('ut2');
|
|
|
5
5
|
var dataURLToBlob = require('./dataURLToBlob.js');
|
|
6
6
|
var isUrl = require('./isUrl.js');
|
|
7
7
|
var ajax = require('./ajax.js');
|
|
8
|
+
var native = require('./utils/native.js');
|
|
8
9
|
|
|
9
10
|
function saver(blobUrl, fileName) {
|
|
10
11
|
if (fileName === void 0) { fileName = ''; }
|
|
@@ -78,9 +79,9 @@ function download(data, options) {
|
|
|
78
79
|
navigator.msSaveBlob(payload, fileName || 'download');
|
|
79
80
|
}
|
|
80
81
|
else {
|
|
81
|
-
url =
|
|
82
|
+
url = native.createObjectURL(payload);
|
|
82
83
|
saver(url, fileName);
|
|
83
|
-
|
|
84
|
+
native.revokeObjectURL(url);
|
|
84
85
|
}
|
|
85
86
|
return [2, Promise.resolve()];
|
|
86
87
|
}
|
package/lib/filterTree.js
CHANGED
|
@@ -7,7 +7,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
7
7
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
8
8
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
9
9
|
var result = [];
|
|
10
|
-
if (!
|
|
10
|
+
if (!ut2.isArray(tree)) {
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
13
|
tree.forEach(function (item) {
|
|
@@ -18,7 +18,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
18
18
|
if (predicate(newItem)) {
|
|
19
19
|
if (ut2.isObject(newItem)) {
|
|
20
20
|
var childs = newItem[childrenField];
|
|
21
|
-
if (
|
|
21
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
22
22
|
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/lib/findTreeNode.js
CHANGED
|
@@ -8,7 +8,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
8
8
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
9
9
|
var stack = [];
|
|
10
10
|
var node;
|
|
11
|
-
if (!
|
|
11
|
+
if (!ut2.isArray(tree)) {
|
|
12
12
|
return node;
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
@@ -23,7 +23,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
23
23
|
}
|
|
24
24
|
if (ut2.isObject(temp)) {
|
|
25
25
|
var childs = temp[childrenField];
|
|
26
|
-
if (
|
|
26
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
27
27
|
childs.forEach(function (c) {
|
|
28
28
|
stack.push(c);
|
|
29
29
|
});
|
package/lib/findTreeNodes.js
CHANGED
|
@@ -8,7 +8,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
8
8
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
9
9
|
var stack = [];
|
|
10
10
|
var nodes = [];
|
|
11
|
-
if (!
|
|
11
|
+
if (!ut2.isArray(tree)) {
|
|
12
12
|
return nodes;
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
@@ -22,7 +22,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
22
22
|
}
|
|
23
23
|
if (ut2.isObject(temp)) {
|
|
24
24
|
var childs = temp[childrenField];
|
|
25
|
-
if (
|
|
25
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
26
26
|
childs.forEach(function (c) {
|
|
27
27
|
stack.push(c);
|
|
28
28
|
});
|
package/lib/findTreeSelect.js
CHANGED
|
@@ -6,7 +6,7 @@ var ut2 = require('ut2');
|
|
|
6
6
|
function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
7
7
|
var e_1, _a;
|
|
8
8
|
if (path === void 0) { path = []; }
|
|
9
|
-
if (!
|
|
9
|
+
if (!ut2.isArray(tree)) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -18,7 +18,7 @@ function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
|
18
18
|
}
|
|
19
19
|
if (ut2.isObject(item)) {
|
|
20
20
|
var childs = item[childrenField];
|
|
21
|
-
if (
|
|
21
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
22
22
|
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
23
23
|
if (findChildren.length > 0) {
|
|
24
24
|
return findChildren;
|
package/lib/index.js
CHANGED
|
@@ -65,7 +65,7 @@ var findTreeSelect = require('./findTreeSelect.js');
|
|
|
65
65
|
var config = require('./utils/config.js');
|
|
66
66
|
var VERSION = require('./VERSION.js');
|
|
67
67
|
|
|
68
|
-
exports.version = "4.20.
|
|
68
|
+
exports.version = "4.20.2";
|
|
69
69
|
|
|
70
70
|
exports.isMobile = isMobile;
|
|
71
71
|
exports.isTelephone = isTelephone;
|
package/lib/listToTree.js
CHANGED
|
@@ -24,7 +24,7 @@ function listToTree(list, options) {
|
|
|
24
24
|
var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
|
|
25
25
|
var tree = [];
|
|
26
26
|
var record = {};
|
|
27
|
-
if (!
|
|
27
|
+
if (!ut2.isArray(list)) {
|
|
28
28
|
return tree;
|
|
29
29
|
}
|
|
30
30
|
list.forEach(function (item) {
|
package/lib/loadImage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
|
+
var native = require('./utils/native.js');
|
|
4
5
|
|
|
5
6
|
var cacheImage;
|
|
6
7
|
var cacheResult;
|
|
@@ -12,14 +13,14 @@ function loadImage(img, useCache) {
|
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
15
|
var imgIsBlob_1 = ut2.isBlob(img);
|
|
15
|
-
var url_1 = imgIsBlob_1 ?
|
|
16
|
+
var url_1 = imgIsBlob_1 ? native.createObjectURL(img) : img;
|
|
16
17
|
var image_1 = new Image();
|
|
17
18
|
if (!imgIsBlob_1) {
|
|
18
19
|
image_1.crossOrigin = 'anonymous';
|
|
19
20
|
}
|
|
20
21
|
image_1.onload = function () {
|
|
21
22
|
if (imgIsBlob_1) {
|
|
22
|
-
|
|
23
|
+
native.revokeObjectURL(url_1);
|
|
23
24
|
}
|
|
24
25
|
if (useCache) {
|
|
25
26
|
cacheImage = img;
|
|
@@ -29,7 +30,7 @@ function loadImage(img, useCache) {
|
|
|
29
30
|
};
|
|
30
31
|
image_1.onerror = function (err) {
|
|
31
32
|
if (imgIsBlob_1) {
|
|
32
|
-
|
|
33
|
+
native.revokeObjectURL(url_1);
|
|
33
34
|
}
|
|
34
35
|
console.error("[loadImage] The image load failed, '".concat(img, "'."));
|
|
35
36
|
reject(err);
|
package/lib/loadImageWithBlob.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
var ajax = require('./ajax.js');
|
|
5
|
+
var native = require('./utils/native.js');
|
|
5
6
|
|
|
6
7
|
var SuccessResponseStatus = [200, 304];
|
|
7
8
|
function getBlob(img) {
|
|
@@ -35,10 +36,10 @@ function loadImageWithBlob(img, useCache) {
|
|
|
35
36
|
else {
|
|
36
37
|
getBlob(img)
|
|
37
38
|
.then(function (blob) {
|
|
38
|
-
var url =
|
|
39
|
+
var url = native.createObjectURL(blob);
|
|
39
40
|
var image = new Image();
|
|
40
41
|
image.onload = function () {
|
|
41
|
-
|
|
42
|
+
native.revokeObjectURL(url);
|
|
42
43
|
var result = { blob: blob, image: image };
|
|
43
44
|
if (useCache) {
|
|
44
45
|
cacheImage = img;
|
|
@@ -47,7 +48,7 @@ function loadImageWithBlob(img, useCache) {
|
|
|
47
48
|
resolve(result);
|
|
48
49
|
};
|
|
49
50
|
image.onerror = function (err) {
|
|
50
|
-
|
|
51
|
+
native.revokeObjectURL(url);
|
|
51
52
|
console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
|
|
52
53
|
reject(err);
|
|
53
54
|
};
|
package/lib/loadScript.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
|
+
var native = require('./utils/native.js');
|
|
4
5
|
|
|
5
6
|
function loadScript(src, options) {
|
|
6
7
|
return new Promise(function (resolve, reject) {
|
|
@@ -15,7 +16,7 @@ function loadScript(src, options) {
|
|
|
15
16
|
script[key] = props[key];
|
|
16
17
|
}
|
|
17
18
|
if (typeof attrs === 'object') {
|
|
18
|
-
|
|
19
|
+
native.objectKeys(attrs).forEach(function (key) {
|
|
19
20
|
script.setAttribute(key, attrs[key]);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var ut2 = require('ut2');
|
|
5
|
+
var native = require('./utils/native.js');
|
|
5
6
|
|
|
6
7
|
function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
7
8
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
8
|
-
if (!
|
|
9
|
+
if (!ut2.isArray(data)) {
|
|
9
10
|
return data;
|
|
10
11
|
}
|
|
11
12
|
if (data.length <= 0) {
|
|
@@ -18,10 +19,10 @@ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
|
18
19
|
}
|
|
19
20
|
var newItem = nodeAssign === 'spread' ? tslib.__assign({}, item) : item;
|
|
20
21
|
var delKeys = [];
|
|
21
|
-
if (childrenField &&
|
|
22
|
+
if (childrenField && ut2.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
22
23
|
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
native.objectKeys(fieldNames).forEach(function (newKey) {
|
|
25
26
|
var oldKey = fieldNames[newKey];
|
|
26
27
|
if (oldKey in newItem) {
|
|
27
28
|
newItem[newKey] = newItem[oldKey];
|
package/lib/treeToList.js
CHANGED
|
@@ -5,7 +5,7 @@ var ut2 = require('ut2');
|
|
|
5
5
|
|
|
6
6
|
function treeToList(tree, childrenField) {
|
|
7
7
|
var list = [];
|
|
8
|
-
if (!
|
|
8
|
+
if (!ut2.isArray(tree)) {
|
|
9
9
|
return list;
|
|
10
10
|
}
|
|
11
11
|
function recusion(arr) {
|
|
@@ -14,7 +14,7 @@ function treeToList(tree, childrenField) {
|
|
|
14
14
|
var newItem = tslib.__assign({}, item);
|
|
15
15
|
list.push(newItem);
|
|
16
16
|
if (newItem[childrenField]) {
|
|
17
|
-
if (
|
|
17
|
+
if (ut2.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
18
18
|
recusion(newItem[childrenField]);
|
|
19
19
|
}
|
|
20
20
|
delete newItem[childrenField];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.20.
|
|
3
|
+
"version": "4.20.2",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -94,6 +94,6 @@
|
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
96
|
"tslib": "^2.6.2",
|
|
97
|
-
"ut2": "^1.4.
|
|
97
|
+
"ut2": "^1.4.8"
|
|
98
98
|
}
|
|
99
99
|
}
|