amos-apptool 1.2.2 → 1.3.1

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/esm/equal.js ADDED
@@ -0,0 +1,36 @@
1
+ export const Equal = {
2
+ any(e, t) {
3
+ if (e === t) return !0;
4
+ if (Number.isNaN(e) && Number.isNaN(t)) return !0;
5
+ if ("number" == typeof e && "string" == typeof t || "string" == typeof e && "number" == typeof t) {
6
+ const r = Number(e), n = Number(t);
7
+ return !Number.isNaN(r) && !Number.isNaN(n) && r === n;
8
+ }
9
+ return "object" == typeof e && "object" == typeof t && null !== e && null !== t && this.obj(e, t);
10
+ },
11
+ single(e, t) {
12
+ const r = [ "string", "number" ];
13
+ if (!r.includes(typeof e) || !r.includes(typeof t)) return !1;
14
+ if (e === t) return !0;
15
+ if (typeof e != typeof t) {
16
+ const r = Number(e), n = Number(t);
17
+ return !Number.isNaN(r) && !Number.isNaN(n) && r === n;
18
+ }
19
+ return !1;
20
+ },
21
+ string(e, t, r = {
22
+ ignoreCase: !1,
23
+ trim: !1
24
+ }) {
25
+ if ("string" != typeof e || "string" != typeof t) return !1;
26
+ let n = e, o = t;
27
+ return r.trim && (n = n.trim(), o = o.trim()), r.ignoreCase && (n = n.toLowerCase(),
28
+ o = o.toLowerCase()), n === o;
29
+ },
30
+ obj(e, t, r) {
31
+ if (null === e || null === t || "object" != typeof e || "object" != typeof t) return e === t;
32
+ const n = r || [ ...new Set([ ...Object.keys(e), ...Object.keys(t) ]) ];
33
+ for (const r of n) if (!this.any(e[r], t[r])) return !1;
34
+ return !0;
35
+ }
36
+ };
package/esm/index.js CHANGED
@@ -48,6 +48,10 @@ export { default as strUtils } from "./strUtils";
48
48
 
49
49
  export { default as utils } from "./utils";
50
50
 
51
+ export * from "./search";
52
+
53
+ export * from "./equal";
54
+
51
55
  export { default as addition } from "./math/addition";
52
56
 
53
57
  export { default as amountCase } from "./math/amountCase";
package/esm/search.js ADDED
@@ -0,0 +1,108 @@
1
+ import { deepCopy } from "./_deepCopy";
2
+
3
+ export function recursive(t, h = "children") {
4
+ return new class {
5
+ constructor(t, h) {
6
+ this.list = deepCopy(t || []), this.childName = h;
7
+ }
8
+ getLeafNodes() {
9
+ const t = [], h = i => {
10
+ if (i[this.childName] && i[this.childName].length > 0) for (const t of i[this.childName]) h(t); else t.push(i);
11
+ };
12
+ return (this.list || []).map(t => h(t)), t;
13
+ }
14
+ some(t) {
15
+ const h = i => i.some((i, e) => {
16
+ const s = t(i, e);
17
+ return s || !!(i[this.childName] && i[this.childName].length > 0) && h(i[this.childName]);
18
+ });
19
+ return h(this.list);
20
+ }
21
+ find(t) {
22
+ let h = null;
23
+ const i = e => e.find((e, s) => {
24
+ const l = t(e, s);
25
+ return l ? (h = e, l) : !!(e[this.childName] && e[this.childName].length > 0) && i(e[this.childName]);
26
+ });
27
+ return i(this.list), h;
28
+ }
29
+ findParent(t) {
30
+ let h = null;
31
+ const i = (e, s) => e.find((e, l) => {
32
+ const c = t(e, l, s);
33
+ return c ? (h = s, c) : !!(e[this.childName] && e[this.childName].length > 0) && i(e[this.childName], e);
34
+ });
35
+ return i(this.list, {}), h;
36
+ }
37
+ findPath(t) {
38
+ let h = [];
39
+ const i = e => e.some((e, s) => {
40
+ let l = !1;
41
+ return t(e, s) ? l = !0 : e[this.childName] && e[this.childName].length > 0 && (l = i(e[this.childName], e)),
42
+ l && (h = [ ...h, e ]), l;
43
+ });
44
+ return i(this.list), h;
45
+ }
46
+ getMaxLengthPaths() {
47
+ let t = [], h = [];
48
+ const i = (e, s) => e.forEach((e, s) => {
49
+ e[this.childName] && e[this.childName].length > 0 ? (h.push(e), i(e[this.childName], e)) : (h.push(e),
50
+ t.push(h), h = []);
51
+ });
52
+ return i(this.list), t.reduce((t, h) => t.length > h.length ? t : h, []);
53
+ }
54
+ getPaths(t) {
55
+ let h = [], i = [];
56
+ const e = (s, l) => s.forEach((s, l) => {
57
+ s[this.childName] && s[this.childName].length > 0 ? (i.push(s), e(s[this.childName], s)) : (i.push(s),
58
+ t ? t(s) && h.push(i) : h.push(i), i = []);
59
+ });
60
+ return e(this.list), h;
61
+ }
62
+ findIndex(t) {
63
+ let h = -1;
64
+ const i = (e, s) => e.find((e, l) => {
65
+ const c = t(e, l, s);
66
+ return c ? (h = l, c) : !!(e[this.childName] && e[this.childName].length > 0) && i(e[this.childName], e);
67
+ });
68
+ return i(this.list, {}), h;
69
+ }
70
+ filter(t) {
71
+ const h = (i, e) => i.filter((i, s) => {
72
+ i[this.childName] && i[this.childName].length > 0 && (i[this.childName] = h(i[this.childName], i));
73
+ return t(i, s, e);
74
+ });
75
+ return h(this.list, {});
76
+ }
77
+ flatFilter(t) {
78
+ const h = [], i = (e, s) => e.forEach((e, l) => {
79
+ t(e, l, s) && h.push(e), e[this.childName] && e[this.childName].length > 0 && i(e[this.childName], e);
80
+ });
81
+ return i(this.list, {}), h;
82
+ }
83
+ map(t) {
84
+ const h = (i, e) => i.map((i, s) => {
85
+ const l = t(i, s, e);
86
+ return l && (i = l), i[this.childName] && i[this.childName].length > 0 && (i[this.childName] = h(i[this.childName], i)),
87
+ i;
88
+ });
89
+ return h(this.list, {});
90
+ }
91
+ search(t) {
92
+ const h = (i, e) => i.filter((i, s) => {
93
+ let l = t(i, s, e), c = !1;
94
+ return l && l.length && (l[1] ? (l = !1, c = !0) : l = l[0]), l || (i[this.childName] && i[this.childName].length > 0 && (i[this.childName] = h(i[this.childName], i),
95
+ i[this.childName] && i[this.childName].length > 0 && (l = !0)), !!c || l);
96
+ });
97
+ return h(this.list, {});
98
+ }
99
+ forEach(t) {
100
+ const h = (i, e) => i.map((i, s) => {
101
+ const l = t(i, s, e);
102
+ return l && (i = l), i[this.childName] && i[this.childName].length > 0 && (i[this.childName] = h(i[this.childName], i)),
103
+ i;
104
+ });
105
+ return h(this.list, {});
106
+ }
107
+ }(t, h);
108
+ }
package/index.d.ts CHANGED
@@ -1612,3 +1612,202 @@ export {
1612
1612
  utils
1613
1613
  };
1614
1614
 
1615
+ // search
1616
+ /**
1617
+ * 递归遍历树形结构的类类型定义
1618
+ * @template T 树节点的类型
1619
+ */
1620
+ declare class RecursiveClass<T = Record<string, any>> {
1621
+ /** 原始树形列表数据 */
1622
+ list: T[];
1623
+ /** 子节点字段名 */
1624
+ childName: string;
1625
+
1626
+ /**
1627
+ * 构造函数
1628
+ * @param _list 树形结构列表
1629
+ * @param _childName 子节点字段名
1630
+ */
1631
+ constructor(_list: T[], _childName: string);
1632
+
1633
+ /**
1634
+ * 按顺序获取树的所有叶子节点
1635
+ * @returns 所有叶子节点组成的数组
1636
+ */
1637
+ getLeafNodes(): T[];
1638
+
1639
+ /**
1640
+ * 递归执行 some 逻辑(只要有一个节点满足条件就返回 true)
1641
+ * @param callback 回调函数,参数为当前节点、索引,返回布尔值
1642
+ * @returns 是否存在满足条件的节点
1643
+ */
1644
+ some(callback: (node: T, index: number) => boolean): boolean;
1645
+
1646
+ /**
1647
+ * 递归查找第一个满足条件的节点
1648
+ * @param callback 回调函数,参数为当前节点、索引,返回布尔值
1649
+ * @returns 满足条件的节点 | null
1650
+ */
1651
+ find(callback: (node: T, index: number) => boolean): T | null;
1652
+
1653
+ /**
1654
+ * 递归查找满足条件节点的父节点
1655
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回布尔值
1656
+ * @returns 父节点 | null
1657
+ */
1658
+ findParent(callback: (node: T, index: number, parent: T) => boolean): T | null;
1659
+
1660
+ /**
1661
+ * 递归查找满足条件节点的路径(从目标节点到根节点)
1662
+ * @param callback 回调函数,参数为当前节点、索引,返回布尔值
1663
+ * @returns 路径节点组成的数组
1664
+ */
1665
+ findPath(callback: (node: T, index: number) => boolean): T[];
1666
+
1667
+ /**
1668
+ * 获取树中最长路径的节点数组
1669
+ * @returns 最长路径的节点数组
1670
+ */
1671
+ getMaxLengthPaths(): T[];
1672
+
1673
+ /**
1674
+ * 获取树中所有路径(可通过回调筛选)
1675
+ * @param callback 可选回调函数,参数为叶子节点,返回布尔值,用于筛选路径
1676
+ * @returns 所有符合条件的路径数组
1677
+ */
1678
+ getPaths(callback?: (node: T) => boolean): T[][];
1679
+
1680
+ /**
1681
+ * 递归查找满足条件节点的索引
1682
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回布尔值
1683
+ * @returns 满足条件的节点索引(未找到返回 -1)
1684
+ */
1685
+ findIndex(callback: (node: T, index: number, parent: T) => boolean): number;
1686
+
1687
+ /**
1688
+ * 递归过滤树形结构(保留满足条件的节点及其父节点层级)
1689
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回布尔值
1690
+ * @returns 过滤后的树形结构
1691
+ */
1692
+ filter(callback: (node: T, index: number, parent: T) => boolean): T[];
1693
+
1694
+ /**
1695
+ * 扁平化过滤(返回所有满足条件的节点,不保留树形结构)
1696
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回布尔值
1697
+ * @returns 满足条件的所有节点数组
1698
+ */
1699
+ flatFilter(callback: (node: T, index: number, parent: T) => boolean): T[];
1700
+
1701
+ /**
1702
+ * 递归映射(遍历所有节点并支持修改节点,保留树形结构)
1703
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回修改后的节点或原节点
1704
+ * @returns 映射后的树形结构
1705
+ */
1706
+ map(callback: (node: T, index: number, parent: T) => T | void): T[];
1707
+
1708
+ /**
1709
+ * 递归搜索(支持复杂的搜索逻辑,返回匹配节点及其父层级)
1710
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回布尔值或 [boolean, boolean]
1711
+ * @returns 搜索后的树形结构
1712
+ */
1713
+ search(
1714
+ callback: (node: T, index: number, parent: T) => boolean | [boolean, boolean]
1715
+ ): T[];
1716
+
1717
+ /**
1718
+ * 递归遍历所有节点(支持修改节点,保留树形结构)
1719
+ * @param callback 回调函数,参数为当前节点、索引、父节点,返回修改后的节点或原节点
1720
+ * @returns 遍历后的树形结构
1721
+ */
1722
+ forEach(callback: (node: T, index: number, parent: T) => T | void): T[];
1723
+ }
1724
+
1725
+ /**
1726
+ * 用于遍历树形结构数据, 递归执行 `some/find/filter/map/search` 等操作
1727
+ * @template T 树节点的类型
1728
+ * @param list 树形结构列表
1729
+ * @param childName 子节点字段名(默认 'children')
1730
+ * @returns 递归操作的实例
1731
+ * @example
1732
+ * recursive([{name: 'ray', children: [ { name: 'dd' }, { name: 'mm'}, ...]}, { name: 'ilex' }]).find(d => d.name === 'mm');
1733
+ */
1734
+ export declare function recursive<T = Record<string, any>>(
1735
+ list: T[],
1736
+ childName?: string
1737
+ ): RecursiveClass<T>;
1738
+
1739
+ /**
1740
+ * 字符串比较的配置项类型
1741
+ */
1742
+ export interface StringCompareOptions {
1743
+ /** 是否忽略大小写,默认 false */
1744
+ ignoreCase?: boolean;
1745
+ /** 是否去除首尾空格,默认 false */
1746
+ trim?: boolean;
1747
+ }
1748
+
1749
+ /**
1750
+ * 等值比较工具核心对象类型
1751
+ */
1752
+ export interface EqualTool {
1753
+ /**
1754
+ * 通用等值比较(智能匹配任意类型)
1755
+ * @param a 第一个比较值
1756
+ * @param b 第二个比较值
1757
+ * @returns 两个值是否相等
1758
+ * @example
1759
+ * Equal.any(NaN, NaN); // true
1760
+ * Equal.any({ name: '123' }, { name: 123 }); // true
1761
+ */
1762
+ any<T = any>(a: T, b: T): boolean;
1763
+
1764
+ /**
1765
+ * 单一值比较(专注数字/文本)
1766
+ * @param a 数字或文本值
1767
+ * @param b 数字或文本值
1768
+ * @returns 两个值是否相等
1769
+ * @example
1770
+ * Equal.single(123, 123); // true
1771
+ * Equal.single(123, '123'); // true
1772
+ * Equal.single('abc', 'abc'); // true
1773
+ * Equal.single('123a', 123); // false
1774
+ */
1775
+ single(a: string | number, b: string | number): boolean;
1776
+
1777
+ /**
1778
+ * 纯字符串比较(支持扩展配置)
1779
+ * @param a 待比较的字符串
1780
+ * @param b 待比较的字符串
1781
+ * @param options 字符串比较配置项
1782
+ * @returns 两个字符串是否相等
1783
+ * @example
1784
+ * Equal.string(' Hello ', 'hello', { ignoreCase: true, trim: true }); // true
1785
+ * Equal.string('abc', 'ABC'); // false(默认不忽略大小写)
1786
+ */
1787
+ string(
1788
+ a: string,
1789
+ b: string,
1790
+ options?: StringCompareOptions
1791
+ ): boolean;
1792
+
1793
+ /**
1794
+ * 对象属性比较
1795
+ * @param a 第一个对象
1796
+ * @param b 第二个对象
1797
+ * @param props 指定要比较的属性列表(不传则比较全部自有属性)
1798
+ * @returns 对象的指定属性是否全部相等
1799
+ * @example
1800
+ * Equal.obj({ age: 18 }, { age: '18' }); // true
1801
+ * Equal.obj({ a: 1, b: 2 }, { a: 1, b: 3 }, ['a', 'b']); // false
1802
+ */
1803
+ obj<T extends Record<string, any>>(
1804
+ a: T,
1805
+ b: T,
1806
+ props?: (keyof T)[]
1807
+ ): boolean;
1808
+ }
1809
+
1810
+ /**
1811
+ * 等值比较工具实例
1812
+ */
1813
+ export const Equal: EqualTool;
package/lib/equal.js ADDED
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: !0
7
+ }), exports.Equal = void 0;
8
+
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")), _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
+
11
+ function _createForOfIteratorHelper(e, r) {
12
+ var t = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
13
+ if (!t) {
14
+ if (Array.isArray(e) || (t = _unsupportedIterableToArray(e)) || r && e && "number" == typeof e.length) {
15
+ t && (e = t);
16
+ var n = 0, o = function() {};
17
+ return {
18
+ s: o,
19
+ n: function() {
20
+ return n >= e.length ? {
21
+ done: !0
22
+ } : {
23
+ done: !1,
24
+ value: e[n++]
25
+ };
26
+ },
27
+ e: function(e) {
28
+ throw e;
29
+ },
30
+ f: o
31
+ };
32
+ }
33
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
34
+ }
35
+ var a, u = !0, i = !1;
36
+ return {
37
+ s: function() {
38
+ t = t.call(e);
39
+ },
40
+ n: function() {
41
+ var e = t.next();
42
+ return u = e.done, e;
43
+ },
44
+ e: function(e) {
45
+ i = !0, a = e;
46
+ },
47
+ f: function() {
48
+ try {
49
+ u || null == t.return || t.return();
50
+ } finally {
51
+ if (i) throw a;
52
+ }
53
+ }
54
+ };
55
+ }
56
+
57
+ function _unsupportedIterableToArray(e, r) {
58
+ if (e) {
59
+ if ("string" == typeof e) return _arrayLikeToArray(e, r);
60
+ var t = {}.toString.call(e).slice(8, -1);
61
+ return "Object" === t && e.constructor && (t = e.constructor.name), "Map" === t || "Set" === t ? Array.from(e) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(e, r) : void 0;
62
+ }
63
+ }
64
+
65
+ function _arrayLikeToArray(e, r) {
66
+ (null == r || r > e.length) && (r = e.length);
67
+ for (var t = 0, n = Array(r); t < r; t++) n[t] = e[t];
68
+ return n;
69
+ }
70
+
71
+ var Equal = exports.Equal = {
72
+ any: function(e, r) {
73
+ if (e === r) return !0;
74
+ if (Number.isNaN(e) && Number.isNaN(r)) return !0;
75
+ if ("number" == typeof e && "string" == typeof r || "string" == typeof e && "number" == typeof r) {
76
+ var t = Number(e), n = Number(r);
77
+ return !Number.isNaN(t) && !Number.isNaN(n) && t === n;
78
+ }
79
+ return "object" === (0, _typeof2.default)(e) && "object" === (0, _typeof2.default)(r) && null !== e && null !== r && this.obj(e, r);
80
+ },
81
+ single: function(e, r) {
82
+ var t = [ "string", "number" ];
83
+ if (!t.includes((0, _typeof2.default)(e)) || !t.includes((0, _typeof2.default)(r))) return !1;
84
+ if (e === r) return !0;
85
+ if ((0, _typeof2.default)(e) !== (0, _typeof2.default)(r)) {
86
+ var n = Number(e), o = Number(r);
87
+ return !Number.isNaN(n) && !Number.isNaN(o) && n === o;
88
+ }
89
+ return !1;
90
+ },
91
+ string: function(e, r) {
92
+ var t = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {
93
+ ignoreCase: !1,
94
+ trim: !1
95
+ };
96
+ if ("string" != typeof e || "string" != typeof r) return !1;
97
+ var n = e, o = r;
98
+ return t.trim && (n = n.trim(), o = o.trim()), t.ignoreCase && (n = n.toLowerCase(),
99
+ o = o.toLowerCase()), n === o;
100
+ },
101
+ obj: function(e, r, t) {
102
+ if (null === e || null === r || "object" !== (0, _typeof2.default)(e) || "object" !== (0,
103
+ _typeof2.default)(r)) return e === r;
104
+ var n, o = _createForOfIteratorHelper(t || (0, _toConsumableArray2.default)(new Set([].concat((0,
105
+ _toConsumableArray2.default)(Object.keys(e)), (0, _toConsumableArray2.default)(Object.keys(r))))));
106
+ try {
107
+ for (o.s(); !(n = o.n()).done; ) {
108
+ var a = n.value;
109
+ if (!this.any(e[a], r[a])) return !1;
110
+ }
111
+ } catch (e) {
112
+ o.e(e);
113
+ } finally {
114
+ o.f();
115
+ }
116
+ return !0;
117
+ }
118
+ };
package/lib/index.js CHANGED
@@ -242,7 +242,29 @@ Object.keys(_shallowEqual).forEach(function(e) {
242
242
  }));
243
243
  });
244
244
 
245
- var _strUtils = _interopRequireDefault(require("./strUtils")), _utils = _interopRequireDefault(require("./utils")), _addition = _interopRequireDefault(require("./math/addition")), _amountCase = _interopRequireDefault(require("./math/amountCase")), _coinFormat = _interopRequireDefault(require("./math/coinFormat")), _colorUtil = _interopRequireDefault(require("./math/colorUtil")), _dateTime = _interopRequireDefault(require("./math/dateTime")), _pwdStrength = _interopRequireDefault(require("./math/pwdStrength")), _randomColor = _interopRequireDefault(require("./math/randomColor")), _subtraction = _interopRequireDefault(require("./math/subtraction")), _mul = _interopRequireDefault(require("./math/mul")), _divide = _interopRequireDefault(require("./math/divide")), _calendarUtils = require("./math/calendarUtils");
245
+ var _strUtils = _interopRequireDefault(require("./strUtils")), _utils = _interopRequireDefault(require("./utils")), _search = require("./search");
246
+
247
+ Object.keys(_search).forEach(function(e) {
248
+ "default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _search[e] || Object.defineProperty(exports, e, {
249
+ enumerable: !0,
250
+ get: function() {
251
+ return _search[e];
252
+ }
253
+ }));
254
+ });
255
+
256
+ var _equal = require("./equal");
257
+
258
+ Object.keys(_equal).forEach(function(e) {
259
+ "default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _equal[e] || Object.defineProperty(exports, e, {
260
+ enumerable: !0,
261
+ get: function() {
262
+ return _equal[e];
263
+ }
264
+ }));
265
+ });
266
+
267
+ var _addition = _interopRequireDefault(require("./math/addition")), _amountCase = _interopRequireDefault(require("./math/amountCase")), _coinFormat = _interopRequireDefault(require("./math/coinFormat")), _colorUtil = _interopRequireDefault(require("./math/colorUtil")), _dateTime = _interopRequireDefault(require("./math/dateTime")), _pwdStrength = _interopRequireDefault(require("./math/pwdStrength")), _randomColor = _interopRequireDefault(require("./math/randomColor")), _subtraction = _interopRequireDefault(require("./math/subtraction")), _mul = _interopRequireDefault(require("./math/mul")), _divide = _interopRequireDefault(require("./math/divide")), _calendarUtils = require("./math/calendarUtils");
246
268
 
247
269
  Object.keys(_calendarUtils).forEach(function(e) {
248
270
  "default" !== e && "__esModule" !== e && (Object.prototype.hasOwnProperty.call(_exportNames, e) || e in exports && exports[e] === _calendarUtils[e] || Object.defineProperty(exports, e, {
package/lib/search.js ADDED
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: !0
7
+ }), exports.recursive = recursive;
8
+
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _deepCopy = require("./_deepCopy");
10
+
11
+ function _createForOfIteratorHelper(e, t) {
12
+ var r = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
13
+ if (!r) {
14
+ if (Array.isArray(e) || (r = _unsupportedIterableToArray(e)) || t && e && "number" == typeof e.length) {
15
+ r && (e = r);
16
+ var n = 0, i = function() {};
17
+ return {
18
+ s: i,
19
+ n: function() {
20
+ return n >= e.length ? {
21
+ done: !0
22
+ } : {
23
+ done: !1,
24
+ value: e[n++]
25
+ };
26
+ },
27
+ e: function(e) {
28
+ throw e;
29
+ },
30
+ f: i
31
+ };
32
+ }
33
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
34
+ }
35
+ var a, u = !0, l = !1;
36
+ return {
37
+ s: function() {
38
+ r = r.call(e);
39
+ },
40
+ n: function() {
41
+ var e = r.next();
42
+ return u = e.done, e;
43
+ },
44
+ e: function(e) {
45
+ l = !0, a = e;
46
+ },
47
+ f: function() {
48
+ try {
49
+ u || null == r.return || r.return();
50
+ } finally {
51
+ if (l) throw a;
52
+ }
53
+ }
54
+ };
55
+ }
56
+
57
+ function _unsupportedIterableToArray(e, t) {
58
+ if (e) {
59
+ if ("string" == typeof e) return _arrayLikeToArray(e, t);
60
+ var r = {}.toString.call(e).slice(8, -1);
61
+ return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0;
62
+ }
63
+ }
64
+
65
+ function _arrayLikeToArray(e, t) {
66
+ (null == t || t > e.length) && (t = e.length);
67
+ for (var r = 0, n = Array(t); r < t; r++) n[r] = e[r];
68
+ return n;
69
+ }
70
+
71
+ function recursive(e) {
72
+ var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "children";
73
+ return new (function() {
74
+ return (0, _createClass2.default)(function e(t, r) {
75
+ (0, _classCallCheck2.default)(this, e), this.list = (0, _deepCopy.deepCopy)(t || []),
76
+ this.childName = r;
77
+ }, [ {
78
+ key: "getLeafNodes",
79
+ value: function() {
80
+ var e = this, t = [], r = function(n) {
81
+ if (n[e.childName] && n[e.childName].length > 0) {
82
+ var i, a = _createForOfIteratorHelper(n[e.childName]);
83
+ try {
84
+ for (a.s(); !(i = a.n()).done; ) {
85
+ var u = i.value;
86
+ r(u);
87
+ }
88
+ } catch (e) {
89
+ a.e(e);
90
+ } finally {
91
+ a.f();
92
+ }
93
+ } else t.push(n);
94
+ };
95
+ return (this.list || []).map(function(e) {
96
+ return r(e);
97
+ }), t;
98
+ }
99
+ }, {
100
+ key: "some",
101
+ value: function(e) {
102
+ var t = this, r = function(n) {
103
+ return n.some(function(n, i) {
104
+ var a = e(n, i);
105
+ return a || !!(n[t.childName] && n[t.childName].length > 0) && r(n[t.childName]);
106
+ });
107
+ };
108
+ return r(this.list);
109
+ }
110
+ }, {
111
+ key: "find",
112
+ value: function(e) {
113
+ var t = this, r = null, n = function(i) {
114
+ return i.find(function(i, a) {
115
+ var u = e(i, a);
116
+ return u ? (r = i, u) : !!(i[t.childName] && i[t.childName].length > 0) && n(i[t.childName]);
117
+ });
118
+ };
119
+ return n(this.list), r;
120
+ }
121
+ }, {
122
+ key: "findParent",
123
+ value: function(e) {
124
+ var t = this, r = null, n = function(i, a) {
125
+ return i.find(function(i, u) {
126
+ var l = e(i, u, a);
127
+ return l ? (r = a, l) : !!(i[t.childName] && i[t.childName].length > 0) && n(i[t.childName], i);
128
+ });
129
+ };
130
+ return n(this.list, {}), r;
131
+ }
132
+ }, {
133
+ key: "findPath",
134
+ value: function(e) {
135
+ var t = this, r = [], n = function(i) {
136
+ return i.some(function(i, a) {
137
+ var u = !1;
138
+ return e(i, a) ? u = !0 : i[t.childName] && i[t.childName].length > 0 && (u = n(i[t.childName], i)),
139
+ u && (r = [].concat((0, _toConsumableArray2.default)(r), [ i ])), u;
140
+ });
141
+ };
142
+ return n(this.list), r;
143
+ }
144
+ }, {
145
+ key: "getMaxLengthPaths",
146
+ value: function() {
147
+ var e = this, t = [], r = [], n = function(i, a) {
148
+ return i.forEach(function(i, a) {
149
+ i[e.childName] && i[e.childName].length > 0 ? (r.push(i), n(i[e.childName], i)) : (r.push(i),
150
+ t.push(r), r = []);
151
+ });
152
+ };
153
+ return n(this.list), t.reduce(function(e, t) {
154
+ return e.length > t.length ? e : t;
155
+ }, []);
156
+ }
157
+ }, {
158
+ key: "getPaths",
159
+ value: function(e) {
160
+ var t = this, r = [], n = [], i = function(a, u) {
161
+ return a.forEach(function(a, u) {
162
+ a[t.childName] && a[t.childName].length > 0 ? (n.push(a), i(a[t.childName], a)) : (n.push(a),
163
+ e ? e(a) && r.push(n) : r.push(n), n = []);
164
+ });
165
+ };
166
+ return i(this.list), r;
167
+ }
168
+ }, {
169
+ key: "findIndex",
170
+ value: function(e) {
171
+ var t = this, r = -1, n = function(i, a) {
172
+ return i.find(function(i, u) {
173
+ var l = e(i, u, a);
174
+ return l ? (r = u, l) : !!(i[t.childName] && i[t.childName].length > 0) && n(i[t.childName], i);
175
+ });
176
+ };
177
+ return n(this.list, {}), r;
178
+ }
179
+ }, {
180
+ key: "filter",
181
+ value: function(e) {
182
+ var t = this, r = function(n, i) {
183
+ return n.filter(function(n, a) {
184
+ return n[t.childName] && n[t.childName].length > 0 && (n[t.childName] = r(n[t.childName], n)),
185
+ e(n, a, i);
186
+ });
187
+ };
188
+ return r(this.list, {});
189
+ }
190
+ }, {
191
+ key: "flatFilter",
192
+ value: function(e) {
193
+ var t = this, r = [], n = function(i, a) {
194
+ return i.forEach(function(i, u) {
195
+ e(i, u, a) && r.push(i), i[t.childName] && i[t.childName].length > 0 && n(i[t.childName], i);
196
+ });
197
+ };
198
+ return n(this.list, {}), r;
199
+ }
200
+ }, {
201
+ key: "map",
202
+ value: function(e) {
203
+ var t = this, r = function(n, i) {
204
+ return n.map(function(n, a) {
205
+ var u = e(n, a, i);
206
+ return u && (n = u), n[t.childName] && n[t.childName].length > 0 && (n[t.childName] = r(n[t.childName], n)),
207
+ n;
208
+ });
209
+ };
210
+ return r(this.list, {});
211
+ }
212
+ }, {
213
+ key: "search",
214
+ value: function(e) {
215
+ var t = this, r = function(n, i) {
216
+ return n.filter(function(n, a) {
217
+ var u = e(n, a, i), l = !1;
218
+ return u && u.length && (u[1] ? (u = !1, l = !0) : u = u[0]), u || (n[t.childName] && n[t.childName].length > 0 && (n[t.childName] = r(n[t.childName], n),
219
+ n[t.childName] && n[t.childName].length > 0 && (u = !0)), !!l || u);
220
+ });
221
+ };
222
+ return r(this.list, {});
223
+ }
224
+ }, {
225
+ key: "forEach",
226
+ value: function(e) {
227
+ var t = this, r = function(n, i) {
228
+ return n.map(function(n, a) {
229
+ var u = e(n, a, i);
230
+ return u && (n = u), n[t.childName] && n[t.childName].length > 0 && (n[t.childName] = r(n[t.childName], n)),
231
+ n;
232
+ });
233
+ };
234
+ return r(this.list, {});
235
+ }
236
+ } ]);
237
+ }())(e, t);
238
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amos-apptool",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "amos app tool",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./esm/index.js",