@zelgadis87/utils-core 5.2.2 → 5.2.3

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,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@zelgadis87/utils-core",
4
- "version": "5.2.2",
4
+ "version": "5.2.3",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -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 retForStrings = {
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;
@@ -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,19 @@ 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 zip<T, R>( ts: T[], rs: R[] ): [ T, R ][] {
181
+ if ( ts.length !== rs.length )
182
+ throw new Error( `Arrays must have the same length. Got ${ts.length} and ${rs.length}` );
183
+ return ts.map( ( t, i ) => [ t, rs[ i ]! ] as [ T, R ] );
184
+ }
185
+
186
+ export function unzip<T, R>( arr: [ T, R ][] ): [ T[], R[] ] {
187
+ return arr.reduce( ( [ ts, rs ], [ t, r ] ) => {
188
+ return [ [ ...ts, t ], [ ...rs, r ] ];
189
+ }, [ [], [] ] as [ T[], R[] ] );
190
+ }