@soratani-code/samtools 1.5.4 → 1.5.5
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 +2 -0
- package/lib/tools.js +32 -1
- package/package.json +1 -1
package/lib/tools.d.ts
CHANGED
|
@@ -21,3 +21,5 @@ export declare function highlightMatchesToHtml(text: string | null | undefined,
|
|
|
21
21
|
tag?: string;
|
|
22
22
|
className?: string;
|
|
23
23
|
}): string;
|
|
24
|
+
export declare function insertBetweenImmutable<D = any>(arr: D[], filler: (index: number) => D): D[];
|
|
25
|
+
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,6 +1,6 @@
|
|
|
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;
|
|
3
|
+
exports.interchangeById = exports.insertBetweenImmutable = exports.highlightMatchesToHtml = exports.parseOperatorsTokens = 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) {
|
|
@@ -195,3 +195,34 @@ function highlightMatchesToHtml(text, terms, options) {
|
|
|
195
195
|
return out;
|
|
196
196
|
}
|
|
197
197
|
exports.highlightMatchesToHtml = highlightMatchesToHtml;
|
|
198
|
+
function insertBetweenImmutable(arr, filler) {
|
|
199
|
+
const n = arr.length;
|
|
200
|
+
if (n === 0)
|
|
201
|
+
return [];
|
|
202
|
+
if (n === 1)
|
|
203
|
+
return [arr[0]];
|
|
204
|
+
const out = [];
|
|
205
|
+
for (let i = 0; i < n; i++) {
|
|
206
|
+
out.push(arr[i]);
|
|
207
|
+
if (i !== n - 1)
|
|
208
|
+
out.push(filler(i));
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
exports.insertBetweenImmutable = insertBetweenImmutable;
|
|
213
|
+
function interchangeById(arr, idA, idB, idKey = 'id') {
|
|
214
|
+
const isPrimitive = typeof arr[0] !== 'object' || arr[0] === null;
|
|
215
|
+
const findIndex = (id) => isPrimitive
|
|
216
|
+
? arr.indexOf(id)
|
|
217
|
+
: arr.findIndex((x) => x[idKey] === id);
|
|
218
|
+
const i = findIndex(idA);
|
|
219
|
+
const j = findIndex(idB);
|
|
220
|
+
if (i === -1 || j === -1 || i === j)
|
|
221
|
+
return arr.slice();
|
|
222
|
+
const copy = arr.slice();
|
|
223
|
+
const tmp = copy[i];
|
|
224
|
+
copy[i] = copy[j];
|
|
225
|
+
copy[j] = tmp;
|
|
226
|
+
return copy;
|
|
227
|
+
}
|
|
228
|
+
exports.interchangeById = interchangeById;
|