@postxl/utils 0.1.8

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.
Files changed (57) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3 -0
  3. package/dist/DefaultMap.d.ts +11 -0
  4. package/dist/DefaultMap.js +26 -0
  5. package/dist/NestedMap.d.ts +16 -0
  6. package/dist/NestedMap.js +73 -0
  7. package/dist/TypedMapping.d.ts +26 -0
  8. package/dist/TypedMapping.js +33 -0
  9. package/dist/array.d.ts +6 -0
  10. package/dist/array.js +20 -0
  11. package/dist/async.d.ts +3 -0
  12. package/dist/async.js +40 -0
  13. package/dist/buffer.d.ts +4 -0
  14. package/dist/buffer.js +15 -0
  15. package/dist/check-port.d.ts +4 -0
  16. package/dist/check-port.js +27 -0
  17. package/dist/datetime.d.ts +4 -0
  18. package/dist/datetime.js +15 -0
  19. package/dist/dictionary.d.ts +8 -0
  20. package/dist/dictionary.js +44 -0
  21. package/dist/format.d.ts +1 -0
  22. package/dist/format.js +6 -0
  23. package/dist/group-by.d.ts +8 -0
  24. package/dist/group-by.js +65 -0
  25. package/dist/index.d.ts +25 -0
  26. package/dist/index.js +41 -0
  27. package/dist/is-object.d.ts +12 -0
  28. package/dist/is-object.js +24 -0
  29. package/dist/map.d.ts +22 -0
  30. package/dist/map.js +75 -0
  31. package/dist/omit.d.ts +4 -0
  32. package/dist/omit.js +10 -0
  33. package/dist/pagination.d.ts +6 -0
  34. package/dist/pagination.js +13 -0
  35. package/dist/random.d.ts +4 -0
  36. package/dist/random.js +16 -0
  37. package/dist/remove-secrets.d.ts +11 -0
  38. package/dist/remove-secrets.js +61 -0
  39. package/dist/remove-undefined.d.ts +9 -0
  40. package/dist/remove-undefined.js +21 -0
  41. package/dist/result.d.ts +24 -0
  42. package/dist/result.js +49 -0
  43. package/dist/sort.d.ts +17 -0
  44. package/dist/sort.js +63 -0
  45. package/dist/string-colors.d.ts +44 -0
  46. package/dist/string-colors.js +72 -0
  47. package/dist/string.d.ts +115 -0
  48. package/dist/string.js +322 -0
  49. package/dist/types.d.ts +78 -0
  50. package/dist/types.js +38 -0
  51. package/dist/uniq.d.ts +1 -0
  52. package/dist/uniq.js +15 -0
  53. package/dist/zod-excel.decoders.d.ts +151 -0
  54. package/dist/zod-excel.decoders.js +397 -0
  55. package/dist/zod.d.ts +8 -0
  56. package/dist/zod.js +17 -0
  57. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2020 @catamphetamine <purecatamphetamine@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # PXL Utils
2
+
3
+ `utils` is a selection of utility functions that are used in multiple packages and projects.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A map extension that returns a default value if the key is not found.
3
+ */
4
+ export declare class DefaultMap<Key, Value> extends Map<Key, Value> {
5
+ private readonly _default;
6
+ /**
7
+ * A function that returns the default value for the map.
8
+ */
9
+ constructor(_default: () => Value);
10
+ get(key: Key): Value;
11
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultMap = void 0;
4
+ /**
5
+ * A map extension that returns a default value if the key is not found.
6
+ */
7
+ class DefaultMap extends Map {
8
+ _default;
9
+ /**
10
+ * A function that returns the default value for the map.
11
+ */
12
+ constructor(_default) {
13
+ super();
14
+ this._default = _default;
15
+ }
16
+ get(key) {
17
+ const value = super.get(key);
18
+ if (value) {
19
+ return value;
20
+ }
21
+ const defaultValue = this._default();
22
+ this.set(key, defaultValue);
23
+ return defaultValue;
24
+ }
25
+ }
26
+ exports.DefaultMap = DefaultMap;
@@ -0,0 +1,16 @@
1
+ export declare class NestedMap<Key1, Key2, Item> {
2
+ private readonly getKey1;
3
+ private readonly getKey2;
4
+ private readonly _map;
5
+ constructor(getKey1: (item: Item) => Key1, getKey2: (item: Item) => Key2, items?: Item[]);
6
+ get(key1: Key1, key2: Key2): Item | undefined;
7
+ private getKeys;
8
+ set(item: Item): void;
9
+ delete(item: Item): void;
10
+ clear(): void;
11
+ get size(): number;
12
+ get keys(): Iterable<Key1>;
13
+ get values(): Iterable<Item>;
14
+ get entries(): Iterable<[Key1, Key2, Item]>;
15
+ get [Symbol.iterator](): Iterable<[Key1, Key2, Item]>;
16
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestedMap = void 0;
4
+ class NestedMap {
5
+ getKey1;
6
+ getKey2;
7
+ _map = new Map();
8
+ constructor(getKey1, getKey2, items = []) {
9
+ this.getKey1 = getKey1;
10
+ this.getKey2 = getKey2;
11
+ for (const item of items) {
12
+ this.set(item);
13
+ }
14
+ }
15
+ get(key1, key2) {
16
+ const map = this._map.get(key1);
17
+ if (!map) {
18
+ return undefined;
19
+ }
20
+ return map.get(key2);
21
+ }
22
+ getKeys(item) {
23
+ return [this.getKey1(item), this.getKey2(item)];
24
+ }
25
+ set(item) {
26
+ const [key1, key2] = this.getKeys(item);
27
+ let map = this._map.get(key1);
28
+ if (!map) {
29
+ map = new Map();
30
+ this._map.set(key1, map);
31
+ }
32
+ map.set(key2, item);
33
+ }
34
+ delete(item) {
35
+ const [key1, key2] = this.getKeys(item);
36
+ const map = this._map.get(key1);
37
+ if (!map) {
38
+ return;
39
+ }
40
+ map.delete(key2);
41
+ }
42
+ clear() {
43
+ this._map.clear();
44
+ }
45
+ get size() {
46
+ return Array.from(this._map.values()).reduce((sum, map) => sum + map.size, 0);
47
+ }
48
+ get keys() {
49
+ return this._map.keys();
50
+ }
51
+ get values() {
52
+ const values = [];
53
+ for (const map of this._map.values()) {
54
+ for (const value of map.values()) {
55
+ values.push(value);
56
+ }
57
+ }
58
+ return values;
59
+ }
60
+ get entries() {
61
+ const entries = [];
62
+ for (const [key1, map] of this._map.entries()) {
63
+ for (const [key2, value] of map.entries()) {
64
+ entries.push([key1, key2, value]);
65
+ }
66
+ }
67
+ return entries;
68
+ }
69
+ get [Symbol.iterator]() {
70
+ return this.entries;
71
+ }
72
+ }
73
+ exports.NestedMap = NestedMap;
@@ -0,0 +1,26 @@
1
+ type IdentifiersBase = Record<string, string>;
2
+ type Mapping<T> = Map<T, T>;
3
+ /**
4
+ * A map of typed mappings.
5
+ */
6
+ export declare class TypedMapping<Identifiers extends IdentifiersBase> {
7
+ private mappings;
8
+ constructor(mappings?: {
9
+ [Model in keyof Identifiers]?: Mapping<Identifiers[Model]>;
10
+ });
11
+ /**
12
+ * Creates a new mapping from the original id to the new id.
13
+ */
14
+ set<Model extends keyof Identifiers>({ model, id }: {
15
+ model: Model;
16
+ id: Identifiers[Model];
17
+ }, newId: Identifiers[Model]): this;
18
+ /**
19
+ * Returns the id if there exists a mapping, otherwise returns the original id.
20
+ */
21
+ get<Model extends keyof Identifiers>({ model, id, }: {
22
+ model: Model;
23
+ id: Identifiers[Model];
24
+ }): Identifiers[Model];
25
+ }
26
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypedMapping = void 0;
4
+ /**
5
+ * A map of typed mappings.
6
+ */
7
+ class TypedMapping {
8
+ mappings;
9
+ constructor(mappings = {}) {
10
+ this.mappings = mappings;
11
+ }
12
+ /**
13
+ * Creates a new mapping from the original id to the new id.
14
+ */
15
+ set({ model, id }, newId) {
16
+ if (!this.mappings[model]) {
17
+ this.mappings[model] = new Map();
18
+ }
19
+ this.mappings[model].set(id, newId);
20
+ return this;
21
+ }
22
+ /**
23
+ * Returns the id if there exists a mapping, otherwise returns the original id.
24
+ */
25
+ get({ model, id, }) {
26
+ const mapping = this.mappings[model]?.get(id);
27
+ if (!mapping) {
28
+ return id;
29
+ }
30
+ return mapping;
31
+ }
32
+ }
33
+ exports.TypedMapping = TypedMapping;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adds a value to a sorted array and keeps the array sorted.
3
+ *
4
+ * O(n)
5
+ */
6
+ export declare function addAndSort<T>(arr: T[], value: T, predicate: (t: T) => number): T[];
package/dist/array.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAndSort = addAndSort;
4
+ /**
5
+ * Adds a value to a sorted array and keeps the array sorted.
6
+ *
7
+ * O(n)
8
+ */
9
+ function addAndSort(arr, value, predicate) {
10
+ arr.push(value);
11
+ let i = arr.length - 1;
12
+ const item = arr[i];
13
+ const order = predicate(item);
14
+ while (i > 0 && order < predicate(arr[i - 1])) {
15
+ arr[i] = arr[i - 1];
16
+ i -= 1;
17
+ }
18
+ arr[i] = item;
19
+ return arr;
20
+ }
@@ -0,0 +1,3 @@
1
+ type AsyncMapFn<T, R> = (item: T, index: number) => Promise<R>;
2
+ export declare function mapLimit<T, R>(arr: T[], iterator: AsyncMapFn<T, R>, limit?: number): Promise<(R | undefined)[]>;
3
+ export {};
package/dist/async.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ //Credit: https://codeburst.io/async-map-with-limited-parallelism-in-node-js-2b91bd47af70
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.mapLimit = mapLimit;
5
+ const defaultConcurrency = 5;
6
+ // async maps over all values of an array but limits the number of concurrent operations
7
+ async function mapLimit(arr, iterator, limit = defaultConcurrency) {
8
+ const result = [];
9
+ if (arr.length === 0) {
10
+ return result;
11
+ }
12
+ const generator = arrayGenerator(arr);
13
+ limit = Math.min(limit, arr.length);
14
+ const workers = new Array(limit);
15
+ for (let i = 0; i < limit; i++) {
16
+ workers.push(worker(i, generator, iterator, result));
17
+ }
18
+ await Promise.all(workers);
19
+ return result;
20
+ }
21
+ function* arrayGenerator(array) {
22
+ for (let index = 0; index < array.length; index++) {
23
+ const currentValue = array[index];
24
+ yield [currentValue, index];
25
+ }
26
+ }
27
+ async function worker(id, gen, mapFn, result) {
28
+ for (const [currentValue, index] of gen) {
29
+ result[index] = undefined;
30
+ if (currentValue === undefined) {
31
+ return;
32
+ }
33
+ try {
34
+ result[index] = await mapFn(currentValue, index);
35
+ }
36
+ catch (e) {
37
+ console.error(`Worker ${id} --- index ${index} item ${JSON.stringify(currentValue)} failed`, e);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Compares two string or buffer values for equality.
3
+ */
4
+ export declare function equals(a: string | Buffer, b: string | Buffer): boolean;
package/dist/buffer.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.equals = equals;
4
+ /**
5
+ * Compares two string or buffer values for equality.
6
+ */
7
+ function equals(a, b) {
8
+ if (typeof a === 'string' && typeof b === 'string') {
9
+ return a === b;
10
+ }
11
+ if (Buffer.isBuffer(a) && Buffer.isBuffer(b)) {
12
+ return a.equals(b);
13
+ }
14
+ return false;
15
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Checks if a port is available.
3
+ */
4
+ export declare function checkPortAvailability(port: number): Promise<boolean>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.checkPortAvailability = checkPortAvailability;
7
+ const net_1 = __importDefault(require("net"));
8
+ /**
9
+ * Checks if a port is available.
10
+ */
11
+ async function checkPortAvailability(port) {
12
+ return new Promise((resolve) => {
13
+ const tester = net_1.default.createConnection({ port }, () => {
14
+ // Port can be connected to, so something is listening on it
15
+ tester.destroy();
16
+ resolve(false);
17
+ });
18
+ //Port cannot be connected to, so it is available
19
+ tester.on('error', () => {
20
+ resolve(true);
21
+ });
22
+ // Port is available
23
+ tester.on('close', () => {
24
+ resolve(false);
25
+ });
26
+ });
27
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * returns the default time stamp in format YYMMDD HHMM
3
+ */
4
+ export declare function timeStamp(): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.timeStamp = timeStamp;
4
+ /**
5
+ * returns the default time stamp in format YYMMDD HHMM
6
+ */
7
+ function timeStamp() {
8
+ const date = new Date();
9
+ const year = date.getFullYear().toString().slice(-2);
10
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
11
+ const day = date.getDate().toString().padStart(2, '0');
12
+ const hour = date.getHours().toString().padStart(2, '0');
13
+ const minute = date.getMinutes().toString().padStart(2, '0');
14
+ return `${year}${month}${day} ${hour}${minute}`;
15
+ }
@@ -0,0 +1,8 @@
1
+ export type Dictionary<Value, Key extends string = string> = Record<Key, Value>;
2
+ export declare function toDict<Value, Key extends string = string>(data: Value[], keyFn: (item: Value) => Key): Dictionary<Value, Key>;
3
+ export declare function idToDict<T extends {
4
+ id: string | number;
5
+ }>(data: T[]): Dictionary<T>;
6
+ export declare function mapDict<S, T>(dict: Dictionary<S>, predicate: (item: S) => T): Dictionary<T>;
7
+ export declare function filterDict<T>(dict: Dictionary<T>, predicate: (item: T) => boolean): Dictionary<T>;
8
+ export declare function dictGetAndAssert<Key extends string, Value>(dict: Dictionary<Value>, key: Key): NonNullable<Value>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDict = toDict;
4
+ exports.idToDict = idToDict;
5
+ exports.mapDict = mapDict;
6
+ exports.filterDict = filterDict;
7
+ exports.dictGetAndAssert = dictGetAndAssert;
8
+ function toDict(data, keyFn) {
9
+ const result = {};
10
+ for (const item of data) {
11
+ result[keyFn(item)] = item;
12
+ }
13
+ return result;
14
+ }
15
+ function idToDict(data) {
16
+ const result = {};
17
+ for (const item of data) {
18
+ result[item.id.toString()] = item;
19
+ }
20
+ return result;
21
+ }
22
+ function mapDict(dict, predicate) {
23
+ const result = {};
24
+ for (const [key, value] of Object.entries(dict)) {
25
+ result[key] = predicate(value);
26
+ }
27
+ return result;
28
+ }
29
+ function filterDict(dict, predicate) {
30
+ const result = {};
31
+ for (const [key, value] of Object.entries(dict)) {
32
+ if (predicate(value)) {
33
+ result[key] = value;
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+ function dictGetAndAssert(dict, key) {
39
+ const value = dict[key];
40
+ if (value === null || value === undefined) {
41
+ throw new Error(`Key ${key} not found`);
42
+ }
43
+ return value;
44
+ }
@@ -0,0 +1 @@
1
+ export declare function format(n: number, locale?: string): string;
package/dist/format.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.format = format;
4
+ function format(n, locale = 'en-US') {
5
+ return new Intl.NumberFormat(locale).format(n);
6
+ }
@@ -0,0 +1,8 @@
1
+ export declare const groupBy: <T, U extends string | number>(predicate: (x: T) => U, items: T[]) => Partial<Record<U, T[]>>;
2
+ export declare const groupByCurried: <T, U extends string | number>(predicate: (x: T) => U) => ((items: T[]) => Partial<Record<U, T[]>>);
3
+ export declare const groupByToDict: <Id extends string | number, WithId extends {
4
+ id: Id;
5
+ }, GroupId extends string | number>(predicate: (x: WithId) => GroupId, items: WithId[]) => Partial<Record<GroupId, Record<Id, WithId>>>;
6
+ export declare const groupByToMap: <T extends {
7
+ id: ItemID;
8
+ }, ItemID extends string | number, GroupID extends string | number>(getGroupId: (x: T) => GroupID, items: T[]) => Map<GroupID, Map<ItemID, T>>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupByToMap = exports.groupByToDict = exports.groupByCurried = exports.groupBy = void 0;
4
+ const groupBy = (predicate, items) => {
5
+ const result = {};
6
+ for (const item of items) {
7
+ const key = predicate(item);
8
+ const group = result[key];
9
+ if (group === undefined) {
10
+ result[key] = [item];
11
+ }
12
+ else {
13
+ group.push(item);
14
+ }
15
+ }
16
+ return result;
17
+ };
18
+ exports.groupBy = groupBy;
19
+ const groupByCurried = (predicate) => {
20
+ const result = {};
21
+ return (items) => {
22
+ for (const item of items) {
23
+ const key = predicate(item);
24
+ const group = result[key];
25
+ if (group === undefined) {
26
+ result[key] = [item];
27
+ }
28
+ else {
29
+ group.push(item);
30
+ }
31
+ }
32
+ return result;
33
+ };
34
+ };
35
+ exports.groupByCurried = groupByCurried;
36
+ const groupByToDict = (predicate, items) => {
37
+ const result = {};
38
+ for (const item of items) {
39
+ const key = predicate(item);
40
+ const group = result[key];
41
+ if (group === undefined) {
42
+ result[key] = { [item.id]: item };
43
+ }
44
+ else {
45
+ group[item.id] = item;
46
+ }
47
+ }
48
+ return result;
49
+ };
50
+ exports.groupByToDict = groupByToDict;
51
+ const groupByToMap = (getGroupId, items) => {
52
+ const result = new Map();
53
+ for (const item of items) {
54
+ const groupId = getGroupId(item);
55
+ if (!result.has(groupId)) {
56
+ result.set(groupId, new Map());
57
+ }
58
+ const group = result.get(groupId);
59
+ if (group !== undefined) {
60
+ group.set(item.id, item);
61
+ }
62
+ }
63
+ return result;
64
+ };
65
+ exports.groupByToMap = groupByToMap;
@@ -0,0 +1,25 @@
1
+ export * from './DefaultMap';
2
+ export * from './NestedMap';
3
+ export * from './TypedMapping';
4
+ export * from './array';
5
+ export * from './async';
6
+ export * from './buffer';
7
+ export * from './check-port';
8
+ export * from './datetime';
9
+ export * from './dictionary';
10
+ export * from './format';
11
+ export * from './group-by';
12
+ export * from './map';
13
+ export * from './omit';
14
+ export * from './pagination';
15
+ export * from './random';
16
+ export * from './remove-secrets';
17
+ export * from './remove-undefined';
18
+ export * from './result';
19
+ export * from './sort';
20
+ export * from './string-colors';
21
+ export * from './string';
22
+ export * from './types';
23
+ export * from './uniq';
24
+ export * from './zod';
25
+ export * from './zod-excel.decoders';
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./DefaultMap"), exports);
18
+ __exportStar(require("./NestedMap"), exports);
19
+ __exportStar(require("./TypedMapping"), exports);
20
+ __exportStar(require("./array"), exports);
21
+ __exportStar(require("./async"), exports);
22
+ __exportStar(require("./buffer"), exports);
23
+ __exportStar(require("./check-port"), exports);
24
+ __exportStar(require("./datetime"), exports);
25
+ __exportStar(require("./dictionary"), exports);
26
+ __exportStar(require("./format"), exports);
27
+ __exportStar(require("./group-by"), exports);
28
+ __exportStar(require("./map"), exports);
29
+ __exportStar(require("./omit"), exports);
30
+ __exportStar(require("./pagination"), exports);
31
+ __exportStar(require("./random"), exports);
32
+ __exportStar(require("./remove-secrets"), exports);
33
+ __exportStar(require("./remove-undefined"), exports);
34
+ __exportStar(require("./result"), exports);
35
+ __exportStar(require("./sort"), exports);
36
+ __exportStar(require("./string-colors"), exports);
37
+ __exportStar(require("./string"), exports);
38
+ __exportStar(require("./types"), exports);
39
+ __exportStar(require("./uniq"), exports);
40
+ __exportStar(require("./zod"), exports);
41
+ __exportStar(require("./zod-excel.decoders"), exports);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns true if the value is an object, false otherwise.
3
+ */
4
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
5
+ /**
6
+ * Only returns true for plain objects, not for classes or functions
7
+ */
8
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
9
+ /**
10
+ * Returns true if the value is a function, false otherwise.
11
+ */
12
+ export declare function isFunction(value: unknown): value is Function;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = isObject;
4
+ exports.isPlainObject = isPlainObject;
5
+ exports.isFunction = isFunction;
6
+ /**
7
+ * Returns true if the value is an object, false otherwise.
8
+ */
9
+ function isObject(value) {
10
+ return typeof value === 'object' && value !== null;
11
+ }
12
+ /**
13
+ * Only returns true for plain objects, not for classes or functions
14
+ */
15
+ function isPlainObject(value) {
16
+ return value !== null && typeof value === 'object' && value.constructor === Object;
17
+ }
18
+ /**
19
+ * Returns true if the value is a function, false otherwise.
20
+ */
21
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
22
+ function isFunction(value) {
23
+ return typeof value === 'function';
24
+ }
package/dist/map.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export declare function mapMap<Key, ValueFrom, ValueTo>(map: Map<Key, ValueFrom>, predicate: (item: ValueFrom, key: Key) => ValueTo): Map<Key, ValueTo>;
2
+ export declare function mapMapValues<Key, ValueFrom, ValueTo>(map: Map<Key, ValueFrom>, predicate: (item: ValueFrom, key: Key) => ValueTo): ValueTo[];
3
+ /**
4
+ *
5
+ */
6
+ export declare function mapMapKeyValues<KeyFrom, KeyTo, ValueFrom, ValueTo>(map: Map<KeyFrom, ValueFrom>, keyPredicate: (key: KeyFrom, value: ValueFrom) => KeyTo, valuePredicate: (item: ValueFrom, key: KeyFrom) => ValueTo): Map<KeyTo, ValueTo>;
7
+ /**
8
+ * Maps keys of a map.
9
+ */
10
+ export declare function mapMapKeys<KeyFrom, KeyTo, Value>(map: Map<KeyFrom, Value>, keyPredicate: (key: KeyFrom, value: Value) => KeyTo): Map<KeyTo, Value>;
11
+ /**
12
+ * Filters values from a map.
13
+ */
14
+ export declare function filterMap<Key, Value>(map: Map<Key, Value>, predicate: (item: Value, key: Key) => boolean): Map<Key, Value>;
15
+ /**
16
+ * Gets a value from a map and asserts that it exists.
17
+ */
18
+ export declare function mapGetAndAssert<Key, Value>(map: Map<Key, Value>, key: Key): Value;
19
+ /**
20
+ * Converts a map to a dictionary.
21
+ */
22
+ export declare function mapToDict<Key extends string | number, Value>(map: Map<Key, Value>): Record<Key, Value>;