@ditojs/utils 2.78.0 → 2.79.0

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": "@ditojs/utils",
3
- "version": "2.78.0",
3
+ "version": "2.79.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/utils",
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "typescript": "^5.9.3"
41
41
  },
42
- "gitHead": "ede4c836e6b2bb5dfcc80e1614a3d85eb80b0efa"
42
+ "gitHead": "f87ce5ce121a30830776774cd447014afef5b8ec"
43
43
  }
@@ -1,4 +1,3 @@
1
- export * from './asCallback.js'
2
1
  export * from './clone.js'
3
2
  export * from './equals.js'
4
3
  export * from './groupBy.js'
package/types/index.d.ts CHANGED
@@ -142,9 +142,16 @@ export function clone<T>(value: T, options?: {
142
142
  */
143
143
  export function equals(arg1: any, arg2: any): boolean
144
144
 
145
- // TODO: document groupBy
145
+ /**
146
+ * Groups items in a collection by a key returned from the callback function,
147
+ * or by a property name when a string is provided.
148
+ */
149
+ export function groupBy<T, K extends keyof T>(
150
+ collection: T[] | Record<string, T>,
151
+ callback: K
152
+ ): Record<string, T[]>
146
153
  export function groupBy<T, K extends string | number | symbol>(
147
- list: T[],
154
+ collection: T[] | Record<string, T>,
148
155
  callback: (item: T) => K
149
156
  ): Record<K, T[]>
150
157
 
@@ -217,10 +224,16 @@ export function pick<ArgA, ArgB, ArgC, ArgD, ArgE>(
217
224
  export function pick(...args: any[]): any
218
225
  /**
219
226
  * Creates an object composed of the object properties predicate returns
220
- * truthy for.
227
+ * truthy for. When a string is provided, filters by the truthiness of that
228
+ * property on each value.
221
229
  * @param object The source object.
222
- * @param callback Callback invoked with three arguments: (value, key, item).
230
+ * @param callback Callback invoked with three arguments: (value, key, item),
231
+ * or a property name string to check for truthiness.
223
232
  */
233
+ export function pickBy<T extends Dictionary<any>, K extends keyof T[keyof T]>(
234
+ object: T,
235
+ callback: K
236
+ ): Partial<T>
224
237
  export function pickBy<T extends Dictionary<any>>(
225
238
  object: T,
226
239
  callback?: (value: T[keyof T], key: keyof T, object: T) => any
@@ -231,6 +244,17 @@ export function mapKeys<T extends Dictionary<any>, K extends keyof any>(
231
244
  callback?: (key: keyof T, value: T[keyof T], object: T) => K
232
245
  ): Record<K, T[keyof T]>
233
246
 
247
+ /**
248
+ * Maps the values of an object using a callback function, or extracts a
249
+ * property when a string is provided.
250
+ */
251
+ export function mapValues<
252
+ T extends Dictionary<any>,
253
+ K extends keyof T[keyof T]
254
+ >(
255
+ object: T,
256
+ callback: K
257
+ ): Record<keyof T, T[keyof T][K]>
234
258
  export function mapValues<T extends Dictionary<any>, K>(
235
259
  object: T,
236
260
  callback?: (value: T[keyof T], key: keyof T, object: T) => K
@@ -290,8 +314,12 @@ export function underscore(str: string): string
290
314
  */
291
315
  export function deindent(
292
316
  strings: OrArrayOf<string>,
293
- ...values: Array<string>
317
+ ...values: Array<any>
294
318
  ): string
319
+ /**
320
+ * Escapes special characters in a string for use in a regular expression.
321
+ */
322
+ export function escapeRegexp(string: string): string
295
323
  /**
296
324
  * Returns the longest prefix string that is common to the supplied strings.
297
325
  */
@@ -314,6 +342,11 @@ export function isAbsoluteUrl(str: string): boolean
314
342
  * Determines whether the supplied string is a valid creditcard number.
315
343
  */
316
344
  export function isCreditCard(str: string): boolean
345
+ /**
346
+ * Determines whether the supplied string is a valid domain name.
347
+ * Supports internationalized domain names with punycode.
348
+ */
349
+ export function isDomain(str: string): boolean
317
350
  /**
318
351
  * Determines whether the supplied string is a valid email address.
319
352
  */
@@ -419,8 +452,37 @@ export function format(
419
452
  number?: boolean | NumberFormat
420
453
  }
421
454
  ): string
455
+ /**
456
+ * Formats a date value as a string. If the value is not a Date,
457
+ * attempts to convert it to a Date first.
458
+ */
459
+ export function formatDate(
460
+ value: any,
461
+ options?: {
462
+ /**
463
+ * @default 'en-US'
464
+ */
465
+ locale?: string
466
+ /**
467
+ * @default true
468
+ */
469
+ date?: boolean | DateFormat
470
+ /**
471
+ * @default true
472
+ */
473
+ time?: boolean | TimeFormat
474
+ }
475
+ ): string
422
476
  /* -------------------------------- function -------------------------------- */
423
477
 
478
+ /**
479
+ * Logs a deprecation warning message to the console. Each unique message
480
+ * is only logged once.
481
+ *
482
+ * @param message The deprecation message to log.
483
+ */
484
+ export function deprecate(message: string): void
485
+
424
486
  /**
425
487
  * Creates a debounced function that delays invoking func until after wait
426
488
  * milliseconds have elapsed since the last time the debounced function was
@@ -671,6 +733,21 @@ export function toPromiseCallback<T, R>(
671
733
 
672
734
  /* -------------------------------- dataPath -------------------------------- */
673
735
 
736
+ /**
737
+ * Gets entries at a data path, supporting wildcards (* and **).
738
+ * Wildcard * matches direct children, ** matches recursively.
739
+ *
740
+ * @param obj The object to query.
741
+ * @param path The data path (supports wildcards).
742
+ * @param handleError Optional error handler called when path is invalid.
743
+ * @returns Object with normalized paths as keys and values at those paths.
744
+ */
745
+ export function getEntriesAtDataPath(
746
+ obj: any,
747
+ path: OrArrayOf<string>,
748
+ handleError?: (obj: any, part: string, index: number) => any
749
+ ): Record<string, any>
750
+
674
751
  export function getValueAtDataPath(
675
752
  obj: any,
676
753
  path: OrArrayOf<string>,
@@ -681,12 +758,37 @@ export function normalizeDataPath(path: OrArrayOf<string>): string
681
758
 
682
759
  export function parseDataPath(path: OrArrayOf<string>): string
683
760
 
761
+ /**
762
+ * Sets multiple values at data paths from an entries object.
763
+ *
764
+ * @param obj The object to modify.
765
+ * @param entries Object with data paths as keys and values to set.
766
+ * @returns The modified object.
767
+ */
768
+ export function setDataPathEntries<O>(
769
+ obj: O,
770
+ entries: Record<string, any>
771
+ ): O
772
+
684
773
  export function setValueAtDataPath<O>(
685
774
  obj: O,
686
775
  path: OrArrayOf<string>,
687
776
  value: any
688
777
  ): O
689
778
 
779
+ /* --------------------------------- class ---------------------------------- */
780
+
781
+ /**
782
+ * Creates a mixin decorator that applies a mixin function to a class.
783
+ * Prevents duplicate application of the same mixin in the inheritance chain.
784
+ *
785
+ * @param mixinFunction Function that takes a class and returns a mixed class.
786
+ * @returns Decorator function that applies the mixin to a target class.
787
+ */
788
+ export function mixin<T extends new (...args: any[]) => any>(
789
+ mixinFunction: (targetClass: T) => T
790
+ ): (targetClass: T) => T
791
+
690
792
  /* ---------------------------------- html ---------------------------------- */
691
793
 
692
794
  /**