@soratani-code/samtools 1.5.0 → 1.5.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/lib/tools.d.ts +8 -2
- package/lib/tools.js +29 -35
- package/package.json +1 -1
package/lib/tools.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export declare function isDeepEqual(a: any, b: any): any;
|
|
2
2
|
export declare function deepDelete(data: any, path: string): any;
|
|
3
3
|
export declare function insertArray(arr: any[], index: number, item: any): any[];
|
|
4
|
-
export declare function parseTemplateToOptions(source: string, template: string
|
|
4
|
+
export declare function parseTemplateToOptions(source: string, template: string, opts?: {
|
|
5
|
+
keepBraces?: boolean;
|
|
6
|
+
}): {
|
|
5
7
|
text: string;
|
|
6
|
-
|
|
8
|
+
items: any[];
|
|
7
9
|
};
|
|
8
10
|
export declare function mergeTemplateToSource(source: string, template: string): string;
|
|
9
11
|
export declare function replaceTemplateFromOptions(template: string, options: {
|
|
10
12
|
label: string;
|
|
11
13
|
value: any;
|
|
12
14
|
}[]): string;
|
|
15
|
+
export declare function mergeTemplateFromOptions(template: string, options: {
|
|
16
|
+
label: string;
|
|
17
|
+
value: any;
|
|
18
|
+
}[]): string;
|
package/lib/tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceTemplateFromOptions = exports.mergeTemplateToSource = exports.parseTemplateToOptions = exports.insertArray = exports.deepDelete = exports.isDeepEqual = void 0;
|
|
3
|
+
exports.mergeTemplateFromOptions = exports.replaceTemplateFromOptions = exports.mergeTemplateToSource = exports.parseTemplateToOptions = exports.insertArray = exports.deepDelete = exports.isDeepEqual = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const type_1 = require("./type");
|
|
6
6
|
function isDeepEqual(a, b) {
|
|
@@ -71,55 +71,40 @@ function insertArray(arr, index, item) {
|
|
|
71
71
|
return clone;
|
|
72
72
|
}
|
|
73
73
|
exports.insertArray = insertArray;
|
|
74
|
-
function parseTemplateToOptions(source, template) {
|
|
74
|
+
function parseTemplateToOptions(source, template, opts) {
|
|
75
75
|
var _a, _b;
|
|
76
|
+
const keepBraces = !!(opts === null || opts === void 0 ? void 0 : opts.keepBraces);
|
|
76
77
|
if (!template)
|
|
77
|
-
return { text:
|
|
78
|
+
return { text: '', items: [] };
|
|
78
79
|
const normalizeOp = (ch) => (ch === '−' ? '-' : ch);
|
|
79
|
-
const
|
|
80
|
+
const cleanLabel = (s) => (s !== null && s !== void 0 ? s : '').replace(/[()()]/g, '').trim();
|
|
80
81
|
const valueTokens = [];
|
|
81
|
-
const
|
|
82
|
+
const valRe = /\$\{\s*([^}]*)\s*\}/g;
|
|
82
83
|
let m;
|
|
83
|
-
while ((m =
|
|
84
|
+
while ((m = valRe.exec(template)) !== null) {
|
|
84
85
|
valueTokens.push(m[1]);
|
|
85
86
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const opsFromValue = template ? Array.from(template.matchAll(/[+\-−]/g)).map(x => normalizeOp(x[0])) : [];
|
|
91
|
-
const ops = opsFromLabel.length ? opsFromLabel : opsFromValue;
|
|
92
|
-
const parseToken = (tok) => {
|
|
93
|
-
if (tok == null)
|
|
94
|
-
return null;
|
|
95
|
-
const t = String(tok).trim();
|
|
96
|
-
if (t === '' || t.toLowerCase() === 'null')
|
|
97
|
-
return null;
|
|
98
|
-
const n = Number(t);
|
|
99
|
-
return Number.isFinite(n) ? n : null;
|
|
100
|
-
};
|
|
101
|
-
const len = Math.max(valueTokens.length, rawLabelPieces.length);
|
|
102
|
-
const options = [];
|
|
87
|
+
const labelSegmentsRaw = source ? source.split(/[+\-−*/]/) : [];
|
|
88
|
+
const labelSegments = labelSegmentsRaw.map(s => cleanLabel(s));
|
|
89
|
+
const len = Math.max(valueTokens.length, labelSegments.length);
|
|
90
|
+
const items = [];
|
|
103
91
|
for (let i = 0; i < len; i++) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const value =
|
|
107
|
-
|
|
92
|
+
const raw = (_a = valueTokens[i]) !== null && _a !== void 0 ? _a : '';
|
|
93
|
+
const label = (_b = labelSegments[i]) !== null && _b !== void 0 ? _b : '';
|
|
94
|
+
const value = Number(raw);
|
|
95
|
+
items.push({ label, value: isNaN(value) ? null : value });
|
|
108
96
|
}
|
|
109
|
-
let
|
|
97
|
+
let index = 0;
|
|
110
98
|
const text = template.replace(/\$\{\s*([^}]*)\s*\}/g, (match, inner) => {
|
|
111
99
|
const token = inner == null ? '' : String(inner).trim();
|
|
112
|
-
const
|
|
113
|
-
|
|
100
|
+
const mappedLabel = items[index] ? items[index].label : '';
|
|
101
|
+
index += 1;
|
|
114
102
|
if (token === '' || token.toLowerCase() === 'null') {
|
|
115
|
-
return
|
|
103
|
+
return keepBraces ? `\${${mappedLabel}}` : mappedLabel;
|
|
116
104
|
}
|
|
117
105
|
return match;
|
|
118
106
|
});
|
|
119
|
-
return {
|
|
120
|
-
text,
|
|
121
|
-
options,
|
|
122
|
-
};
|
|
107
|
+
return { text, items };
|
|
123
108
|
}
|
|
124
109
|
exports.parseTemplateToOptions = parseTemplateToOptions;
|
|
125
110
|
function mergeTemplateToSource(source, template) {
|
|
@@ -154,3 +139,12 @@ function replaceTemplateFromOptions(template, options) {
|
|
|
154
139
|
}, (0, lodash_1.cloneDeep)(template));
|
|
155
140
|
}
|
|
156
141
|
exports.replaceTemplateFromOptions = replaceTemplateFromOptions;
|
|
142
|
+
function mergeTemplateFromOptions(template, options) {
|
|
143
|
+
return (0, lodash_1.reduce)(options, (tpl, opt) => {
|
|
144
|
+
const has = template.includes('${' + opt.value + '}');
|
|
145
|
+
if (has)
|
|
146
|
+
return tpl.replace('${' + opt.value + '}', opt.label);
|
|
147
|
+
return tpl;
|
|
148
|
+
}, (0, lodash_1.cloneDeep)(template));
|
|
149
|
+
}
|
|
150
|
+
exports.mergeTemplateFromOptions = mergeTemplateFromOptions;
|