@soratani-code/samtools 1.5.1 → 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 CHANGED
@@ -1,9 +1,11 @@
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
- options: any;
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: {
package/lib/tools.js CHANGED
@@ -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: template || '', options: [] };
78
+ return { text: '', items: [] };
78
79
  const normalizeOp = (ch) => (ch === '−' ? '-' : ch);
79
- const cleanLabelPiece = (s) => (s || '').replace(/[()()]/g, '').trim();
80
+ const cleanLabel = (s) => (s !== null && s !== void 0 ? s : '').replace(/[()()]/g, '').trim();
80
81
  const valueTokens = [];
81
- const valueRe = /\$\{\s*([^}]*)\s*\}/g;
82
+ const valRe = /\$\{\s*([^}]*)\s*\}/g;
82
83
  let m;
83
- while ((m = valueRe.exec(template)) !== null) {
84
+ while ((m = valRe.exec(template)) !== null) {
84
85
  valueTokens.push(m[1]);
85
86
  }
86
- const rawLabelPieces = source
87
- ? source.split(/\s*[+\-−]\s*/).map((s) => cleanLabelPiece(s)).filter(Boolean)
88
- : [];
89
- const opsFromLabel = source ? Array.from(source.matchAll(/[+\-−]/g)).map(x => normalizeOp(x[0])) : [];
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 label = (_a = rawLabelPieces[i]) !== null && _a !== void 0 ? _a : '';
105
- const raw = (_b = valueTokens[i]) !== null && _b !== void 0 ? _b : '';
106
- const value = parseToken(raw);
107
- options.push({ label, raw, value });
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 idx = 0;
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 labelForThis = options[idx] ? (options[idx].label || '') : '';
113
- idx += 1;
100
+ const mappedLabel = items[index] ? items[index].label : '';
101
+ index += 1;
114
102
  if (token === '' || token.toLowerCase() === 'null') {
115
- return '${' + labelForThis + '}';
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soratani-code/samtools",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "",
5
5
  "typings": "lib/index.d.ts",
6
6
  "main": "lib/index.js",