@soratani-code/samtools 1.5.8 → 1.5.9

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/set.d.ts CHANGED
@@ -2,3 +2,4 @@ export declare function unrepetition<D = any>(array: D[], index?: string): D[];
2
2
  export declare function intersection<D = any>(array1: D[], array2: D[]): D[];
3
3
  export declare function union<D = any>(array1: D[], array2: D[]): D[];
4
4
  export declare function difference<D = any>(array1: D[], array2: D[]): D[];
5
+ export declare function insertByIndex<T>(arr: T[], item: T | T[], index: number, position?: 'before' | 'after'): T[];
package/lib/set.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.difference = exports.union = exports.intersection = exports.unrepetition = void 0;
3
+ exports.insertByIndex = exports.difference = exports.union = exports.intersection = exports.unrepetition = void 0;
4
+ const tools_1 = require("./tools");
4
5
  const type_1 = require("./type");
5
6
  function unrepetition(array, index) {
6
7
  if ((0, type_1.isString)(index)) {
@@ -31,3 +32,17 @@ function difference(array1, array2) {
31
32
  return un.filter((u) => !int.some(i => i === u));
32
33
  }
33
34
  exports.difference = difference;
35
+ function insertByIndex(arr, item, index, position = 'after') {
36
+ const items = Array.isArray(item) ? item : [item];
37
+ if (arr.length === 0) {
38
+ return [...items];
39
+ }
40
+ const normalizedIndex = (0, tools_1.clamp)(Math.trunc(index), 0, arr.length - 1);
41
+ const insertIndex = position === 'before' ? normalizedIndex : normalizedIndex + 1;
42
+ return [
43
+ ...arr.slice(0, insertIndex),
44
+ ...items,
45
+ ...arr.slice(insertIndex),
46
+ ];
47
+ }
48
+ exports.insertByIndex = insertByIndex;
package/lib/tools.d.ts CHANGED
@@ -6,3 +6,4 @@ export declare function get(obj: any, path: string | Array<string | number> | nu
6
6
  export declare function omit<T extends any = any>(obj: T | null | undefined, props: string | Array<string>): Partial<T>;
7
7
  export declare function insertBetweenImmutable<D = any>(arr: D[], filler: (index: number) => D): D[];
8
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)[];
9
+ export declare function clamp(n: any, min2: any, max2: any): any;
package/lib/tools.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interchangeById = exports.insertBetweenImmutable = exports.omit = exports.get = exports.insertArray = exports.deleteDeep = exports.isEqual = exports.cloneDeep = void 0;
3
+ exports.clamp = exports.interchangeById = exports.insertBetweenImmutable = exports.omit = exports.get = exports.insertArray = exports.deleteDeep = exports.isEqual = exports.cloneDeep = void 0;
4
4
  const type_1 = require("./type");
5
5
  function cloneDeep(value) {
6
6
  if (value === null || typeof value !== 'object')
@@ -424,3 +424,10 @@ function interchangeById(arr, idA, idB, idKey = 'id') {
424
424
  return copy;
425
425
  }
426
426
  exports.interchangeById = interchangeById;
427
+ function clamp(n, min2, max2) {
428
+ if (max2 != null && min2 != null && min2 > max2) {
429
+ throw new Error("invalid clamp range");
430
+ }
431
+ return max2 != null && n > max2 ? max2 : min2 != null && n < min2 ? min2 : n;
432
+ }
433
+ exports.clamp = clamp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soratani-code/samtools",
3
- "version": "1.5.8",
3
+ "version": "1.5.9",
4
4
  "description": "",
5
5
  "typings": "lib/index.d.ts",
6
6
  "main": "lib/index.js",