@dereekb/util 11.0.21 → 11.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util",
3
- "version": "11.0.21",
3
+ "version": "11.1.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -1,3 +1,4 @@
1
+ import { type IterableOrValue } from '../iterable/iterable';
1
2
  import { type Maybe } from '../value/maybe.type';
2
3
  export type EmptyArray = never[];
3
4
  export type ArrayOrValue<T> = T | T[];
@@ -118,3 +119,9 @@ export declare function forEachWithArray<T>(array: Maybe<ArrayOrValue<T>>, forEa
118
119
  * @returns
119
120
  */
120
121
  export declare function countAllInNestedArray<T>(array: T[][]): number;
122
+ /**
123
+ * Creates a copy of the array with the items at the specified indexes removed.
124
+ *
125
+ * @param array
126
+ */
127
+ export declare function removeValuesAtIndexesFromArrayCopy<T>(array: T[], removeIndexes: IterableOrValue<number>): T[];
@@ -8,13 +8,23 @@ export declare function reduceNumbersWithAddFn(emptyArrayValue?: number): (array
8
8
  export declare function reduceNumbers(reduceFn: (a: number, b: number) => number, array: number[], emptyArrayValue?: number): number | undefined;
9
9
  export declare function reduceNumbersFn(reduceFn: (a: number, b: number) => number): (array: number[]) => number | undefined;
10
10
  export declare function reduceNumbersFn<D extends number>(reduceFn: (a: number, b: number) => number, emptyArrayValue?: D): (array: number[]) => number | D;
11
+ /**
12
+ * Exclusive end value used by range().
13
+ */
14
+ export type RangeInputEndValue = number;
11
15
  /**
12
16
  * Input for range()
13
17
  */
14
- export type RangeInputObject = {
15
- start?: number;
16
- end: number;
17
- };
18
+ export interface RangeInputObject {
19
+ /**
20
+ * Start value. Defaults to 0 if not defined.
21
+ */
22
+ readonly start?: number;
23
+ /**
24
+ * The exclusive end value.
25
+ */
26
+ readonly end: RangeInputEndValue;
27
+ }
18
28
  export type RangeInput = number | RangeInputObject | IndexRange;
19
29
  /**
20
30
  * Generates an array containing the range of numbers specified.
@@ -24,4 +34,4 @@ export type RangeInput = number | RangeInputObject | IndexRange;
24
34
  * @param param0
25
35
  * @returns
26
36
  */
27
- export declare function range(input: RangeInput, inputEnd?: number): number[];
37
+ export declare function range(input: RangeInput, inputEnd?: RangeInputEndValue): number[];
@@ -1,18 +1,24 @@
1
1
  import { type Maybe, type MaybeNot } from '../value/maybe.type';
2
+ /**
3
+ * Function that takes the input and returns an array with no Maybe values.
4
+ */
5
+ export type FilterMaybeArrayFunction<T> = (value: Maybe<Maybe<T[]>>) => T[];
6
+ export type UniversalFilterMaybeArrayFunction = <T>(values: Maybe<Maybe<T>[]>) => T[];
7
+ export declare function filterMaybeArrayFunction<T>(filterFn: Parameters<Array<Maybe<T>>['filter']>[0]): FilterMaybeArrayFunction<T>;
2
8
  /**
3
9
  * Filters all maybe values from the input array. If a maybe value is input, returns an empty array.
4
10
  *
5
11
  * @param values
6
12
  * @returns
7
13
  */
8
- export declare function filterMaybeValues<T>(values: Maybe<Maybe<T>[]>): T[];
14
+ export declare const filterMaybeArrayValues: UniversalFilterMaybeArrayFunction;
9
15
  /**
10
16
  * Filters all empty and maybe values from the input array. If a maybe value is input, returns an empty array.
11
17
  *
12
18
  * @param values
13
19
  * @returns
14
20
  */
15
- export declare function filterEmptyValues<T>(values: Maybe<Maybe<T>[]>): T[];
21
+ export declare const filterEmptyArrayValues: UniversalFilterMaybeArrayFunction;
16
22
  /**
17
23
  * Checks whether or not all values are MaybeNot values.
18
24
  *
@@ -27,3 +33,21 @@ export declare function allValuesAreMaybeNot<T>(values: Maybe<T>[]): values is M
27
33
  * @returns
28
34
  */
29
35
  export declare function allValuesAreNotMaybe<T>(values: Maybe<T>[]): values is T[];
36
+ /**
37
+ * Filters all maybe values from the input array. If a maybe value is input, returns an empty array.
38
+ *
39
+ * @param values
40
+ * @returns
41
+ *
42
+ * @deprecated use filterMaybeArrayValues instead.
43
+ */
44
+ export declare const filterMaybeValues: UniversalFilterMaybeArrayFunction;
45
+ /**
46
+ * Filters all empty and maybe values from the input array. If a maybe value is input, returns an empty array.
47
+ *
48
+ * @param values
49
+ * @returns
50
+ *
51
+ * @deprecated use filterEmptyArrayValues instead.
52
+ */
53
+ export declare const filterEmptyValues: UniversalFilterMaybeArrayFunction;
@@ -62,6 +62,9 @@ export type BitwiseObjectDencoder<T extends object> = BitwiseObjectEncoder<T> &
62
62
  export interface BitwiseObjectDencoderConfig<T extends object, D extends BitwiseEncodedSetIndex = BitwiseEncodedSetIndex> {
63
63
  readonly toSetFunction: BitwiseObjectToSetFunction<T, D>;
64
64
  readonly fromSetFunction: BitwiseObjectFromSetFunction<T, D>;
65
+ /**
66
+ * The max index, exclusive
67
+ */
65
68
  readonly maxIndex?: number;
66
69
  }
67
70
  export declare function bitwiseObjectDencoder<T extends object, D extends BitwiseEncodedSetIndex = BitwiseEncodedSetIndex>(config: BitwiseObjectDencoderConfig<T, D>): BitwiseObjectDencoder<T>;
@@ -2,7 +2,11 @@ import { type FieldOfType } from '../key';
2
2
  import { type SetIncludesMode } from '../set/set.mode';
3
3
  import { type KeyAsString } from '../type';
4
4
  /**
5
- * Key of an object.
5
+ * Any valid Plain-old Javascript Object key.
6
+ */
7
+ export type POJOKey = string | number | symbol;
8
+ /**
9
+ * String key of an object.
6
10
  */
7
11
  export type ObjectKey = string;
8
12
  export type EmptyObject = Record<string, never>;
@@ -1,11 +1,18 @@
1
1
  import { type FieldOfType } from '../key';
2
2
  import { type EqualityComparatorFunction } from '../value/comparator';
3
+ import { type FilterFromPOJOFunction } from './object.filter.pojo';
3
4
  /**
4
5
  * Performs a deep comparison to check if all values on the input filters are equal.
5
6
  *
6
7
  * Recursively compares Arrays, Objects, Maps, Sets, Primatives, and Dates.
7
8
  */
8
9
  export declare function areEqualPOJOValues<F>(a: F, b: F): boolean;
10
+ /**
11
+ * Performs a deep comparison to check if all values on the input filters are equal. Each input is run through the pojo filter
12
+ *
13
+ * Recursively compares Arrays, Objects, Maps, Sets, Primatives, and Dates.
14
+ */
15
+ export declare function areEqualPOJOValuesUsingPojoFilter<F>(a: F, b: F, pojoFilter: FilterFromPOJOFunction<F>): boolean;
9
16
  /**
10
17
  * Configuration for an ObjectFieldEqualityChecker.
11
18
  */
@@ -139,7 +139,7 @@ export declare function filterFromPOJO<T extends object>(obj: T, config?: Filter
139
139
  * @param obj POJO to remove undefined values from.
140
140
  * @param copy Whether or not to return a copy of the input object. Default is true.
141
141
  */
142
- export type FilterFromPOJOFunction<T> = (input: T) => T;
142
+ export type FilterFromPOJOFunction<T> = (input: T, copyOverride?: Maybe<boolean>) => T;
143
143
  export type GeneralFilterFromPOJOFunction<X = object> = <T extends X>(input: T) => T;
144
144
  export declare function filterFromPOJOFunction<T extends object>({ copy, filter: inputFilter }?: FilterFromPOJO<T>): FilterFromPOJOFunction<T>;
145
145
  /**
@@ -181,6 +181,19 @@ export declare function valuesFromPOJO<O = unknown, I extends object = object>(t
181
181
  */
182
182
  export type ValuesFromPOJOFunction<O = unknown, I extends object = object> = (obj: I) => O[];
183
183
  export declare function valuesFromPOJOFunction<O = unknown, I extends object = object>(filter?: FilterKeyValueTuplesInput<I>): ValuesFromPOJOFunction<O, I>;
184
+ /**
185
+ * Returns a FilterTuplesOnPOJOFunction that returns an object that contains only the input keys, or does not contain the input keys if invertFilter is true.
186
+ *
187
+ * @param keysToFilter
188
+ * @returns
189
+ */
190
+ export declare function filterKeysOnPOJOFunction<T extends object>(keysToFilter: Iterable<string>, invertFilter?: boolean): FilterTuplesOnPOJOFunction<T>;
191
+ export type FilterTuplesOnPOJOFilter<T extends object> = Parameters<ReturnType<typeof Object.entries<T>>['filter']>['0'];
192
+ /**
193
+ * Function that filters keys/values on a POJO using the pre-configured function.
194
+ */
195
+ export type FilterTuplesOnPOJOFunction<T extends object> = T extends Record<string, infer I> ? (input: T) => Record<string, I> : (input: T) => Partial<T>;
196
+ export declare function filterTuplesOnPOJOFunction<T extends object>(filterTupleOnObject: FilterTuplesOnPOJOFilter<T>): FilterTuplesOnPOJOFunction<T>;
184
197
  export type ForEachKeyValueOnPOJOTupleFunction<T extends object, C = unknown, K extends keyof T = keyof T> = (tuple: KeyValueTuple<T, K>, index: number, object: T, context: C) => void;
185
198
  export type ForEachKeyValueOnPOJOFunction<T extends object, C = unknown> = C extends void ? ForEachKeyValueOnPOJOFunctionWithoutContext<T> : ForEachKeyValueOnPOJOFunctionWithContext<T, C>;
186
199
  export type ForEachKeyValueOnPOJOFunctionWithoutContext<T extends object> = (object: T) => void;
@@ -1,4 +1,5 @@
1
1
  import { type MapFunction } from '../value/map';
2
+ import { type POJOKey } from './object';
2
3
  /**
3
4
  * An object with values of a specific type keyed by either string or number or symbols.
4
5
  */
@@ -21,13 +22,6 @@ export type MappedObjectMap<M extends object, O> = {
21
22
  * @returns
22
23
  */
23
24
  export declare function objectToMap<T>(object: ObjectMap<T>): Map<string, T>;
24
- /**
25
- * Converts an ObjectMap into tuples.
26
- *
27
- * @param object
28
- * @returns
29
- */
30
- export declare function objectToTuples<T>(object: ObjectMap<T>): [string, T][];
31
25
  /**
32
26
  * Maps an ObjectMap of one type to another ObjectMap with the mapped values.
33
27
  */
@@ -55,3 +49,37 @@ export declare function mapObjectMap<M extends ObjectMap<I>, I = unknown, O = un
55
49
  * @returns
56
50
  */
57
51
  export declare function mapObjectToTargetObject<M extends ObjectMap<I>, I = unknown, O = unknown>(object: M, target: MappedObjectMap<M, O>, mapFn: MapObjectMapValueFunction<M, I, O>): MappedObjectMap<M, O>;
52
+ /**
53
+ * Maps each key of the input object to a new object using the pre-configured function.
54
+ */
55
+ export type MapObjectKeysFunction<M> = (object: M) => any;
56
+ /**
57
+ * Map function that returns the new POJOKey using the input key/value pair.
58
+ */
59
+ export type MapObjectKeyFunction<M> = <K extends keyof M>(key: K, value: M[K]) => POJOKey;
60
+ /**
61
+ * Maps the keys of the input object to a new object with the mapped keys.
62
+ *
63
+ * @param object
64
+ */
65
+ export declare function mapObjectKeysFunction<M extends object>(mapKeyFn: MapObjectKeyFunction<M>): MapObjectKeysFunction<M>;
66
+ export type MappedKeysToLowercaseObjectMap<M extends object> = {
67
+ [K in keyof M as K extends string ? Lowercase<K> : K]: M[K];
68
+ };
69
+ /**
70
+ * Maps all the keys of an object to a new object with keys of the object mapped to lowercase.
71
+ *
72
+ * @param object
73
+ * @param target
74
+ * @param mapFn
75
+ */
76
+ export declare const mapObjectKeysToLowercase: <M extends object>(object: M) => MappedKeysToLowercaseObjectMap<M>;
77
+ /**
78
+ * Converts an ObjectMap into tuples.
79
+ *
80
+ * @deprecated use Object.entries instead.
81
+ *
82
+ * @param object
83
+ * @returns
84
+ */
85
+ export declare const objectToTuples: <T>(object: ObjectMap<T>) => [string, T][];
@@ -71,3 +71,25 @@ export declare function joinStringsWithSpaces(input: Maybe<string>[]): string;
71
71
  * @returns
72
72
  */
73
73
  export declare function repeatString(string: string, reapeat: number): string;
74
+ export interface CutStringFunctionConfig {
75
+ /**
76
+ * Max length of the string.
77
+ */
78
+ readonly maxLength: number;
79
+ /**
80
+ * Whether or not the end text addition should be included in the max length computation.
81
+ *
82
+ * If false, then the input string will be cut at the max length.
83
+ */
84
+ readonly maxLengthIncludesEndText?: Maybe<boolean>;
85
+ /**
86
+ * The end text to add to the cut string.
87
+ *
88
+ * Defaults to "...".
89
+ */
90
+ readonly endText?: Maybe<string>;
91
+ }
92
+ export declare const DEFAULT_CUT_STRING_END_TEXT = "...";
93
+ export type CutStringFunction = ((input: string) => string) & ((input: Maybe<string>) => Maybe<string>);
94
+ export declare function cutStringFunction(config: CutStringFunctionConfig): CutStringFunction;
95
+ export declare function cutString(input: Maybe<string>, maxLength: number, endText?: Maybe<string>): Maybe<string>;
@@ -7,9 +7,18 @@ import { type Maybe } from './maybe.type';
7
7
  import { type WrapNumberFunction } from '../number';
8
8
  import { type FilterUniqueFunctionExcludeKeysInput } from '../array/array.unique';
9
9
  /**
10
- * A number that denotes which index an item is at.
10
+ * An integer that denotes which index an item is at.
11
+ *
12
+ * Is typically non-negative only.
11
13
  */
12
14
  export type IndexNumber = number;
15
+ /**
16
+ * The default index number when no index is set.
17
+ *
18
+ * Only applicable for non-negative indexes.
19
+ */
20
+ export declare const UNSET_INDEX_NUMBER = -1;
21
+ export type UnsetIndexNumber = typeof UNSET_INDEX_NUMBER;
13
22
  /**
14
23
  * Item that references an IndexNumber.
15
24
  */
@@ -80,12 +89,18 @@ export declare function indexDeltaGroup<T>(readIndex: ReadMaybeIndexFunction<T>,
80
89
  export declare function sortByIndexAscendingCompareFunction<T>(readIndex: ReadIndexFunction<T>): SortCompareFunction<T>;
81
90
  /**
82
91
  * Computes the next free index given the input values.
92
+ *
93
+ * Returns 0 if no values are present.
83
94
  */
84
95
  export type ComputeNextFreeIndexFunction<T> = (values: T[]) => IndexNumber;
85
96
  /**
86
97
  * Creates a new ComputeNextFreeIndexFunction.
87
98
  */
88
99
  export declare function computeNextFreeIndexFunction<T>(readIndex: ReadIndexFunction<T>, nextIndex?: (value: T) => IndexNumber): ComputeNextFreeIndexFunction<T>;
100
+ /**
101
+ * Creates a new ComputeNextFreeIndexFunction that assumes that the input values are sorted in ascending order, with the latest index at the end.
102
+ */
103
+ export declare function computeNextFreeIndexOnSortedValuesFunction<T>(readIndex: ReadIndexFunction<T>, nextIndex?: (value: T) => IndexNumber): ComputeNextFreeIndexFunction<T>;
89
104
  /**
90
105
  * Reads the min and max index from the input values.
91
106
  */
@@ -87,3 +87,14 @@ export declare function isSameNonNullValue<T>(a: Maybe<T>, b: Maybe<T>): a is No
87
87
  * @returns
88
88
  */
89
89
  export declare function valuesAreBothNullishOrEquivalent<T>(a: Maybe<T>, b: Maybe<T>): boolean;
90
+ /**
91
+ * Updates "a" with "b".
92
+ *
93
+ * - If b is defined, then returns b
94
+ * - If b is undefined, then returns a
95
+ * - If b is null, then returns null
96
+ *
97
+ * @param a
98
+ * @param b
99
+ */
100
+ export declare function updateMaybeValue<T>(a: Maybe<T>, b: Maybe<T>): Maybe<T>;
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [11.1.1](https://github.com/dereekb/dbx-components/compare/v11.1.0-dev...v11.1.1) (2025-03-03)
6
+
7
+
8
+
9
+ # [11.1.0](https://github.com/dereekb/dbx-components/compare/v11.0.21-dev...v11.1.0) (2025-02-28)
10
+
11
+
12
+
5
13
  ## [11.0.21](https://github.com/dereekb/dbx-components/compare/v11.0.20-dev...v11.0.21) (2025-01-28)
6
14
 
7
15
 
package/test/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "11.0.21",
3
+ "version": "11.1.1",
4
4
  "type": "commonjs",
5
5
  "peerDependencies": {
6
6
  "@dereekb/util": "*"