@nemigo/helpers 0.7.0 → 0.7.1

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CanBeArray } from "./types.js";
1
+ import type { CanBeArray, CanBeReadonly } from "./types.js";
2
2
  /**
3
3
  * Добавляет ведущие нули к числу для достижения указанной длины
4
4
  *
@@ -32,11 +32,11 @@ export interface Partition<T> {
32
32
  /**
33
33
  * Разделяет массив на два по условию
34
34
  */
35
- export declare const partition: <T>(arr: T[], filter: (item: T) => boolean, initial?: Partition<T>) => Partition<T>;
35
+ export declare const partition: <T>(arr: CanBeReadonly<T>, filter: (item: T) => boolean, initial?: Partition<T>) => Partition<T>;
36
36
  /**
37
37
  * Удаляет `null` и `undefined` и оставляет только уникальные строки
38
38
  */
39
- export declare const setify: (arr: (string | undefined | null)[]) => string[];
39
+ export declare const setify: (arr: CanBeReadonly<string | undefined | null>) => string[];
40
40
  /**
41
41
  * Удаляет дубликаты объектов из массива на основе указанного ключа
42
42
  *
@@ -46,5 +46,5 @@ export declare const setify: (arr: (string | undefined | null)[]) => string[];
46
46
  * @param {K} [key="id"] - Ключ, по которому будут удаляться дубликаты
47
47
  * @returns {T[]} Новый массив без дубликатов
48
48
  */
49
- export declare const unify: <T, K extends keyof T>(arr: T[], key?: K) => T[];
49
+ export declare const unify: <T, K extends keyof T>(arr: CanBeReadonly<T>, key?: K) => T[];
50
50
  export declare const useConditionGuard: (condition: unknown, ...args: any[]) => boolean;
package/dist/index.js CHANGED
@@ -23,12 +23,16 @@ export const isSameType = (a, b) => Object.prototype.toString.call(a) === Object
23
23
  /**
24
24
  * Разделяет массив на два по условию
25
25
  */
26
- export const partition = (arr, filter, initial = { result: [], excluded: [] }) => arr.reduce((acc, item) => (acc[filter(item) ? "result" : "excluded"].push(item), acc), initial);
26
+ export const partition = (arr, filter, initial = { result: [], excluded: [] }) =>
27
+ // @ts-expect-error <оно себя неадекватно ведёт>
28
+ arr.reduce((acc, item) => (acc[filter(item) ? "result" : "excluded"].push(item), acc), initial);
27
29
  //...
28
30
  /**
29
31
  * Удаляет `null` и `undefined` и оставляет только уникальные строки
30
32
  */
31
- export const setify = (arr) => [...new Set(arr.filter((item) => typeof item === "string"))];
33
+ export const setify = (arr) =>
34
+ // @ts-expect-error <оно себя неадекватно ведёт>
35
+ [...new Set(arr.filter((item) => typeof item === "string"))];
32
36
  /**
33
37
  * Удаляет дубликаты объектов из массива на основе указанного ключа
34
38
  *
@@ -38,7 +42,9 @@ export const setify = (arr) => [...new Set(arr.filter((item) => typeof item ===
38
42
  * @param {K} [key="id"] - Ключ, по которому будут удаляться дубликаты
39
43
  * @returns {T[]} Новый массив без дубликатов
40
44
  */
41
- export const unify = (arr, key = "id") => [...new Map(arr.map((item) => [item[key], item])).values()];
45
+ export const unify = (arr, key = "id") =>
46
+ // @ts-expect-error <оно себя неадекватно ведёт>
47
+ [...new Map(arr.map((item) => [item[key], item])).values()];
42
48
  //...
43
49
  export const useConditionGuard = (condition, ...args) => {
44
50
  switch (typeof condition) {
package/dist/types.d.ts CHANGED
@@ -29,6 +29,10 @@ export type CanBeNullable<T = unknown> = T | null | undefined;
29
29
  * Значение может быть массивом или одиночным элементом
30
30
  */
31
31
  export type CanBeArray<T = unknown> = T | T[];
32
+ /**
33
+ * Массив может быть readonly
34
+ */
35
+ export type CanBeReadonly<T = unknown> = readonly T[] | T[];
32
36
  /**
33
37
  * Значение может быть промиссом
34
38
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",