@zelgadis87/utils-core 5.2.2 → 5.2.4
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/CHANGELOG.md +14 -0
- package/dist/sorting/Sorter.d.ts +16 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +5 -0
- package/esbuild/index.cjs +217 -175
- package/esbuild/index.cjs.map +3 -3
- package/esbuild/index.mjs +212 -174
- package/esbuild/index.mjs.map +3 -3
- package/package.json +1 -1
- package/src/sorting/Sorter.ts +25 -5
- package/src/utils/arrays.ts +22 -0
package/package.json
CHANGED
package/src/sorting/Sorter.ts
CHANGED
|
@@ -149,7 +149,7 @@ const next = <T, R>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFun
|
|
|
149
149
|
return compareNumbers( fns, transform as TFunction<T, number>, { direction: 'DESC', ...opts } );
|
|
150
150
|
},
|
|
151
151
|
} as const satisfies TSorterStepForNumbers<R, TSorter<T>>;
|
|
152
|
-
const
|
|
152
|
+
const retForStringsV1 = {
|
|
153
153
|
...retAsUsing,
|
|
154
154
|
inLexographicalOrder( opts: { nullsFirst?: boolean } = {} ) {
|
|
155
155
|
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'ASC', ignoreCase: false, ...opts } );
|
|
@@ -163,6 +163,22 @@ const next = <T, R>( fns: ReadonlyArray<TComparisonFunction<T>>, transform: TFun
|
|
|
163
163
|
inReverseLexographicalOrderIgnoringCase( opts: { nullsFirst?: boolean } = {} ) {
|
|
164
164
|
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'DESC', ignoreCase: true, ...opts } );
|
|
165
165
|
},
|
|
166
|
+
} as const;
|
|
167
|
+
const retForStrings = {
|
|
168
|
+
...retAsUsing,
|
|
169
|
+
...retForStringsV1,
|
|
170
|
+
inLexicographicalOrder( opts: { nullsFirst?: boolean } = {} ) {
|
|
171
|
+
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'ASC', ignoreCase: false, ...opts } );
|
|
172
|
+
},
|
|
173
|
+
inLexicographicalOrderIgnoringCase( opts: { nullsFirst?: boolean } = {} ) {
|
|
174
|
+
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'ASC', ignoreCase: true, ...opts } );
|
|
175
|
+
},
|
|
176
|
+
inReverseLexicographicalOrder( opts: { nullsFirst?: boolean } = {} ) {
|
|
177
|
+
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'DESC', ignoreCase: false, ...opts } );
|
|
178
|
+
},
|
|
179
|
+
inReverseLexicographicalOrderIgnoringCase( opts: { nullsFirst?: boolean } = {} ) {
|
|
180
|
+
return compareStrings( fns, transform as TFunction<T, string>, { direction: 'DESC', ignoreCase: true, ...opts } );
|
|
181
|
+
},
|
|
166
182
|
} as const satisfies TSorterStepForStrings<R, TSorter<T>>;
|
|
167
183
|
const retForBooleans = {
|
|
168
184
|
...retAsUsing,
|
|
@@ -317,10 +333,14 @@ type TSorterStepForNumbers<_T, Ret> = {
|
|
|
317
333
|
inDescendingOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
318
334
|
};
|
|
319
335
|
type TSorterStepForStrings<_T, Ret> = {
|
|
320
|
-
inLexographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
321
|
-
inLexographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
322
|
-
inReverseLexographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
323
|
-
inReverseLexographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
336
|
+
/** @deprecated: Use inLexographicalOrder instead */ inLexographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
337
|
+
/** @deprecated: Use inLexographicalOrderIgnoringCase instead */ inLexographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
338
|
+
/** @deprecated: Use inReverseLexographicalOrder instead */ inReverseLexographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
339
|
+
/** @deprecated: Use inReverseLexographicalOrderIgnoringCase instead */ inReverseLexographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
340
|
+
inLexicographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
341
|
+
inLexicographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
342
|
+
inReverseLexicographicalOrder( opts?: { nullsFirst?: boolean } ): Ret;
|
|
343
|
+
inReverseLexicographicalOrderIgnoringCase( opts?: { nullsFirst?: boolean } ): Ret;
|
|
324
344
|
};
|
|
325
345
|
type TSorterStepForBooleans<_T, Ret> = {
|
|
326
346
|
truesFirst( opts?: { nullsFirst?: boolean } ): Ret;
|
package/src/utils/arrays.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Optional, { type TOptional } from "../Optional.js";
|
|
1
2
|
import type { TComparisonFunction } from "../sorting/_index.js";
|
|
2
3
|
import type { TAccumulator, TBiPredicate, TPredicate, TTransformer } from "./functions.js";
|
|
3
4
|
import { isNullOrUndefined, type TMaybe } from "./nulls.js";
|
|
@@ -171,3 +172,24 @@ export function shallowArrayEquals( a: unknown[], b: unknown[] ): boolean {
|
|
|
171
172
|
}
|
|
172
173
|
return true;
|
|
173
174
|
}
|
|
175
|
+
|
|
176
|
+
export function findInArray<T>( arr: T[], predicate: TPredicate<T> ): TOptional<T> {
|
|
177
|
+
return Optional.ofNullable( arr.find( predicate ) );
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function findIndexInArray<T>( arr: T[], predicate: TPredicate<T> ): TOptional<number> {
|
|
181
|
+
const idx = arr.findIndex( predicate );
|
|
182
|
+
return idx === -1 ? Optional.empty() : Optional.of( idx );
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function zip<T, R>( ts: T[], rs: R[] ): [ T, R ][] {
|
|
186
|
+
if ( ts.length !== rs.length )
|
|
187
|
+
throw new Error( `Arrays must have the same length. Got ${ts.length} and ${rs.length}` );
|
|
188
|
+
return ts.map( ( t, i ) => [ t, rs[ i ]! ] as [ T, R ] );
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function unzip<T, R>( arr: [ T, R ][] ): [ T[], R[] ] {
|
|
192
|
+
return arr.reduce( ( [ ts, rs ], [ t, r ] ) => {
|
|
193
|
+
return [ [ ...ts, t ], [ ...rs, r ] ];
|
|
194
|
+
}, [ [], [] ] as [ T[], R[] ] );
|
|
195
|
+
}
|