@soratani-code/samtools 1.3.10 → 1.3.12
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/lib/time.d.ts +3 -0
- package/lib/time.js +18 -0
- package/lib/transform.d.ts +3 -1
- package/lib/transform.js +52 -2
- package/package.json +1 -1
package/lib/time.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
type FormatType = "YYYY-MM-DD" | "YYYY/MM/DD" | "DD/MM/YYYY" | "YYYY-MM-DD HH:mm:ss" | "YYYY/MM/DD HH:mm:ss" | "DD/MM/YYYY HH:mm:ss" | "YYYY-MM-DD HH:mm" | "YYYY/MM/DD HH:mm" | "DD/MM/YYYY HH:mm" | "YYYY-MM-DD HH" | "YYYY/MM/DD HH" | "DD/MM/YYYY HH";
|
|
2
|
+
type DiffType = 'day' | 'hour' | 'minute' | 'second';
|
|
2
3
|
export declare class Time {
|
|
3
4
|
private readonly time;
|
|
4
5
|
private static types;
|
|
@@ -12,6 +13,8 @@ export declare class Time {
|
|
|
12
13
|
private mm;
|
|
13
14
|
private ss;
|
|
14
15
|
private _format;
|
|
16
|
+
timestamp(): number;
|
|
17
|
+
diff(time: Time, type: DiffType): number;
|
|
15
18
|
format(type: FormatType): string;
|
|
16
19
|
}
|
|
17
20
|
export {};
|
package/lib/time.js
CHANGED
|
@@ -44,6 +44,24 @@ class Time {
|
|
|
44
44
|
})
|
|
45
45
|
.join(sep);
|
|
46
46
|
}
|
|
47
|
+
timestamp() {
|
|
48
|
+
return this.data.getTime();
|
|
49
|
+
}
|
|
50
|
+
diff(time, type) {
|
|
51
|
+
const num = time.timestamp() - this.timestamp();
|
|
52
|
+
if (type === 'day') {
|
|
53
|
+
return Math.floor(num / (1000 * 60 * 60 * 24));
|
|
54
|
+
}
|
|
55
|
+
else if (type === 'hour') {
|
|
56
|
+
return Math.floor((num % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
|
57
|
+
}
|
|
58
|
+
else if (type === 'minute') {
|
|
59
|
+
return Math.floor((num % (1000 * 60 * 60)) / (1000 * 60));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return Math.floor((num % (1000 * 60)) / 1000);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
47
65
|
format(type) {
|
|
48
66
|
let defaultTime = type;
|
|
49
67
|
if (!Time.types.includes(type)) {
|
package/lib/transform.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ListToTreeSchema, TreeChildren } from '.';
|
|
2
|
-
export declare function listToTree<P = any, I =
|
|
2
|
+
export declare function listToTree<P = any, I = string, PI = string>(list: P[], id: I, parentId: PI, value: any, schema?: ListToTreeSchema): TreeChildren<P>[];
|
|
3
3
|
export declare function enumToList<K = number, V = string>(params: any): [K, V][];
|
|
4
4
|
export declare function enumToOptions(params?: any): {
|
|
5
5
|
label: string;
|
|
6
6
|
value: any;
|
|
7
7
|
}[];
|
|
8
|
+
export declare function isNotEmpty(data: any): any;
|
|
9
|
+
export declare function conversMenusPath<D = any, P = string, C = string>(data: D[], key: P, child: C, prefix?: string): any[];
|
package/lib/transform.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enumToOptions = exports.enumToList = exports.listToTree = void 0;
|
|
3
|
+
exports.conversMenusPath = exports.isNotEmpty = exports.enumToOptions = exports.enumToList = exports.listToTree = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const type_1 = require("./type");
|
|
5
6
|
function schemaToObj(obj, schema) {
|
|
6
7
|
if (!(0, type_1.isObject)(obj) || !schema || !(0, type_1.isObject)(schema) || (0, type_1.isEmpty)(schema))
|
|
@@ -16,7 +17,13 @@ function schemaToObj(obj, schema) {
|
|
|
16
17
|
}, {});
|
|
17
18
|
}
|
|
18
19
|
function listToTree(list, id, parentId, value, schema) {
|
|
19
|
-
|
|
20
|
+
if (!list || !list.length)
|
|
21
|
+
return [];
|
|
22
|
+
const root = list.filter((l) => {
|
|
23
|
+
if (!value)
|
|
24
|
+
return !l[parentId];
|
|
25
|
+
return l[parentId] == value;
|
|
26
|
+
});
|
|
20
27
|
const childrens = list.filter((l) => l[parentId] !== value);
|
|
21
28
|
return root.map((r) => {
|
|
22
29
|
return Object.assign(Object.assign({}, schemaToObj(r, schema)), { children: listToTree(childrens, id, parentId, r[id], schema) });
|
|
@@ -40,3 +47,46 @@ function enumToOptions(params = {}) {
|
|
|
40
47
|
}, []);
|
|
41
48
|
}
|
|
42
49
|
exports.enumToOptions = enumToOptions;
|
|
50
|
+
function isNotEmpty(data) {
|
|
51
|
+
if ((0, type_1.isEmpty)(data))
|
|
52
|
+
return data;
|
|
53
|
+
if ((0, type_1.isObject)(data)) {
|
|
54
|
+
return (0, lodash_1.reduce)(Object.keys(data), (pre, key) => {
|
|
55
|
+
if ((0, type_1.isUndefined)(data[key]) || (0, type_1.isNull)(data[key]))
|
|
56
|
+
return pre;
|
|
57
|
+
if ((0, type_1.isObject)(data[key]) || (0, type_1.isArray)(data[key])) {
|
|
58
|
+
pre[key] = isNotEmpty(data[key]);
|
|
59
|
+
}
|
|
60
|
+
else if (!(0, type_1.isEmpty)(data[key])) {
|
|
61
|
+
pre[key] = data[key];
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return pre;
|
|
65
|
+
}
|
|
66
|
+
}, {});
|
|
67
|
+
}
|
|
68
|
+
if ((0, type_1.isArray)(data)) {
|
|
69
|
+
return (0, lodash_1.map)(data, (item) => {
|
|
70
|
+
if ((0, type_1.isObject)(item) || (0, type_1.isArray)(item))
|
|
71
|
+
return isNotEmpty(item);
|
|
72
|
+
return item;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
exports.isNotEmpty = isNotEmpty;
|
|
78
|
+
function conversMenusPath(data, key, child, prefix) {
|
|
79
|
+
if (!data || !data.length)
|
|
80
|
+
return data;
|
|
81
|
+
return (0, lodash_1.map)(data, (item) => {
|
|
82
|
+
const clone = (0, lodash_1.cloneDeep)(item);
|
|
83
|
+
const children = (0, lodash_1.get)(clone, child, []);
|
|
84
|
+
const path = (0, lodash_1.filter)([prefix, ...item[key].split('/')], Boolean).join('/');
|
|
85
|
+
clone[key] = path;
|
|
86
|
+
if (children.length) {
|
|
87
|
+
clone[child] = conversMenusPath(children, key, child, path);
|
|
88
|
+
}
|
|
89
|
+
return clone;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.conversMenusPath = conversMenusPath;
|