tools-min-ns 1.7.0 → 1.8.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/README.md +16 -0
- package/esm/array/TreeUtil.d.ts +7 -0
- package/esm/array/TreeUtil.js +21 -5
- package/esm/date/DateUtil.d.ts +7 -0
- package/esm/date/DateUtil.js +26 -0
- package/lib/array/TreeUtil.d.ts +7 -0
- package/lib/array/TreeUtil.js +21 -5
- package/lib/date/DateUtil.d.ts +7 -0
- package/lib/date/DateUtil.js +26 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,6 +5,22 @@ cnpm i tools-min-ns --save
|
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
# updates
|
|
8
|
+
## v1.8.1
|
|
9
|
+
|
|
10
|
+
> TreeUtil 修复getItemPathByTree
|
|
11
|
+
|
|
12
|
+
## v1.8.0
|
|
13
|
+
|
|
14
|
+
> TreeUtil 新增getItemPathByTree
|
|
15
|
+
|
|
16
|
+
## v1.7.2
|
|
17
|
+
|
|
18
|
+
> TreeUtil 修复getIdPathByTree
|
|
19
|
+
|
|
20
|
+
## v1.7.1
|
|
21
|
+
|
|
22
|
+
> DateUtil 新增getDatesOfMonth
|
|
23
|
+
|
|
8
24
|
## v1.7.0
|
|
9
25
|
|
|
10
26
|
> 新增FileUtil
|
package/esm/array/TreeUtil.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ declare namespace TreeUtil {
|
|
|
49
49
|
* @param fieldNames 映射对象
|
|
50
50
|
*/
|
|
51
51
|
function getIdPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): ValueType[];
|
|
52
|
+
/**
|
|
53
|
+
* @name 获取树中路径对象数组
|
|
54
|
+
* @param tree 树
|
|
55
|
+
* @param id 主键
|
|
56
|
+
* @param fieldNames 映射对象
|
|
57
|
+
*/
|
|
58
|
+
function getItemPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): T[];
|
|
52
59
|
/**
|
|
53
60
|
* @name 字符串分割转为树结构
|
|
54
61
|
* @param str string
|
package/esm/array/TreeUtil.js
CHANGED
|
@@ -178,6 +178,20 @@ var TreeUtil;
|
|
|
178
178
|
* @param fieldNames 映射对象
|
|
179
179
|
*/
|
|
180
180
|
function getIdPathByTree(tree, id, fieldNames) {
|
|
181
|
+
var _a = (fieldNames !== null && fieldNames !== void 0 ? fieldNames : {}).value,
|
|
182
|
+
value = _a === void 0 ? 'id' : _a;
|
|
183
|
+
return getItemPathByTree(tree, id, fieldNames).map(function (item) {
|
|
184
|
+
return item[value];
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
TreeUtil.getIdPathByTree = getIdPathByTree;
|
|
188
|
+
/**
|
|
189
|
+
* @name 获取树中路径对象数组
|
|
190
|
+
* @param tree 树
|
|
191
|
+
* @param id 主键
|
|
192
|
+
* @param fieldNames 映射对象
|
|
193
|
+
*/
|
|
194
|
+
function getItemPathByTree(tree, id, fieldNames) {
|
|
181
195
|
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
182
196
|
_b = _a.value,
|
|
183
197
|
value = _b === void 0 ? 'id' : _b,
|
|
@@ -188,15 +202,17 @@ var TreeUtil;
|
|
|
188
202
|
_e = _a.rootPid,
|
|
189
203
|
rootPid = _e === void 0 ? undefined : _e;
|
|
190
204
|
if (BaseUtil.isEmpty(id)) return [];
|
|
191
|
-
var idList =
|
|
192
|
-
|
|
205
|
+
var idList = filterTreeData(tree, function (t) {
|
|
206
|
+
return t[value] === id;
|
|
207
|
+
});
|
|
208
|
+
var list = getListByTree(tree, children);
|
|
193
209
|
var getList = function getList(importOid) {
|
|
194
|
-
forEachTree(tree, function (info) {
|
|
210
|
+
forEachTree(tree, function (info, _parent) {
|
|
195
211
|
if (String(info[value]) === String(importOid)) {
|
|
196
212
|
if (parent in info && info[parent] && list.some(function (e) {
|
|
197
213
|
return String(e[value]) === String(info[parent]);
|
|
198
214
|
})) {
|
|
199
|
-
idList.unshift(
|
|
215
|
+
idList.unshift(_parent);
|
|
200
216
|
getList(info === null || info === void 0 ? void 0 : info[parent]);
|
|
201
217
|
}
|
|
202
218
|
}
|
|
@@ -211,7 +227,7 @@ var TreeUtil;
|
|
|
211
227
|
}
|
|
212
228
|
return idList;
|
|
213
229
|
}
|
|
214
|
-
TreeUtil.
|
|
230
|
+
TreeUtil.getItemPathByTree = getItemPathByTree;
|
|
215
231
|
/**
|
|
216
232
|
* @name 字符串分割转为树结构
|
|
217
233
|
* @param str string
|
package/esm/date/DateUtil.d.ts
CHANGED
|
@@ -257,5 +257,12 @@ declare namespace DateUtil {
|
|
|
257
257
|
* @returns
|
|
258
258
|
*/
|
|
259
259
|
const timeFix: (t?: string) => string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
262
|
+
* @param yearMonth 2024-01
|
|
263
|
+
* @param format 'yyyy-MM-dd'
|
|
264
|
+
* @returns ['2024-01-01',...]
|
|
265
|
+
*/
|
|
266
|
+
function getDatesOfMonth(yearMonth: string, format?: string): string[];
|
|
260
267
|
}
|
|
261
268
|
export default DateUtil;
|
package/esm/date/DateUtil.js
CHANGED
|
@@ -731,6 +731,32 @@ var DateUtil;
|
|
|
731
731
|
var _a;
|
|
732
732
|
return (_a = t === null || t === void 0 ? void 0 : t.split('.')) === null || _a === void 0 ? void 0 : _a[0];
|
|
733
733
|
};
|
|
734
|
+
/**
|
|
735
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
736
|
+
* @param yearMonth 2024-01
|
|
737
|
+
* @param format 'yyyy-MM-dd'
|
|
738
|
+
* @returns ['2024-01-01',...]
|
|
739
|
+
*/
|
|
740
|
+
function getDatesOfMonth(yearMonth, format) {
|
|
741
|
+
if (format === void 0) {
|
|
742
|
+
format = 'yyyy-MM-dd';
|
|
743
|
+
}
|
|
744
|
+
var _a = __read(yearMonth.split('-').map(Number), 2),
|
|
745
|
+
year = _a[0],
|
|
746
|
+
month = _a[1]; // 分割字符串并转换为数字
|
|
747
|
+
var dates = []; // 初始化存储日期的数组
|
|
748
|
+
// 获取该月的第一天
|
|
749
|
+
var date = new Date(year, month - 1, 1);
|
|
750
|
+
// 循环直到月份改变
|
|
751
|
+
while (date.getMonth() === month - 1) {
|
|
752
|
+
// 将日期格式化为字符串并添加到数组中
|
|
753
|
+
dates.push(DateUtil.formatDate(date, format));
|
|
754
|
+
// 日期加一天
|
|
755
|
+
date.setDate(date.getDate() + 2);
|
|
756
|
+
}
|
|
757
|
+
return dates;
|
|
758
|
+
}
|
|
759
|
+
DateUtil.getDatesOfMonth = getDatesOfMonth;
|
|
734
760
|
})(DateUtil || (DateUtil = {}));
|
|
735
761
|
export default DateUtil;
|
|
736
762
|
var dateFormatRules = [{
|
package/lib/array/TreeUtil.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ declare namespace TreeUtil {
|
|
|
49
49
|
* @param fieldNames 映射对象
|
|
50
50
|
*/
|
|
51
51
|
function getIdPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): ValueType[];
|
|
52
|
+
/**
|
|
53
|
+
* @name 获取树中路径对象数组
|
|
54
|
+
* @param tree 树
|
|
55
|
+
* @param id 主键
|
|
56
|
+
* @param fieldNames 映射对象
|
|
57
|
+
*/
|
|
58
|
+
function getItemPathByTree<T>(tree: T[], id: ValueType, fieldNames?: FieldNames): T[];
|
|
52
59
|
/**
|
|
53
60
|
* @name 字符串分割转为树结构
|
|
54
61
|
* @param str string
|
package/lib/array/TreeUtil.js
CHANGED
|
@@ -188,6 +188,20 @@ var TreeUtil;
|
|
|
188
188
|
* @param fieldNames 映射对象
|
|
189
189
|
*/
|
|
190
190
|
function getIdPathByTree(tree, id, fieldNames) {
|
|
191
|
+
var _a = (fieldNames !== null && fieldNames !== void 0 ? fieldNames : {}).value,
|
|
192
|
+
value = _a === void 0 ? 'id' : _a;
|
|
193
|
+
return getItemPathByTree(tree, id, fieldNames).map(function (item) {
|
|
194
|
+
return item[value];
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
TreeUtil.getIdPathByTree = getIdPathByTree;
|
|
198
|
+
/**
|
|
199
|
+
* @name 获取树中路径对象数组
|
|
200
|
+
* @param tree 树
|
|
201
|
+
* @param id 主键
|
|
202
|
+
* @param fieldNames 映射对象
|
|
203
|
+
*/
|
|
204
|
+
function getItemPathByTree(tree, id, fieldNames) {
|
|
191
205
|
var _a = fieldNames !== null && fieldNames !== void 0 ? fieldNames : {},
|
|
192
206
|
_b = _a.value,
|
|
193
207
|
value = _b === void 0 ? 'id' : _b,
|
|
@@ -198,15 +212,17 @@ var TreeUtil;
|
|
|
198
212
|
_e = _a.rootPid,
|
|
199
213
|
rootPid = _e === void 0 ? undefined : _e;
|
|
200
214
|
if (BaseUtil_1.default.isEmpty(id)) return [];
|
|
201
|
-
var idList =
|
|
202
|
-
|
|
215
|
+
var idList = filterTreeData(tree, function (t) {
|
|
216
|
+
return t[value] === id;
|
|
217
|
+
});
|
|
218
|
+
var list = getListByTree(tree, children);
|
|
203
219
|
var getList = function getList(importOid) {
|
|
204
|
-
forEachTree(tree, function (info) {
|
|
220
|
+
forEachTree(tree, function (info, _parent) {
|
|
205
221
|
if (String(info[value]) === String(importOid)) {
|
|
206
222
|
if (parent in info && info[parent] && list.some(function (e) {
|
|
207
223
|
return String(e[value]) === String(info[parent]);
|
|
208
224
|
})) {
|
|
209
|
-
idList.unshift(
|
|
225
|
+
idList.unshift(_parent);
|
|
210
226
|
getList(info === null || info === void 0 ? void 0 : info[parent]);
|
|
211
227
|
}
|
|
212
228
|
}
|
|
@@ -221,7 +237,7 @@ var TreeUtil;
|
|
|
221
237
|
}
|
|
222
238
|
return idList;
|
|
223
239
|
}
|
|
224
|
-
TreeUtil.
|
|
240
|
+
TreeUtil.getItemPathByTree = getItemPathByTree;
|
|
225
241
|
/**
|
|
226
242
|
* @name 字符串分割转为树结构
|
|
227
243
|
* @param str string
|
package/lib/date/DateUtil.d.ts
CHANGED
|
@@ -257,5 +257,12 @@ declare namespace DateUtil {
|
|
|
257
257
|
* @returns
|
|
258
258
|
*/
|
|
259
259
|
const timeFix: (t?: string) => string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
262
|
+
* @param yearMonth 2024-01
|
|
263
|
+
* @param format 'yyyy-MM-dd'
|
|
264
|
+
* @returns ['2024-01-01',...]
|
|
265
|
+
*/
|
|
266
|
+
function getDatesOfMonth(yearMonth: string, format?: string): string[];
|
|
260
267
|
}
|
|
261
268
|
export default DateUtil;
|
package/lib/date/DateUtil.js
CHANGED
|
@@ -741,6 +741,32 @@ var DateUtil;
|
|
|
741
741
|
var _a;
|
|
742
742
|
return (_a = t === null || t === void 0 ? void 0 : t.split('.')) === null || _a === void 0 ? void 0 : _a[0];
|
|
743
743
|
};
|
|
744
|
+
/**
|
|
745
|
+
* 格式为“年-月”,然后输出该月所有日期的数组
|
|
746
|
+
* @param yearMonth 2024-01
|
|
747
|
+
* @param format 'yyyy-MM-dd'
|
|
748
|
+
* @returns ['2024-01-01',...]
|
|
749
|
+
*/
|
|
750
|
+
function getDatesOfMonth(yearMonth, format) {
|
|
751
|
+
if (format === void 0) {
|
|
752
|
+
format = 'yyyy-MM-dd';
|
|
753
|
+
}
|
|
754
|
+
var _a = __read(yearMonth.split('-').map(Number), 2),
|
|
755
|
+
year = _a[0],
|
|
756
|
+
month = _a[1]; // 分割字符串并转换为数字
|
|
757
|
+
var dates = []; // 初始化存储日期的数组
|
|
758
|
+
// 获取该月的第一天
|
|
759
|
+
var date = new Date(year, month - 1, 1);
|
|
760
|
+
// 循环直到月份改变
|
|
761
|
+
while (date.getMonth() === month - 1) {
|
|
762
|
+
// 将日期格式化为字符串并添加到数组中
|
|
763
|
+
dates.push(DateUtil.formatDate(date, format));
|
|
764
|
+
// 日期加一天
|
|
765
|
+
date.setDate(date.getDate() + 2);
|
|
766
|
+
}
|
|
767
|
+
return dates;
|
|
768
|
+
}
|
|
769
|
+
DateUtil.getDatesOfMonth = getDatesOfMonth;
|
|
744
770
|
})(DateUtil || (DateUtil = {}));
|
|
745
771
|
exports.default = DateUtil;
|
|
746
772
|
var dateFormatRules = [{
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools-min-ns",
|
|
3
3
|
"description": "工具包适用于前端以及node",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "nanshen",
|
|
8
8
|
"module": "esm/index.js",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://
|
|
11
|
+
"url": "https://registry.npmjs.org/"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"esm",
|