@soratani-code/samtools 1.5.4 → 1.5.6

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/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * as tree from './tree';
2
2
  export * as set from "./set";
3
3
  export * as log from "./log";
4
+ export * as template from './template';
4
5
  export * as color from "./color";
5
6
  export * as query from "./query";
6
7
  export * as transform from "./transform";
package/lib/index.js CHANGED
@@ -29,10 +29,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.Graph = exports.transform = exports.query = exports.color = exports.log = exports.set = exports.tree = void 0;
32
+ exports.Graph = exports.transform = exports.query = exports.color = exports.template = exports.log = exports.set = exports.tree = void 0;
33
33
  exports.tree = __importStar(require("./tree"));
34
34
  exports.set = __importStar(require("./set"));
35
35
  exports.log = __importStar(require("./log"));
36
+ exports.template = __importStar(require("./template"));
36
37
  exports.color = __importStar(require("./color"));
37
38
  exports.query = __importStar(require("./query"));
38
39
  exports.transform = __importStar(require("./transform"));
package/lib/permission.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.permission = exports.computeUserPermission = exports.permissionCompute = exports.perm = exports.filterPermission = void 0;
4
- const lodash_1 = require("lodash");
5
4
  const type_1 = require("./type");
5
+ const tools_1 = require("./tools");
6
6
  const judge = (actions, perm) => {
7
7
  if (!perm || !perm.length) {
8
8
  return false;
@@ -41,26 +41,26 @@ function filterPermission(code, permissions) {
41
41
  return target && target == source || !source;
42
42
  }
43
43
  function equality(target, source) {
44
- const tar = reversePermissionBinary(target);
45
- const sou = reversePermissionBinary(source);
46
- return (0, lodash_1.every)(sou, (i, index) => diff(Number(tar[index]), Number(i)));
44
+ const tar = reversePermissionBinary(target).split("");
45
+ const sou = reversePermissionBinary(source).split("");
46
+ return sou.every((i, index) => diff(Number(tar[index]), Number(i)));
47
47
  }
48
- return (0, lodash_1.filter)(permissions, (i) => equality(bina, binary(i)));
48
+ return permissions.filter((i) => equality(bina, binary(i)));
49
49
  }
50
50
  exports.filterPermission = filterPermission;
51
51
  function perm(...nums) {
52
- return (0, lodash_1.reduce)(nums, (pre, n) => pre | n, 0);
52
+ return nums.reduce((pre, n) => pre | n, 0);
53
53
  }
54
54
  exports.perm = perm;
55
55
  function permissionCompute(resources, permissions) {
56
56
  const permValues = Object.values(resources);
57
57
  const resources_maps = Object.entries(resources);
58
58
  const permissions_maps = Object.entries(permissions);
59
- return (0, lodash_1.reduce)(permissions_maps, (pre, item) => {
59
+ return permissions_maps.reduce((pre, item) => {
60
60
  const [key, code] = item;
61
- pre[key] = (0, lodash_1.map)(filterPermission(code, permValues), (i) => {
62
- const item = (0, lodash_1.find)(resources_maps, o => o[1] === i);
63
- const perm = (0, lodash_1.get)(item, '0');
61
+ pre[key] = filterPermission(code, permValues).map((i) => {
62
+ const item = resources_maps.find(o => o[1] === i);
63
+ const perm = (0, tools_1.get)(item, '0');
64
64
  return perm;
65
65
  }).filter(Boolean);
66
66
  return pre;
@@ -70,7 +70,7 @@ exports.permissionCompute = permissionCompute;
70
70
  function computeUserPermission(permissions, allPermissions) {
71
71
  const allKeys = Object.keys(allPermissions);
72
72
  const keys = Object.keys(permissions);
73
- return (0, lodash_1.reduce)(allKeys, (pre, key) => {
73
+ return allKeys.reduce((pre, key) => {
74
74
  if (keys.includes(key)) {
75
75
  pre[key] = filterPermission(permissions[key], allPermissions[key]);
76
76
  }
@@ -0,0 +1,20 @@
1
+ export declare function parseTemplateToOptions(source: string, template: string, opts?: {
2
+ keepBraces?: boolean;
3
+ }): {
4
+ text: string;
5
+ items: any[];
6
+ };
7
+ export declare function mergeTemplateToSource(source: string, template: string): string;
8
+ export declare function replaceTemplateFromOptions(template: string, options: {
9
+ label: string;
10
+ value: any;
11
+ }[]): string;
12
+ export declare function mergeTemplateFromOptions(template: string, options: {
13
+ label: string;
14
+ value: any;
15
+ }[]): string;
16
+ export declare function parseOperatorsTokens(expr: string | null | undefined): string[];
17
+ export declare function highlightMatchesToHtml(text: string | null | undefined, terms: string[] | null | undefined, options?: {
18
+ tag?: string;
19
+ className?: string;
20
+ }): string;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.highlightMatchesToHtml = exports.parseOperatorsTokens = exports.mergeTemplateFromOptions = exports.replaceTemplateFromOptions = exports.mergeTemplateToSource = exports.parseTemplateToOptions = void 0;
4
+ const tools_1 = require("./tools");
5
+ function escapeHtml(s) {
6
+ return s
7
+ .replace(/&/g, '&')
8
+ .replace(/</g, '&lt;')
9
+ .replace(/>/g, '&gt;')
10
+ .replace(/"/g, '&quot;')
11
+ .replace(/'/g, '&#39;');
12
+ }
13
+ function parseTemplateToOptions(source, template, opts) {
14
+ var _a, _b;
15
+ const keepBraces = !!(opts === null || opts === void 0 ? void 0 : opts.keepBraces);
16
+ if (!template)
17
+ return { text: '', items: [] };
18
+ const cleanLabel = (s) => (s !== null && s !== void 0 ? s : '').replace(/[()()]/g, '').trim();
19
+ const valueTokens = [];
20
+ const valRe = /\$\{\s*([^}]*)\s*\}/g;
21
+ let m;
22
+ while ((m = valRe.exec(template)) !== null) {
23
+ valueTokens.push(m[1]);
24
+ }
25
+ const labelSegmentsRaw = source ? source.split(/[+\-−*/]/) : [];
26
+ const labelSegments = labelSegmentsRaw.map(s => cleanLabel(s));
27
+ const len = Math.max(valueTokens.length, labelSegments.length);
28
+ const items = [];
29
+ for (let i = 0; i < len; i++) {
30
+ const raw = (_a = valueTokens[i]) !== null && _a !== void 0 ? _a : '';
31
+ const label = (_b = labelSegments[i]) !== null && _b !== void 0 ? _b : '';
32
+ const value = Number(raw);
33
+ items.push({ label, value: isNaN(value) ? null : value });
34
+ }
35
+ let index = 0;
36
+ const text = template.replace(/\$\{\s*([^}]*)\s*\}/g, (match, inner) => {
37
+ const token = inner == null ? '' : String(inner).trim();
38
+ const mappedLabel = items[index] ? items[index].label : '';
39
+ index += 1;
40
+ if (token === '' || token.toLowerCase() === 'null') {
41
+ return keepBraces ? `\${${mappedLabel}}` : mappedLabel;
42
+ }
43
+ return match;
44
+ });
45
+ return { text, items };
46
+ }
47
+ exports.parseTemplateToOptions = parseTemplateToOptions;
48
+ function mergeTemplateToSource(source, template) {
49
+ if (typeof source !== 'string' || typeof template !== 'string')
50
+ return template;
51
+ const regex = /\/\s*(?:\(\s*)?([^()\/-]+?)\s*-\s*([^()\/]+?)(?:\s*\))?/g;
52
+ const leftOperands = [];
53
+ let m;
54
+ while ((m = regex.exec(source)) !== null) {
55
+ leftOperands.push(m[1].trim());
56
+ }
57
+ if (!leftOperands.length) {
58
+ return template;
59
+ }
60
+ let idx = 0;
61
+ const replaced = template.replace(/\$\{null\}|\bnull\b/g, (match) => {
62
+ if (idx >= leftOperands.length) {
63
+ return match;
64
+ }
65
+ const val = leftOperands[idx++];
66
+ return val;
67
+ });
68
+ return replaced;
69
+ }
70
+ exports.mergeTemplateToSource = mergeTemplateToSource;
71
+ function replaceTemplateFromOptions(template, options) {
72
+ return options.reduce((tpl, opt) => {
73
+ const has = template.includes('${' + opt.value + '}');
74
+ if (has)
75
+ tpl;
76
+ return tpl.replace('${' + opt.label + '}', '${' + opt.value + '}');
77
+ }, (0, tools_1.cloneDeep)(template));
78
+ }
79
+ exports.replaceTemplateFromOptions = replaceTemplateFromOptions;
80
+ function mergeTemplateFromOptions(template, options) {
81
+ return options.reduce((tpl, opt) => {
82
+ const has = template.includes('${' + opt.value + '}');
83
+ if (has)
84
+ return tpl.replace('${' + opt.value + '}', opt.label);
85
+ return tpl;
86
+ }, (0, tools_1.cloneDeep)(template));
87
+ }
88
+ exports.mergeTemplateFromOptions = mergeTemplateFromOptions;
89
+ function parseOperatorsTokens(expr) {
90
+ if (expr == null)
91
+ return [];
92
+ return expr
93
+ .split(/[+\-*/()]/)
94
+ .map((s) => s.trim())
95
+ .filter(Boolean);
96
+ }
97
+ exports.parseOperatorsTokens = parseOperatorsTokens;
98
+ function highlightMatchesToHtml(text, terms, options) {
99
+ if (text == null)
100
+ return '';
101
+ const tlist = (terms || []).filter(Boolean);
102
+ if (!tlist.length)
103
+ return escapeHtml(text);
104
+ const tag = (options === null || options === void 0 ? void 0 : options.tag) || 'mark';
105
+ const className = (options === null || options === void 0 ? void 0 : options.className) || 'samtools-highlight';
106
+ const unique = Array.from(new Set(tlist)).sort((a, b) => b.length - a.length);
107
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
108
+ const alt = unique.map(esc).join('|');
109
+ const re = new RegExp(`(^|[^\\p{Script=Han}\\w])(${alt})(?=$|[^\\p{Script=Han}\\w])`, 'gu');
110
+ let lastIndex = 0;
111
+ let out = '';
112
+ let m;
113
+ while ((m = re.exec(text)) !== null) {
114
+ const idx = m.index;
115
+ const prefix = m[1] || '';
116
+ const matched = m[2];
117
+ if (idx > lastIndex)
118
+ out += escapeHtml(text.slice(lastIndex, idx));
119
+ out += escapeHtml(prefix);
120
+ out += `<${tag} class="${escapeHtml(className)}">${escapeHtml(matched)}</${tag}>`;
121
+ lastIndex = idx + prefix.length + matched.length;
122
+ }
123
+ if (lastIndex < text.length)
124
+ out += escapeHtml(text.slice(lastIndex));
125
+ return out;
126
+ }
127
+ exports.highlightMatchesToHtml = highlightMatchesToHtml;
package/lib/tools.d.ts CHANGED
@@ -1,23 +1,8 @@
1
- export declare function isDeepEqual(a: any, b: any): any;
2
- export declare function deepDelete(data: any, path: string): any;
1
+ export declare function cloneDeep<T>(value: T): T;
2
+ export declare function isEqual(a: any, b: any): boolean;
3
+ export declare function deleteDeep(data: any, path: string): any;
3
4
  export declare function insertArray(arr: any[], index: number, item: any): any[];
4
- export declare function parseTemplateToOptions(source: string, template: string, opts?: {
5
- keepBraces?: boolean;
6
- }): {
7
- text: string;
8
- items: any[];
9
- };
10
- export declare function mergeTemplateToSource(source: string, template: string): string;
11
- export declare function replaceTemplateFromOptions(template: string, options: {
12
- label: string;
13
- value: any;
14
- }[]): string;
15
- export declare function mergeTemplateFromOptions(template: string, options: {
16
- label: string;
17
- value: any;
18
- }[]): string;
19
- export declare function parseOperatorsTokens(expr: string | null | undefined): string[];
20
- export declare function highlightMatchesToHtml(text: string | null | undefined, terms: string[] | null | undefined, options?: {
21
- tag?: string;
22
- className?: string;
23
- }): string;
5
+ export declare function get(obj: any, path: string | Array<string | number> | number, defaultValue?: any): any;
6
+ export declare function omit<T extends any = any>(obj: T | null | undefined, props: string | Array<string>): Partial<T>;
7
+ export declare function insertBetweenImmutable<D = any>(arr: D[], filler: (index: number) => D): D[];
8
+ export declare function interchangeById<T extends Record<string, any> = any>(arr: T[] | (string | number)[], idA: string | number, idB: string | number, idKey?: string): T[] | (string | number)[];
package/lib/tools.js CHANGED
@@ -1,50 +1,319 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.highlightMatchesToHtml = exports.parseOperatorsTokens = exports.mergeTemplateFromOptions = exports.replaceTemplateFromOptions = exports.mergeTemplateToSource = exports.parseTemplateToOptions = exports.insertArray = exports.deepDelete = exports.isDeepEqual = void 0;
4
- const lodash_1 = require("lodash");
3
+ exports.interchangeById = exports.insertBetweenImmutable = exports.omit = exports.get = exports.insertArray = exports.deleteDeep = exports.isEqual = exports.cloneDeep = void 0;
5
4
  const type_1 = require("./type");
6
- function isDeepEqual(a, b) {
7
- function isEqualKeys(keys, _keys) {
8
- const sk = keys.sort();
9
- const _sk = _keys.sort();
10
- return (0, lodash_1.isEqual)(sk, _sk);
5
+ function cloneDeep(value) {
6
+ if (value === null || typeof value !== 'object')
7
+ return value;
8
+ const seen = new WeakMap();
9
+ const createEmpty = (val) => {
10
+ if (val instanceof Date)
11
+ return new Date(val.getTime());
12
+ if (val instanceof RegExp)
13
+ return new RegExp(val.source, val.flags);
14
+ if (Array.isArray(val))
15
+ return [];
16
+ if (val instanceof Map)
17
+ return new Map();
18
+ if (val instanceof Set)
19
+ return new Set();
20
+ if (ArrayBuffer.isView(val)) {
21
+ const Ctor = val.constructor;
22
+ return new Ctor(val.length);
23
+ }
24
+ const proto = Object.getPrototypeOf(val);
25
+ return Object.create(proto);
26
+ };
27
+ const root = createEmpty(value);
28
+ seen.set(value, root);
29
+ const stack = [{ src: value, dst: root }];
30
+ while (stack.length) {
31
+ const { src, dst } = stack.pop();
32
+ if (src instanceof Map) {
33
+ src.forEach((v, k) => {
34
+ if (v && typeof v === 'object') {
35
+ if (seen.has(v))
36
+ dst.set(k, seen.get(v));
37
+ else {
38
+ const node = createEmpty(v);
39
+ seen.set(v, node);
40
+ dst.set(k, node);
41
+ stack.push({ src: v, dst: node });
42
+ }
43
+ }
44
+ else
45
+ dst.set(k, v);
46
+ });
47
+ continue;
48
+ }
49
+ if (src instanceof Set) {
50
+ src.forEach((v) => {
51
+ if (v && typeof v === 'object') {
52
+ if (seen.has(v))
53
+ dst.add(seen.get(v));
54
+ else {
55
+ const node = createEmpty(v);
56
+ seen.set(v, node);
57
+ dst.add(node);
58
+ stack.push({ src: v, dst: node });
59
+ }
60
+ }
61
+ else
62
+ dst.add(v);
63
+ });
64
+ continue;
65
+ }
66
+ if (ArrayBuffer.isView(src)) {
67
+ for (let i = 0; i < src.length; i++)
68
+ dst[i] = src[i];
69
+ continue;
70
+ }
71
+ if (Array.isArray(src)) {
72
+ for (let i = 0; i < src.length; i++) {
73
+ const v = src[i];
74
+ if (v && typeof v === 'object') {
75
+ if (seen.has(v))
76
+ dst[i] = seen.get(v);
77
+ else {
78
+ const node = createEmpty(v);
79
+ seen.set(v, node);
80
+ dst[i] = node;
81
+ stack.push({ src: v, dst: node });
82
+ }
83
+ }
84
+ else
85
+ dst[i] = v;
86
+ }
87
+ const keys = Object.keys(src).filter((k) => String(Number(k)) !== k);
88
+ for (const key of keys) {
89
+ const v = src[key];
90
+ if (v && typeof v === 'object') {
91
+ if (seen.has(v))
92
+ dst[key] = seen.get(v);
93
+ else {
94
+ const node = createEmpty(v);
95
+ seen.set(v, node);
96
+ dst[key] = node;
97
+ stack.push({ src: v, dst: node });
98
+ }
99
+ }
100
+ else
101
+ dst[key] = v;
102
+ }
103
+ const syms = Object.getOwnPropertySymbols(src);
104
+ for (const s of syms)
105
+ dst[s] = src[s];
106
+ continue;
107
+ }
108
+ const ownKeys = Object.keys(src);
109
+ for (const key of ownKeys) {
110
+ const v = src[key];
111
+ if (v && typeof v === 'object') {
112
+ if (seen.has(v))
113
+ dst[key] = seen.get(v);
114
+ else {
115
+ const node = createEmpty(v);
116
+ seen.set(v, node);
117
+ dst[key] = node;
118
+ stack.push({ src: v, dst: node });
119
+ }
120
+ }
121
+ else
122
+ dst[key] = v;
123
+ }
124
+ const symbols = Object.getOwnPropertySymbols(src);
125
+ for (const sym of symbols) {
126
+ const v = src[sym];
127
+ if (v && typeof v === 'object') {
128
+ if (seen.has(v))
129
+ dst[sym] = seen.get(v);
130
+ else {
131
+ const node = createEmpty(v);
132
+ seen.set(v, node);
133
+ dst[sym] = node;
134
+ stack.push({ src: v, dst: node });
135
+ }
136
+ }
137
+ else
138
+ dst[sym] = v;
139
+ }
11
140
  }
12
- return (0, lodash_1.isEqualWith)(a, b, (n, o) => {
13
- if ((0, type_1.type)(n) !== (0, type_1.type)(o))
141
+ return root;
142
+ }
143
+ exports.cloneDeep = cloneDeep;
144
+ function isEqual(a, b) {
145
+ const aStack = [];
146
+ const bStack = [];
147
+ function eq(x, y) {
148
+ if (x === y)
149
+ return x !== 0 || 1 / x === 1 / y;
150
+ if (x !== x && y !== y)
151
+ return true;
152
+ const typeX = typeof x;
153
+ const typeY = typeof y;
154
+ if (typeX !== 'object' || typeY !== 'object')
155
+ return false;
156
+ if (x == null || y == null)
157
+ return x === y;
158
+ for (let i = 0; i < aStack.length; i++) {
159
+ if (aStack[i] === x)
160
+ return bStack[i] === y;
161
+ }
162
+ const toString = Object.prototype.toString;
163
+ const xTag = toString.call(x);
164
+ const yTag = toString.call(y);
165
+ if (xTag !== yTag)
14
166
  return false;
15
- if ((0, type_1.isObject)(n)) {
16
- const nk = Object.keys(n);
17
- const ok = Object.keys(o);
18
- if (nk.length !== ok.length || !isEqualKeys(nk, ok))
167
+ switch (xTag) {
168
+ case '[object String]':
169
+ case '[object Boolean]':
170
+ case '[object Number]':
171
+ return Object.prototype.valueOf.call(x) === Object.prototype.valueOf.call(y);
172
+ case '[object Date]':
173
+ return x.getTime() === y.getTime();
174
+ case '[object RegExp]':
175
+ return x.source === y.source && x.flags === y.flags;
176
+ case '[object Map]':
177
+ if (x.size !== y.size)
178
+ return false;
179
+ break;
180
+ case '[object Set]':
181
+ if (x.size !== y.size)
182
+ return false;
183
+ break;
184
+ default:
185
+ break;
186
+ }
187
+ aStack.push(x);
188
+ bStack.push(y);
189
+ if (xTag === '[object Array]') {
190
+ if (x.length !== y.length) {
191
+ aStack.pop();
192
+ bStack.pop();
19
193
  return false;
20
- return (0, lodash_1.every)(nk, (key) => isDeepEqual(n[key], o[key]));
194
+ }
195
+ for (let i = 0; i < x.length; i++)
196
+ if (!eq(x[i], y[i])) {
197
+ aStack.pop();
198
+ bStack.pop();
199
+ return false;
200
+ }
201
+ aStack.pop();
202
+ bStack.pop();
203
+ return true;
21
204
  }
22
- if ((0, type_1.isArray)(n)) {
23
- if (n.length !== o.length)
205
+ if (xTag === '[object Map]') {
206
+ const mx = x;
207
+ const my = y;
208
+ for (const [kx, vx] of mx) {
209
+ let found = false;
210
+ for (const [ky, vy] of my) {
211
+ if (eq(kx, ky) && eq(vx, vy)) {
212
+ found = true;
213
+ break;
214
+ }
215
+ }
216
+ if (!found) {
217
+ aStack.pop();
218
+ bStack.pop();
219
+ return false;
220
+ }
221
+ }
222
+ aStack.pop();
223
+ bStack.pop();
224
+ return true;
225
+ }
226
+ if (xTag === '[object Set]') {
227
+ const sx = Array.from(x);
228
+ const sy = Array.from(y);
229
+ for (const ex of sx) {
230
+ let found = false;
231
+ for (let j = 0; j < sy.length; j++) {
232
+ if (eq(ex, sy[j])) {
233
+ sy.splice(j, 1);
234
+ found = true;
235
+ break;
236
+ }
237
+ }
238
+ if (!found) {
239
+ aStack.pop();
240
+ bStack.pop();
241
+ return false;
242
+ }
243
+ }
244
+ aStack.pop();
245
+ bStack.pop();
246
+ return true;
247
+ }
248
+ if (ArrayBuffer.isView(x)) {
249
+ const lx = x.length;
250
+ if (lx !== y.length) {
251
+ aStack.pop();
252
+ bStack.pop();
24
253
  return false;
25
- return (0, lodash_1.every)(n, (item, index) => {
26
- return isDeepEqual(item, o[index]);
27
- });
254
+ }
255
+ for (let i = 0; i < lx; i++)
256
+ if (x[i] !== y[i]) {
257
+ aStack.pop();
258
+ bStack.pop();
259
+ return false;
260
+ }
261
+ aStack.pop();
262
+ bStack.pop();
263
+ return true;
264
+ }
265
+ const keysX = Object.keys(x);
266
+ const keysY = Object.keys(y);
267
+ if (keysX.length !== keysY.length) {
268
+ aStack.pop();
269
+ bStack.pop();
270
+ return false;
28
271
  }
29
- if ((0, type_1.isUndefined)(n))
30
- return (0, type_1.isUndefined)(o);
31
- if ((0, type_1.isNull)(n))
32
- return (0, type_1.isNull)(o);
33
- return (0, lodash_1.isEqual)(n, o);
34
- });
272
+ for (const key of keysX)
273
+ if (!(key in y)) {
274
+ aStack.pop();
275
+ bStack.pop();
276
+ return false;
277
+ }
278
+ const symX = Object.getOwnPropertySymbols(x);
279
+ const symY = Object.getOwnPropertySymbols(y);
280
+ if (symX.length !== symY.length) {
281
+ aStack.pop();
282
+ bStack.pop();
283
+ return false;
284
+ }
285
+ for (const key of keysX) {
286
+ if (!eq(x[key], y[key])) {
287
+ aStack.pop();
288
+ bStack.pop();
289
+ return false;
290
+ }
291
+ }
292
+ for (const s of symX) {
293
+ if (!eq(x[s], y[s])) {
294
+ aStack.pop();
295
+ bStack.pop();
296
+ return false;
297
+ }
298
+ }
299
+ aStack.pop();
300
+ bStack.pop();
301
+ return true;
302
+ }
303
+ return eq(a, b);
35
304
  }
36
- exports.isDeepEqual = isDeepEqual;
37
- function deepDelete(data, path) {
38
- const clone = (0, lodash_1.cloneDeep)(data);
305
+ exports.isEqual = isEqual;
306
+ function deleteDeep(data, path) {
307
+ const clone = cloneDeep(data);
39
308
  if (!path || !(0, type_1.isString)(path))
40
309
  return clone;
41
- const paths = (0, lodash_1.filter)(path.split('.'), Boolean);
310
+ const paths = path.split('.').filter(Boolean);
42
311
  if (!paths.length)
43
312
  return clone;
44
313
  const key = paths.shift();
45
314
  if ((0, type_1.isObject)(clone)) {
46
315
  if (paths.length) {
47
- clone[key] = deepDelete(clone[key], paths.join('.'));
316
+ clone[key] = deleteDeep(clone[key], paths.join('.'));
48
317
  }
49
318
  else {
50
319
  delete clone[key];
@@ -53,7 +322,7 @@ function deepDelete(data, path) {
53
322
  }
54
323
  if ((0, type_1.isArray)(clone)) {
55
324
  if (paths.length) {
56
- clone[key] = deepDelete(clone[key], paths.join('.'));
325
+ clone[key] = deleteDeep(clone[key], paths.join('.'));
57
326
  }
58
327
  else {
59
328
  clone.splice(Number(key), 1);
@@ -62,136 +331,96 @@ function deepDelete(data, path) {
62
331
  }
63
332
  return clone;
64
333
  }
65
- exports.deepDelete = deepDelete;
334
+ exports.deleteDeep = deleteDeep;
66
335
  function insertArray(arr, index, item) {
67
336
  if (!Array.isArray(arr))
68
337
  return arr;
69
- const clone = (0, lodash_1.cloneDeep)(arr);
338
+ const clone = cloneDeep(arr);
70
339
  clone.splice(index, 0, item);
71
340
  return clone;
72
341
  }
73
342
  exports.insertArray = insertArray;
74
- function parseTemplateToOptions(source, template, opts) {
75
- var _a, _b;
76
- const keepBraces = !!(opts === null || opts === void 0 ? void 0 : opts.keepBraces);
77
- if (!template)
78
- return { text: '', items: [] };
79
- const normalizeOp = (ch) => (ch === '−' ? '-' : ch);
80
- const cleanLabel = (s) => (s !== null && s !== void 0 ? s : '').replace(/[()()]/g, '').trim();
81
- const valueTokens = [];
82
- const valRe = /\$\{\s*([^}]*)\s*\}/g;
83
- let m;
84
- while ((m = valRe.exec(template)) !== null) {
85
- valueTokens.push(m[1]);
86
- }
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 = [];
91
- for (let i = 0; i < len; i++) {
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 });
343
+ function get(obj, path, defaultValue) {
344
+ if (obj == null)
345
+ return defaultValue;
346
+ const toPath = (p) => {
347
+ var _a, _b, _c;
348
+ if (Array.isArray(p))
349
+ return p;
350
+ if (typeof p === 'number')
351
+ return [p];
352
+ const str = String(p);
353
+ const res = [];
354
+ const re = /\[(?:'([^']*)'|"([^"]*)"|([^'"\]]+))\]|([^.\[\]]+)/g;
355
+ let m;
356
+ while ((m = re.exec(str)) !== null) {
357
+ const part = (_c = (_b = (_a = m[1]) !== null && _a !== void 0 ? _a : m[2]) !== null && _b !== void 0 ? _b : m[3]) !== null && _c !== void 0 ? _c : m[4];
358
+ if (part === undefined)
359
+ continue;
360
+ if (/^-?\d+$/.test(part))
361
+ res.push(Number(part));
362
+ else
363
+ res.push(part);
364
+ }
365
+ return res;
366
+ };
367
+ const keys = toPath(path);
368
+ let cur = obj;
369
+ for (const key of keys) {
370
+ if (cur == null)
371
+ return defaultValue;
372
+ cur = cur[key];
96
373
  }
97
- let index = 0;
98
- const text = template.replace(/\$\{\s*([^}]*)\s*\}/g, (match, inner) => {
99
- const token = inner == null ? '' : String(inner).trim();
100
- const mappedLabel = items[index] ? items[index].label : '';
101
- index += 1;
102
- if (token === '' || token.toLowerCase() === 'null') {
103
- return keepBraces ? `\${${mappedLabel}}` : mappedLabel;
104
- }
105
- return match;
106
- });
107
- return { text, items };
374
+ return cur === undefined ? defaultValue : cur;
108
375
  }
109
- exports.parseTemplateToOptions = parseTemplateToOptions;
110
- function mergeTemplateToSource(source, template) {
111
- if (typeof source !== 'string' || typeof template !== 'string')
112
- return template;
113
- const regex = /\/\s*(?:\(\s*)?([^()\/-]+?)\s*-\s*([^()\/]+?)(?:\s*\))?/g;
114
- const leftOperands = [];
115
- let m;
116
- while ((m = regex.exec(source)) !== null) {
117
- leftOperands.push(m[1].trim());
376
+ exports.get = get;
377
+ function omit(obj, props) {
378
+ if (obj == null)
379
+ return {};
380
+ const keys = Array.isArray(props) ? props : [props];
381
+ let result = cloneDeep(obj);
382
+ const normalize = (p) => String(p)
383
+ .replace(/\[(?:'([^']*)'|"([^\"]*)"|([^\]]+))\]/g, (_m, g1, g2, g3) => { var _a; return '.' + ((_a = g1 !== null && g1 !== void 0 ? g1 : g2) !== null && _a !== void 0 ? _a : g3); })
384
+ .replace(/^\./, '');
385
+ for (const k of keys) {
386
+ if (k == null)
387
+ continue;
388
+ const path = normalize(k);
389
+ if (!path)
390
+ continue;
391
+ result = deleteDeep(result, path);
118
392
  }
119
- if (!leftOperands.length) {
120
- return template;
121
- }
122
- let idx = 0;
123
- const replaced = template.replace(/\$\{null\}|\bnull\b/g, (match) => {
124
- if (idx >= leftOperands.length) {
125
- return match;
126
- }
127
- const val = leftOperands[idx++];
128
- return val;
129
- });
130
- return replaced;
131
- }
132
- exports.mergeTemplateToSource = mergeTemplateToSource;
133
- function replaceTemplateFromOptions(template, options) {
134
- return (0, lodash_1.reduce)(options, (tpl, opt) => {
135
- const has = template.includes('${' + opt.value + '}');
136
- if (has)
137
- tpl;
138
- return tpl.replace('${' + opt.label + '}', '${' + opt.value + '}');
139
- }, (0, lodash_1.cloneDeep)(template));
393
+ return result;
140
394
  }
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;
151
- function parseOperatorsTokens(expr) {
152
- if (expr == null)
395
+ exports.omit = omit;
396
+ function insertBetweenImmutable(arr, filler) {
397
+ const n = arr.length;
398
+ if (n === 0)
153
399
  return [];
154
- return expr
155
- .split(/[+\-*/()]/)
156
- .map((s) => s.trim())
157
- .filter(Boolean);
158
- }
159
- exports.parseOperatorsTokens = parseOperatorsTokens;
160
- function escapeHtml(s) {
161
- return s
162
- .replace(/&/g, '&amp;')
163
- .replace(/</g, '&lt;')
164
- .replace(/>/g, '&gt;')
165
- .replace(/"/g, '&quot;')
166
- .replace(/'/g, '&#39;');
167
- }
168
- function highlightMatchesToHtml(text, terms, options) {
169
- if (text == null)
170
- return '';
171
- const tlist = (terms || []).filter(Boolean);
172
- if (!tlist.length)
173
- return escapeHtml(text);
174
- const tag = (options === null || options === void 0 ? void 0 : options.tag) || 'mark';
175
- const className = (options === null || options === void 0 ? void 0 : options.className) || 'samtools-highlight';
176
- const unique = Array.from(new Set(tlist)).sort((a, b) => b.length - a.length);
177
- const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
178
- const alt = unique.map(esc).join('|');
179
- const re = new RegExp(`(^|[^\\p{Script=Han}\\w])(${alt})(?=$|[^\\p{Script=Han}\\w])`, 'gu');
180
- let lastIndex = 0;
181
- let out = '';
182
- let m;
183
- while ((m = re.exec(text)) !== null) {
184
- const idx = m.index;
185
- const prefix = m[1] || '';
186
- const matched = m[2];
187
- if (idx > lastIndex)
188
- out += escapeHtml(text.slice(lastIndex, idx));
189
- out += escapeHtml(prefix);
190
- out += `<${tag} class="${escapeHtml(className)}">${escapeHtml(matched)}</${tag}>`;
191
- lastIndex = idx + prefix.length + matched.length;
400
+ if (n === 1)
401
+ return [arr[0]];
402
+ const out = [];
403
+ for (let i = 0; i < n; i++) {
404
+ out.push(arr[i]);
405
+ if (i !== n - 1)
406
+ out.push(filler(i));
192
407
  }
193
- if (lastIndex < text.length)
194
- out += escapeHtml(text.slice(lastIndex));
195
408
  return out;
196
409
  }
197
- exports.highlightMatchesToHtml = highlightMatchesToHtml;
410
+ exports.insertBetweenImmutable = insertBetweenImmutable;
411
+ function interchangeById(arr, idA, idB, idKey = 'id') {
412
+ const isPrimitive = typeof arr[0] !== 'object' || arr[0] === null;
413
+ const findIndex = (id) => isPrimitive
414
+ ? arr.indexOf(id)
415
+ : arr.findIndex((x) => x[idKey] === id);
416
+ const i = findIndex(idA);
417
+ const j = findIndex(idB);
418
+ if (i === -1 || j === -1 || i === j)
419
+ return arr.slice();
420
+ const copy = arr.slice();
421
+ const tmp = copy[i];
422
+ copy[i] = copy[j];
423
+ copy[j] = tmp;
424
+ return copy;
425
+ }
426
+ exports.interchangeById = interchangeById;
package/lib/transform.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.conversMenusPath = exports.isNotEmpty = exports.enumToOptions = exports.enumToList = exports.listToTree = void 0;
4
- const lodash_1 = require("lodash");
4
+ const _1 = require(".");
5
5
  const type_1 = require("./type");
6
6
  function schemaToObj(obj, schema) {
7
7
  if (!(0, type_1.isObject)(obj) || !schema || !(0, type_1.isObject)(schema) || (0, type_1.isEmpty)(schema))
@@ -51,7 +51,7 @@ function isNotEmpty(data) {
51
51
  if ((0, type_1.isEmpty)(data))
52
52
  return data;
53
53
  if ((0, type_1.isObject)(data)) {
54
- return (0, lodash_1.reduce)(Object.keys(data), (pre, key) => {
54
+ return Object.keys(data).reduce((pre, key) => {
55
55
  if ((0, type_1.isUndefined)(data[key]) || (0, type_1.isNull)(data[key]))
56
56
  return pre;
57
57
  if ((0, type_1.isObject)(data[key]) || (0, type_1.isArray)(data[key])) {
@@ -64,7 +64,7 @@ function isNotEmpty(data) {
64
64
  }, {});
65
65
  }
66
66
  if ((0, type_1.isArray)(data)) {
67
- return (0, lodash_1.map)(data, (item) => {
67
+ return data.map((item) => {
68
68
  if ((0, type_1.isObject)(item) || (0, type_1.isArray)(item))
69
69
  return isNotEmpty(item);
70
70
  return item;
@@ -76,11 +76,11 @@ exports.isNotEmpty = isNotEmpty;
76
76
  function conversMenusPath(data, key, child, prefix) {
77
77
  if (!data || !data.length)
78
78
  return data;
79
- return (0, lodash_1.map)(data, (item) => {
80
- const clone = (0, lodash_1.cloneDeep)(item);
81
- const children = (0, lodash_1.get)(clone, child, []);
82
- const mergePath = (0, lodash_1.filter)([prefix, item[key]], Boolean).join('/');
83
- const path = (0, lodash_1.filter)(mergePath.split('/'), Boolean).join('/');
79
+ return data.map((item) => {
80
+ const clone = (0, _1.cloneDeep)(item);
81
+ const children = (0, _1.get)(clone, child, []);
82
+ const mergePath = [prefix, item[key]].filter(Boolean).join('/');
83
+ const path = mergePath.split('/').filter(Boolean).join('/');
84
84
  clone[key] = path.startsWith('/') ? path : `/${path}`;
85
85
  if (children.length) {
86
86
  clone[child] = conversMenusPath(children, key, child, clone[key]);
package/lib/tree.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.slice = exports.toList = exports.deleteNodeFormKey = exports.updateNodeFormKey = exports.findNodeFormKey = void 0;
4
- const lodash_1 = require("lodash");
4
+ const tools_1 = require("./tools");
5
5
  function findNodeFormKey(key, nodes, id) {
6
6
  if (!id)
7
7
  return undefined;
8
- const tree = (0, lodash_1.cloneDeep)(nodes);
8
+ const tree = (0, tools_1.cloneDeep)(nodes);
9
9
  const queue = [...tree];
10
10
  while (queue.length > 0) {
11
11
  const node = queue.shift();
12
- const children = (0, lodash_1.get)(node, 'children', []);
12
+ const children = (0, tools_1.get)(node, 'children', []);
13
13
  if (node[key] === id) {
14
14
  return node;
15
15
  }
@@ -21,11 +21,11 @@ function findNodeFormKey(key, nodes, id) {
21
21
  }
22
22
  exports.findNodeFormKey = findNodeFormKey;
23
23
  function updateNodeFormKey(key, nodes, id, value) {
24
- const tree = (0, lodash_1.cloneDeep)(nodes);
24
+ const tree = (0, tools_1.cloneDeep)(nodes);
25
25
  const queue = [...tree];
26
26
  while (queue.length > 0) {
27
27
  const node = queue.shift();
28
- const children = (0, lodash_1.get)(node, 'children', []);
28
+ const children = (0, tools_1.get)(node, 'children', []);
29
29
  if (node[key] === id) {
30
30
  Object.assign(node, value);
31
31
  return tree;
@@ -38,14 +38,14 @@ function updateNodeFormKey(key, nodes, id, value) {
38
38
  }
39
39
  exports.updateNodeFormKey = updateNodeFormKey;
40
40
  function deleteNodeFormKey(key, nodes, id) {
41
- const tree = (0, lodash_1.cloneDeep)(nodes);
41
+ const tree = (0, tools_1.cloneDeep)(nodes);
42
42
  const queue = [...tree];
43
43
  while (queue.length > 0) {
44
44
  const node = queue.shift();
45
45
  if (node[key] === id) {
46
46
  return [];
47
47
  }
48
- if ((0, lodash_1.isArray)(node.children)) {
48
+ if (Array.isArray(node.children)) {
49
49
  const newChildren = [];
50
50
  for (let child of node.children) {
51
51
  const result = deleteNodeFormKey(key, [child], id);
@@ -55,7 +55,7 @@ function deleteNodeFormKey(key, nodes, id) {
55
55
  }
56
56
  node.children = newChildren;
57
57
  }
58
- if ((0, lodash_1.isArray)(node.children)) {
58
+ if (Array.isArray(node.children)) {
59
59
  queue.push(...node.children);
60
60
  }
61
61
  }
@@ -63,13 +63,13 @@ function deleteNodeFormKey(key, nodes, id) {
63
63
  }
64
64
  exports.deleteNodeFormKey = deleteNodeFormKey;
65
65
  function toList(nodes) {
66
- const tree = (0, lodash_1.cloneDeep)(nodes);
66
+ const tree = (0, tools_1.cloneDeep)(nodes);
67
67
  const result = [];
68
68
  const queue = [...tree];
69
69
  while (queue.length > 0) {
70
70
  const node = queue.shift();
71
- const children = (0, lodash_1.get)(node, 'children', []);
72
- result.push((0, lodash_1.omit)(node, 'children'));
71
+ const children = (0, tools_1.get)(node, 'children', []);
72
+ result.push((0, tools_1.omit)(node, 'children'));
73
73
  if (children.length) {
74
74
  queue.push(...children);
75
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soratani-code/samtools",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "",
5
5
  "typings": "lib/index.d.ts",
6
6
  "main": "lib/index.js",
@@ -29,9 +29,6 @@
29
29
  "url": "https://github.com/soratani/samtools/issues"
30
30
  },
31
31
  "homepage": "https://github.com/soratani/samtools#readme",
32
- "peerDependencies": {
33
- "lodash": "^4.17.21"
34
- },
35
32
  "devDependencies": {
36
33
  "@changesets/cli": "^2.26.1",
37
34
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -40,13 +37,11 @@
40
37
  "@rollup/plugin-typescript": "^11.1.6",
41
38
  "@types/enzyme": "^3.10.13",
42
39
  "@types/jest": "^29.5.2",
43
- "@types/lodash": "^4.17.13",
44
40
  "@types/node": "^20.2.5",
45
41
  "@types/platform": "^1.3.3",
46
42
  "enzyme": "^3.11.0",
47
43
  "jest": "^29.5.0",
48
44
  "jest-enzyme": "^7.1.2",
49
- "lodash": "^4.17.21",
50
45
  "rollup": "^4.14.2",
51
46
  "ts-jest": "^29.1.0",
52
47
  "ts-node": "^10.9.1",