cmpstr 3.0.3 → 3.1.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.
Files changed (139) hide show
  1. package/README.md +2 -1
  2. package/dist/CmpStr.esm.js +2487 -4948
  3. package/dist/CmpStr.esm.js.map +1 -1
  4. package/dist/CmpStr.esm.min.js +3 -3
  5. package/dist/CmpStr.esm.min.js.map +1 -1
  6. package/dist/CmpStr.umd.js +2601 -5040
  7. package/dist/CmpStr.umd.js.map +1 -1
  8. package/dist/CmpStr.umd.min.js +3 -3
  9. package/dist/CmpStr.umd.min.js.map +1 -1
  10. package/dist/cjs/CmpStr.cjs +41 -405
  11. package/dist/cjs/CmpStr.cjs.map +1 -1
  12. package/dist/cjs/CmpStrAsync.cjs +38 -221
  13. package/dist/cjs/CmpStrAsync.cjs.map +1 -1
  14. package/dist/cjs/index.cjs +1 -1
  15. package/dist/cjs/metric/Cosine.cjs +1 -56
  16. package/dist/cjs/metric/Cosine.cjs.map +1 -1
  17. package/dist/cjs/metric/DamerauLevenshtein.cjs +2 -64
  18. package/dist/cjs/metric/DamerauLevenshtein.cjs.map +1 -1
  19. package/dist/cjs/metric/DiceSorensen.cjs +1 -56
  20. package/dist/cjs/metric/DiceSorensen.cjs.map +1 -1
  21. package/dist/cjs/metric/Hamming.cjs +2 -51
  22. package/dist/cjs/metric/Hamming.cjs.map +1 -1
  23. package/dist/cjs/metric/Jaccard.cjs +1 -48
  24. package/dist/cjs/metric/Jaccard.cjs.map +1 -1
  25. package/dist/cjs/metric/JaroWinkler.cjs +1 -53
  26. package/dist/cjs/metric/JaroWinkler.cjs.map +1 -1
  27. package/dist/cjs/metric/LCS.cjs +1 -54
  28. package/dist/cjs/metric/LCS.cjs.map +1 -1
  29. package/dist/cjs/metric/Levenshtein.cjs +2 -60
  30. package/dist/cjs/metric/Levenshtein.cjs.map +1 -1
  31. package/dist/cjs/metric/Metric.cjs +1 -261
  32. package/dist/cjs/metric/Metric.cjs.map +1 -1
  33. package/dist/cjs/metric/NeedlemanWunsch.cjs +4 -56
  34. package/dist/cjs/metric/NeedlemanWunsch.cjs.map +1 -1
  35. package/dist/cjs/metric/SmithWaterman.cjs +4 -58
  36. package/dist/cjs/metric/SmithWaterman.cjs.map +1 -1
  37. package/dist/cjs/metric/qGram.cjs +1 -55
  38. package/dist/cjs/metric/qGram.cjs.map +1 -1
  39. package/dist/cjs/phonetic/Caverphone.cjs +1 -78
  40. package/dist/cjs/phonetic/Caverphone.cjs.map +1 -1
  41. package/dist/cjs/phonetic/Cologne.cjs +1 -43
  42. package/dist/cjs/phonetic/Cologne.cjs.map +1 -1
  43. package/dist/cjs/phonetic/Metaphone.cjs +1 -76
  44. package/dist/cjs/phonetic/Metaphone.cjs.map +1 -1
  45. package/dist/cjs/phonetic/Phonetic.cjs +1 -261
  46. package/dist/cjs/phonetic/Phonetic.cjs.map +1 -1
  47. package/dist/cjs/phonetic/Soundex.cjs +1 -47
  48. package/dist/cjs/phonetic/Soundex.cjs.map +1 -1
  49. package/dist/cjs/root.cjs +49 -0
  50. package/dist/cjs/root.cjs.map +1 -0
  51. package/dist/cjs/utils/DeepMerge.cjs +8 -75
  52. package/dist/cjs/utils/DeepMerge.cjs.map +1 -1
  53. package/dist/cjs/utils/DiffChecker.cjs +2 -190
  54. package/dist/cjs/utils/DiffChecker.cjs.map +1 -1
  55. package/dist/cjs/utils/Filter.cjs +1 -112
  56. package/dist/cjs/utils/Filter.cjs.map +1 -1
  57. package/dist/cjs/utils/HashTable.cjs +1 -99
  58. package/dist/cjs/utils/HashTable.cjs.map +1 -1
  59. package/dist/cjs/utils/Normalizer.cjs +3 -94
  60. package/dist/cjs/utils/Normalizer.cjs.map +1 -1
  61. package/dist/cjs/utils/Pool.cjs +10 -105
  62. package/dist/cjs/utils/Pool.cjs.map +1 -1
  63. package/dist/cjs/utils/Profiler.cjs +1 -133
  64. package/dist/cjs/utils/Profiler.cjs.map +1 -1
  65. package/dist/cjs/utils/Registry.cjs +1 -89
  66. package/dist/cjs/utils/Registry.cjs.map +1 -1
  67. package/dist/cjs/utils/StructuredData.cjs +145 -0
  68. package/dist/cjs/utils/StructuredData.cjs.map +1 -0
  69. package/dist/cjs/utils/TextAnalyzer.cjs +1 -180
  70. package/dist/cjs/utils/TextAnalyzer.cjs.map +1 -1
  71. package/dist/esm/CmpStr.mjs +41 -405
  72. package/dist/esm/CmpStr.mjs.map +1 -1
  73. package/dist/esm/CmpStrAsync.mjs +38 -221
  74. package/dist/esm/CmpStrAsync.mjs.map +1 -1
  75. package/dist/esm/index.mjs +1 -1
  76. package/dist/esm/metric/Cosine.mjs +1 -56
  77. package/dist/esm/metric/Cosine.mjs.map +1 -1
  78. package/dist/esm/metric/DamerauLevenshtein.mjs +2 -64
  79. package/dist/esm/metric/DamerauLevenshtein.mjs.map +1 -1
  80. package/dist/esm/metric/DiceSorensen.mjs +1 -56
  81. package/dist/esm/metric/DiceSorensen.mjs.map +1 -1
  82. package/dist/esm/metric/Hamming.mjs +2 -51
  83. package/dist/esm/metric/Hamming.mjs.map +1 -1
  84. package/dist/esm/metric/Jaccard.mjs +1 -48
  85. package/dist/esm/metric/Jaccard.mjs.map +1 -1
  86. package/dist/esm/metric/JaroWinkler.mjs +1 -53
  87. package/dist/esm/metric/JaroWinkler.mjs.map +1 -1
  88. package/dist/esm/metric/LCS.mjs +1 -54
  89. package/dist/esm/metric/LCS.mjs.map +1 -1
  90. package/dist/esm/metric/Levenshtein.mjs +2 -60
  91. package/dist/esm/metric/Levenshtein.mjs.map +1 -1
  92. package/dist/esm/metric/Metric.mjs +1 -261
  93. package/dist/esm/metric/Metric.mjs.map +1 -1
  94. package/dist/esm/metric/NeedlemanWunsch.mjs +4 -56
  95. package/dist/esm/metric/NeedlemanWunsch.mjs.map +1 -1
  96. package/dist/esm/metric/SmithWaterman.mjs +4 -58
  97. package/dist/esm/metric/SmithWaterman.mjs.map +1 -1
  98. package/dist/esm/metric/qGram.mjs +1 -55
  99. package/dist/esm/metric/qGram.mjs.map +1 -1
  100. package/dist/esm/phonetic/Caverphone.mjs +1 -78
  101. package/dist/esm/phonetic/Caverphone.mjs.map +1 -1
  102. package/dist/esm/phonetic/Cologne.mjs +1 -43
  103. package/dist/esm/phonetic/Cologne.mjs.map +1 -1
  104. package/dist/esm/phonetic/Metaphone.mjs +1 -76
  105. package/dist/esm/phonetic/Metaphone.mjs.map +1 -1
  106. package/dist/esm/phonetic/Phonetic.mjs +1 -261
  107. package/dist/esm/phonetic/Phonetic.mjs.map +1 -1
  108. package/dist/esm/phonetic/Soundex.mjs +1 -47
  109. package/dist/esm/phonetic/Soundex.mjs.map +1 -1
  110. package/dist/esm/root.mjs +35 -0
  111. package/dist/esm/root.mjs.map +1 -0
  112. package/dist/esm/utils/DeepMerge.mjs +8 -76
  113. package/dist/esm/utils/DeepMerge.mjs.map +1 -1
  114. package/dist/esm/utils/DiffChecker.mjs +2 -190
  115. package/dist/esm/utils/DiffChecker.mjs.map +1 -1
  116. package/dist/esm/utils/Filter.mjs +1 -112
  117. package/dist/esm/utils/Filter.mjs.map +1 -1
  118. package/dist/esm/utils/HashTable.mjs +1 -99
  119. package/dist/esm/utils/HashTable.mjs.map +1 -1
  120. package/dist/esm/utils/Normalizer.mjs +3 -94
  121. package/dist/esm/utils/Normalizer.mjs.map +1 -1
  122. package/dist/esm/utils/Pool.mjs +10 -105
  123. package/dist/esm/utils/Pool.mjs.map +1 -1
  124. package/dist/esm/utils/Profiler.mjs +1 -133
  125. package/dist/esm/utils/Profiler.mjs.map +1 -1
  126. package/dist/esm/utils/Registry.mjs +1 -89
  127. package/dist/esm/utils/Registry.mjs.map +1 -1
  128. package/dist/esm/utils/StructuredData.mjs +143 -0
  129. package/dist/esm/utils/StructuredData.mjs.map +1 -0
  130. package/dist/esm/utils/TextAnalyzer.mjs +1 -180
  131. package/dist/esm/utils/TextAnalyzer.mjs.map +1 -1
  132. package/dist/types/CmpStr.d.ts +90 -8
  133. package/dist/types/CmpStrAsync.d.ts +82 -8
  134. package/dist/types/index.d.ts +3 -2
  135. package/dist/types/root.d.ts +39 -0
  136. package/dist/types/utils/Pool.d.ts +2 -2
  137. package/dist/types/utils/StructuredData.d.ts +162 -0
  138. package/dist/types/utils/Types.d.ts +35 -1
  139. package/package.json +63 -22
@@ -12,6 +12,7 @@
12
12
  * - Flexible normalization and filtering pipeline for all inputs
13
13
  * - Batch, pairwise, and single string comparison with detailed results
14
14
  * - Phonetic indexing and phonetic-aware search and comparison
15
+ * - Structured data comparison by extracting properties from objects
15
16
  * - Text analysis and unified diff utilities
16
17
  * - Full TypeScript type safety and extensibility
17
18
  *
@@ -19,11 +20,12 @@
19
20
  * @author Paul Köhler (komed3)
20
21
  * @license MIT
21
22
  */
22
- import type { CmpStrOptions, CmpStrProcessors, CmpStrResult, NormalizeFlags, DiffOptions, PhoneticOptions, MetricRaw, MetricInput, MetricMode, MetricResult, MetricResultSingle, MetricResultBatch } from './utils/Types';
23
+ import type { CmpStrOptions, CmpStrProcessors, CmpStrResult, NormalizeFlags, DiffOptions, PhoneticOptions, MetricRaw, MetricInput, MetricMode, MetricResult, MetricResultSingle, MetricResultBatch, StructuredDataBatchResult, StructuredDataOptions } from './utils/Types';
23
24
  import { TextAnalyzer } from './utils/TextAnalyzer';
24
25
  import { DiffChecker } from './utils/DiffChecker';
25
26
  import { Normalizer } from './utils/Normalizer';
26
27
  import { Filter } from './utils/Filter';
28
+ import { StructuredData } from './utils/StructuredData';
27
29
  import { Metric } from './metric';
28
30
  import { Phonetic } from './phonetic';
29
31
  /**
@@ -207,6 +209,15 @@ export declare class CmpStr<R = MetricRaw> {
207
209
  algo: string;
208
210
  opt?: PhoneticOptions;
209
211
  }): MetricInput;
212
+ /**
213
+ * Creates a instance for processing structured data.
214
+ *
215
+ * @template T - The type of objects in the data array
216
+ * @param {T[]} data - The array of structured objects
217
+ * @param {keyof T} key - The property key to compare
218
+ * @returns {StructuredData<T, R>} - The lookup instance
219
+ */
220
+ protected structured<T = any>(data: T[], key: keyof T): StructuredData<T, R>;
210
221
  /**
211
222
  * Computes the metric result for the given inputs, applying normalization and
212
223
  * filtering as configured.
@@ -362,7 +373,7 @@ export declare class CmpStr<R = MetricRaw> {
362
373
  * @param {CmpStrOptions} [opt] - Optional options
363
374
  * @returns {T} - The metric result
364
375
  */
365
- test<T extends CmpStrResult | MetricResultSingle<R>>(a: string, b: string, opt?: CmpStrOptions): T;
376
+ test<T extends CmpStrResult | MetricResultSingle<R> = any>(a: string, b: string, opt?: CmpStrOptions): T;
366
377
  /**
367
378
  * Performs a single metric comparison and returns only the numeric score.
368
379
  *
@@ -382,7 +393,7 @@ export declare class CmpStr<R = MetricRaw> {
382
393
  * @param {CmpStrOptions} [opt] - Optional options
383
394
  * @returns {T} - The batch metric results
384
395
  */
385
- batchTest<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): T;
396
+ batchTest<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): T;
386
397
  /**
387
398
  * Performs a batch metric comparison and returns results sorted by score.
388
399
  *
@@ -393,7 +404,7 @@ export declare class CmpStr<R = MetricRaw> {
393
404
  * @param {CmpStrOptions} [opt] - Optional options
394
405
  * @returns {T} - The sorted batch results
395
406
  */
396
- batchSorted<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, dir?: 'desc' | 'asc', opt?: CmpStrOptions): T;
407
+ batchSorted<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, dir?: 'desc' | 'asc', opt?: CmpStrOptions): T;
397
408
  /**
398
409
  * Performs a pairwise metric comparison between source and target strings
399
410
  * or array of strings.
@@ -407,7 +418,7 @@ export declare class CmpStr<R = MetricRaw> {
407
418
  * @param {CmpStrOptions} [opt] - Optional options
408
419
  * @returns {T} - The pairwise metric results
409
420
  */
410
- pairs<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): T;
421
+ pairs<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): T;
411
422
  /**
412
423
  * Performs a batch comparison and returns only results above the threshold.
413
424
  *
@@ -418,7 +429,7 @@ export declare class CmpStr<R = MetricRaw> {
418
429
  * @param {CmpStrOptions} [opt] - Optional options
419
430
  * @returns {T} - The filtered batch results
420
431
  */
421
- match<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, threshold: number, opt?: CmpStrOptions): T;
432
+ match<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, threshold: number, opt?: CmpStrOptions): T;
422
433
  /**
423
434
  * Returns the n closest matches from a batch comparison.
424
435
  *
@@ -429,7 +440,7 @@ export declare class CmpStr<R = MetricRaw> {
429
440
  * @param {CmpStrOptions} [opt] - Optional options
430
441
  * @returns {T} - The closest matches
431
442
  */
432
- closest<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): T;
443
+ closest<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): T;
433
444
  /**
434
445
  * Returns the n furthest matches from a batch comparison.
435
446
  *
@@ -440,7 +451,7 @@ export declare class CmpStr<R = MetricRaw> {
440
451
  * @param {CmpStrOptions} [opt] - Optional options
441
452
  * @returns {T} - The furthest matches
442
453
  */
443
- furthest<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): T;
454
+ furthest<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): T;
444
455
  /**
445
456
  * Performs a normalized and filtered substring search.
446
457
  *
@@ -469,4 +480,75 @@ export declare class CmpStr<R = MetricRaw> {
469
480
  * @returns {string} - The phonetic index as a string
470
481
  */
471
482
  phoneticIndex(input: string, algo?: string, opt?: PhoneticOptions): string;
483
+ /**
484
+ * ---------------------------------------------------------------------------------
485
+ * Public methods for structured data comparison
486
+ * ---------------------------------------------------------------------------------
487
+ *
488
+ * These methods provide interfaces for comparing arrays of structured objects
489
+ * by extracting and comparing specific properties.
490
+ */
491
+ /**
492
+ * Performs a batch comparison against structured data by extracting
493
+ * a specific property and returning results with original objects attached.
494
+ *
495
+ * @template T - The type of objects in the data array
496
+ * @param {string} query - The query string to compare against
497
+ * @param {T[]} data - The array of structured objects
498
+ * @param {keyof T} key - The property key to extract for comparison
499
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
500
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Batch results with original objects
501
+ */
502
+ structuredLookup<T = any>(query: string, data: T[], key: keyof T, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
503
+ /**
504
+ * Performs a batch comparison and returns only results above the threshold
505
+ * for structured data.
506
+ *
507
+ * @template T - The type of objects in the data array
508
+ * @param {string} query - The query string to compare against
509
+ * @param {T[]} data - The array of structured objects
510
+ * @param {keyof T} key - The property key to extract for comparison
511
+ * @param {number} threshold - The similarity threshold (0..1)
512
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
513
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Filtered batch results with objects
514
+ */
515
+ structuredMatch<T = any>(query: string, data: T[], key: keyof T, threshold: number, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
516
+ /**
517
+ * Returns the n closest matches from a batch comparison of structured data.
518
+ *
519
+ * @template T - The type of objects in the data array
520
+ * @param {string} query - The query string to compare against
521
+ * @param {T[]} data - The array of structured objects
522
+ * @param {keyof T} key - The property key to extract for comparison
523
+ * @param {number} [n=1] - Number of closest matches
524
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
525
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Closest matches with objects
526
+ */
527
+ structuredClosest<T = any>(query: string, data: T[], key: keyof T, n?: number, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
528
+ /**
529
+ * Returns the n furthest matches from a batch comparison of structured data.
530
+ *
531
+ * @template T - The type of objects in the data array
532
+ * @param {string} query - The query string to compare against
533
+ * @param {T[]} data - The array of structured objects
534
+ * @param {keyof T} key - The property key to extract for comparison
535
+ * @param {number} [n=1] - Number of furthest matches
536
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
537
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Furthest matches with objects
538
+ */
539
+ structuredFurthest<T = any>(query: string, data: T[], key: keyof T, n?: number, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
540
+ /**
541
+ * Performs a pairwise comparison between two arrays of structured objects
542
+ * by extracting specific properties and returning results with original objects attached.
543
+ *
544
+ * @template T - The type of objects in the arrays
545
+ * @template O - The type of objects in the other array
546
+ * @param {T[]} data - The array of structured objects
547
+ * @param {keyof T} key - The property key to extract for comparison
548
+ * @param {O[]} other - The other array of structured objects
549
+ * @param {keyof O} otherKey - The property key to extract from other array
550
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
551
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Pairwise results with original objects
552
+ */
553
+ structuredPairs<T = any, O = any>(data: T[], key: keyof T, other: O[], otherKey: keyof O, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
472
554
  }
@@ -11,6 +11,7 @@
11
11
  * - Asynchronous normalization, filtering, and metric computation
12
12
  * - Async batch, pairwise, and single string comparison with detailed results
13
13
  * - Async phonetic indexing and phonetic-aware search and comparison
14
+ * - Async structured data comparison by extracting object properties
14
15
  * - Full compatibility with the synchronous CmpStr API
15
16
  * - Designed for large-scale, high-performance, and server-side applications
16
17
  *
@@ -18,7 +19,7 @@
18
19
  * @author Paul Köhler (komed3)
19
20
  * @license MIT
20
21
  */
21
- import type { CmpStrOptions, CmpStrProcessors, CmpStrResult, NormalizeFlags, PhoneticOptions, MetricRaw, MetricInput, MetricMode, MetricResult, MetricResultSingle, MetricResultBatch } from './utils/Types';
22
+ import type { CmpStrOptions, CmpStrProcessors, CmpStrResult, NormalizeFlags, PhoneticOptions, MetricRaw, MetricInput, MetricMode, MetricResult, MetricResultSingle, MetricResultBatch, StructuredDataBatchResult, StructuredDataOptions } from './utils/Types';
22
23
  import { CmpStr } from './CmpStr';
23
24
  /**
24
25
  * The CmpStrAsync class provides a fully asynchronous API for string comparison,
@@ -123,7 +124,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
123
124
  * @param {CmpStrOptions} [opt] - Optional options
124
125
  * @returns {Promise<T>} - The metric result
125
126
  */
126
- testAsync<T extends CmpStrResult | MetricResultSingle<R>>(a: string, b: string, opt?: CmpStrOptions): Promise<T>;
127
+ testAsync<T extends CmpStrResult | MetricResultSingle<R> = any>(a: string, b: string, opt?: CmpStrOptions): Promise<T>;
127
128
  /**
128
129
  * Asynchronously performs a single metric comparison returning the numeric score.
129
130
  *
@@ -143,7 +144,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
143
144
  * @param {CmpStrOptions} [opt] - Optional options
144
145
  * @returns {Promise<T>} - The batch metric results
145
146
  */
146
- batchTestAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): Promise<T>;
147
+ batchTestAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): Promise<T>;
147
148
  /**
148
149
  * Asynchronously performs a batch metric comparison and returns results sorted by score.
149
150
  *
@@ -154,7 +155,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
154
155
  * @param {CmpStrOptions} [opt] - Optional options
155
156
  * @returns {Promise<T>} - The sorted batch results
156
157
  */
157
- batchSortedAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, dir?: 'desc' | 'asc', opt?: CmpStrOptions): Promise<T>;
158
+ batchSortedAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, dir?: 'desc' | 'asc', opt?: CmpStrOptions): Promise<T>;
158
159
  /**
159
160
  * Asynchronously performs a pairwise metric comparison between source and target
160
161
  * strings or array of strings.
@@ -168,7 +169,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
168
169
  * @param {CmpStrOptions} [opt] - Optional options
169
170
  * @returns {Promise<T>} - The pairwise metric results
170
171
  */
171
- pairsAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): Promise<T>;
172
+ pairsAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions): Promise<T>;
172
173
  /**
173
174
  * Asynchronously performs a batch comparison and returns only results above the threshold.
174
175
  *
@@ -179,7 +180,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
179
180
  * @param {CmpStrOptions} [opt] - Optional options
180
181
  * @returns {Promise<T>} - The filtered batch results
181
182
  */
182
- matchAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, threshold: number, opt?: CmpStrOptions): Promise<T>;
183
+ matchAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, threshold: number, opt?: CmpStrOptions): Promise<T>;
183
184
  /**
184
185
  * Asynchronously returns the n closest matches from a batch comparison.
185
186
  *
@@ -190,7 +191,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
190
191
  * @param {CmpStrOptions} [opt] - Optional options
191
192
  * @returns {Promise<T>} - The closest matches
192
193
  */
193
- closestAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): Promise<T>;
194
+ closestAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): Promise<T>;
194
195
  /**
195
196
  * Asynchronously returns the n furthest matches from a batch comparison.
196
197
  *
@@ -201,7 +202,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
201
202
  * @param {CmpStrOptions} [opt] - Optional options
202
203
  * @returns {Promise<T>} - The furthest matches
203
204
  */
204
- furthestAsync<T extends CmpStrResult[] | MetricResultBatch<R>>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): Promise<T>;
205
+ furthestAsync<T extends CmpStrResult[] | MetricResultBatch<R> = any>(a: MetricInput, b: MetricInput, n?: number, opt?: CmpStrOptions): Promise<T>;
205
206
  /**
206
207
  * Asynchronously performs a normalized and filtered substring search.
207
208
  *
@@ -230,4 +231,77 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
230
231
  * @returns {Promise<string>} - The phonetic index as a string
231
232
  */
232
233
  phoneticIndexAsync(input: string, algo?: string, opt?: PhoneticOptions): Promise<string>;
234
+ /**
235
+ * ---------------------------------------------------------------------------------
236
+ * Public asynchronous methods for structured data comparison
237
+ * ---------------------------------------------------------------------------------
238
+ *
239
+ * These methods provide asynchronous interfaces for comparing arrays of
240
+ * structured objects by extracting and comparing specific properties.
241
+ */
242
+ /**
243
+ * Asynchronously performs a batch comparison against structured data by extracting
244
+ * a specific property and returning results with original objects attached.
245
+ *
246
+ * @template T - The type of objects in the data array
247
+ * @param {string} query - The query string to compare against
248
+ * @param {T[]} data - The array of structured objects
249
+ * @param {keyof T} key - The property key to extract for comparison
250
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
251
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - Async batch results with original objects
252
+ */
253
+ structuredLookupAsync<T = any>(query: string, data: T[], key: keyof T, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
254
+ /**
255
+ * Asynchronously performs a batch comparison and returns only results above
256
+ * the threshold for structured data.
257
+ *
258
+ * @template T - The type of objects in the data array
259
+ * @param {string} query - The query string to compare against
260
+ * @param {T[]} data - The array of structured objects
261
+ * @param {keyof T} key - The property key to extract for comparison
262
+ * @param {number} threshold - The similarity threshold (0..1)
263
+ * @param {StructuredDataLookupOptions} [opt] - Optional lookup options
264
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - Async filtered batch results
265
+ */
266
+ structuredMatchAsync<T = any>(query: string, data: T[], key: keyof T, threshold: number, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
267
+ /**
268
+ * Asynchronously returns the n closest matches from a batch comparison
269
+ * of structured data.
270
+ *
271
+ * @template T - The type of objects in the data array
272
+ * @param {string} query - The query string to compare against
273
+ * @param {T[]} data - The array of structured objects
274
+ * @param {keyof T} key - The property key to extract for comparison
275
+ * @param {number} [n=1] - Number of closest matches
276
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
277
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - Async closest matches
278
+ */
279
+ structuredClosestAsync<T = any>(query: string, data: T[], key: keyof T, n?: number, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
280
+ /**
281
+ * Asynchronously returns the n furthest matches from a batch comparison
282
+ * of structured data.
283
+ *
284
+ * @template T - The type of objects in the data array
285
+ * @param {string} query - The query string to compare against
286
+ * @param {T[]} data - The array of structured objects
287
+ * @param {keyof T} key - The property key to extract for comparison
288
+ * @param {number} [n=1] - Number of furthest matches
289
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
290
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - Async furthest matches
291
+ */
292
+ structuredFurthestAsync<T = any>(query: string, data: T[], key: keyof T, n?: number, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
293
+ /**
294
+ * Asynchronously performs a pairwise comparison between two arrays of structured objects
295
+ * by extracting specific properties and returning results with original objects attached.
296
+ *
297
+ * @template T - The type of objects in the arrays
298
+ * @template O - The type of objects in the other array
299
+ * @param {T[]} data - The array of structured objects
300
+ * @param {keyof T} key - The property key to extract for comparison
301
+ * @param {T[]} other - The other array of structured objects
302
+ * @param {keyof T} otherKey - The property key to extract from other array
303
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
304
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - Async pairwise results with original objects
305
+ */
306
+ structuredPairsAsync<T = any, O = any>(data: T[], key: keyof T, other: O[], otherKey: keyof O, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
233
307
  }
@@ -7,7 +7,7 @@
7
7
  * filtering, and text analysis. It is designed for both high-level application development
8
8
  * and research, offering a unified API for single, batch, and pairwise operations.
9
9
  *
10
- * Version: 3.0.3
10
+ * Version: 3.1.0
11
11
  * Author: Paul Köhler (komed3)
12
12
  * License: MIT
13
13
  *
@@ -21,6 +21,7 @@
21
21
  * - Batch, pairwise, and single comparison with detailed, type-safe results
22
22
  * - Safe-mode for handling empty inputs gracefully
23
23
  * - Phonetic-aware search, indexing, and comparison
24
+ * - Structured data comparison by extracting properties from objects
24
25
  * - Readability and text analysis utilities (syllables, word stats, etc.)
25
26
  * - Unified diff and difference reporting (line/word, ASCII/CLI)
26
27
  * - Full TypeScript type safety, extensibility, and profiling support
@@ -40,7 +41,7 @@
40
41
  * For asynchronous workloads, use `CmpStrAsync`, which provides the same API with
41
42
  * Promise-based, non-blocking methods for large-scale or I/O-bound operations.
42
43
  *
43
- * @version 3.0.3
44
+ * @version 3.1.0
44
45
  * @author Paul Köhler (komed3)
45
46
  * @license MIT
46
47
  */
@@ -0,0 +1,39 @@
1
+ /**
2
+ * CmpStr Development Entry Point
3
+ * src/root.ts
4
+ *
5
+ * This entry point is intended for development and extension of the CmpStr library. It exposes
6
+ * core components and utilities that allow developers to create new metrics, phonetic algorithms,
7
+ * and other extensions to the library.
8
+ *
9
+ * Please visit CmpStr's documentation for more information:
10
+ * https://github.com/komed3/cmpstr/wiki/Extending-CmpStr
11
+ *
12
+ * @version 3.1.0
13
+ * @author Paul Köhler (komed3)
14
+ * @license MIT
15
+ */
16
+ export * from './index';
17
+ /**
18
+ * Export utils to implement new metrics
19
+ *
20
+ * - MetricRegistry: Metric registry service for managing metric implementations.
21
+ * - Metric: Abstract class representing a generic string metric.
22
+ * - MetricCls: Type definition for a class constructor that extends the Metric class.
23
+ */
24
+ export { MetricRegistry, Metric, MetricCls } from './metric';
25
+ /**
26
+ * Export utils to implement new phonetic algorithms
27
+ *
28
+ * - PhoneticRegistry: Phonetic registry service for managing phonetic algorithm implementations.
29
+ * - PhoneticMappingRegistry: Registry for managing phonetic character mappings.
30
+ * - Phonetic: Abstract class representing a generic phonetic algorithm.
31
+ * - PhoneticCls: Type definition for a class constructor that extends the Phonetic class.
32
+ */
33
+ export { PhoneticRegistry, PhoneticMappingRegistry, Phonetic, PhoneticCls } from './phonetic';
34
+ export * as DeepMerge from './utils/DeepMerge';
35
+ export { Filter } from './utils/Filter';
36
+ export { HashTable } from './utils/HashTable';
37
+ export { Pool } from './utils/Pool';
38
+ export { Profiler } from './utils/Profiler';
39
+ export { StructuredData } from './utils/StructuredData';
@@ -9,8 +9,8 @@
9
9
  * By reusing pre-allocated typed arrays, it reduces memory allocations and garbage
10
10
  * collection overhead, especially for repeated or batch computations.
11
11
  *
12
- * It supports different types of buffers (Uint16Array, number[], Set, Map) and allows
13
- * for acquiring buffers of specific sizes while managing a maximum pool size.
12
+ * It supports different types of buffers (Uint16Array, number[], string[], Set, Map)
13
+ * and allows for acquiring buffers of specific sizes while managing a max pool size.
14
14
  *
15
15
  * @module Utils/Pool
16
16
  * @author Paul Köhler (komed3)
@@ -0,0 +1,162 @@
1
+ /**
2
+ * StructuredData - Structured Data Processing Utility
3
+ * src/utils/StructuredData.ts
4
+ *
5
+ * This utility provides a factory for processing arrays of structured objects,
6
+ * enabling efficient lookups and comparisons on specific object properties.
7
+ *
8
+ * Features:
9
+ * - Support for arbitrary object structures and property keys
10
+ * - Flexible extraction and transformation of object properties
11
+ * - Batch comparison with original object reconstruction
12
+ * - Full TypeScript type safety with generics
13
+ * - Integration with CmpStr comparison methods
14
+ * - Optional "objects-only" output mode for minimal result structure
15
+ *
16
+ * @module Utils/StructuredData
17
+ * @author Paul Köhler (komed3)
18
+ * @license MIT
19
+ */
20
+ import type { CmpFnResult, CmpStrOptions, MetricRaw, StructuredDataBatchResult, StructuredDataOptions } from './Types';
21
+ /**
22
+ * The StructuredData class provides factory methods for processing arrays of
23
+ * structured objects with string comparison capabilities.
24
+ *
25
+ * @template T - The type of objects in the data array
26
+ * @template R - The type of the metric raw result
27
+ */
28
+ export declare class StructuredData<T = any, R = MetricRaw> {
29
+ /**
30
+ * Creates a new StructuredData instance for processing structured data.
31
+ *
32
+ * @param {T[]} data - The array of objects to process
33
+ * @param {string|number|symbol} key - The property key to extract for comparison
34
+ * @returns {StructuredData<T, R>} - A new class instance
35
+ */
36
+ static create<T = any, R = MetricRaw>(data: T[], key: keyof T): StructuredData<T, R>;
37
+ protected data: T[];
38
+ protected key: keyof T;
39
+ /**
40
+ * Creates a new StructuredData instance.
41
+ *
42
+ * @param {T[]} data - The array of objects to process
43
+ * @param {keyof T} key - The property key to extract for comparison
44
+ */
45
+ private constructor();
46
+ /**
47
+ * Extracts properties from another array.
48
+ *
49
+ * @template A - The type of objects in the array
50
+ * @param {A[]} arr - The array to extract from
51
+ * @param {keyof A} key - The property key
52
+ * @returns {string[]} - Array of extracted strings
53
+ */
54
+ private extractFrom;
55
+ /**
56
+ * Extracts string values from the data array using the configured key.
57
+ *
58
+ * @returns {string[]} - Array of extracted strings
59
+ */
60
+ private extract;
61
+ /**
62
+ * Type guard to check if a value is MetricResultSingle<R>.
63
+ *
64
+ * @param {unknown} v - The value to check
65
+ * @returns {v is MetricResultSingle<R>} - True if v is MetricResultSingle<R>
66
+ */
67
+ private isMetricResult;
68
+ /**
69
+ * Type guard to check if a value is CmpStrResult & { raw?: R }.
70
+ *
71
+ * @param {unknown} v - The value to check
72
+ * @returns {v is CmpStrResult & { raw?: R }
73
+ */
74
+ private isCmpStrResult;
75
+ /**
76
+ * Normalizes metric results to a consistent format.
77
+ * Handles both CmpStrResult[] and MetricResultBatch<R> formats.
78
+ *
79
+ * @param {any} results - The raw metric results
80
+ * @returns {MetricResultSingle<R>[]} - Normalized single results array
81
+ */
82
+ private normalizeResults;
83
+ /**
84
+ * Rebuilds results with original objects attached.
85
+ * IMPORTANT: Results are assumed to be in the same order as sourceData,
86
+ * or they must include index information via the source/target mapping.
87
+ *
88
+ * @param {MetricResultSingle<R>[]} results - The normalized metric results
89
+ * @param {T[]} sourceData - The source data array for object attachment
90
+ * @param {string[]} extractedStrings - The extracted strings array for index mapping
91
+ * @param {boolean} [removeZero] - Whether to remove zero similarity results
92
+ * @param {boolean} [objectsOnly] - Return only objects without metadata
93
+ * @returns {StructuredDataResult<T, R>[] | T[]} - Results with objects (or just objects if objectsOnly=true)
94
+ */
95
+ private rebuild;
96
+ /**
97
+ * Sorts results in-place by match score.
98
+ *
99
+ * @param {MetricResultSingle<R>[]} results - The results to sort
100
+ * @param {string|boolean} [sort] - Sort direction (asc, desc, or boolean true=desc)
101
+ * @returns {MetricResultSingle<R>[]} - Sorted results
102
+ */
103
+ private sort;
104
+ /**
105
+ * Performs a lookup with a synchronous comparison function.
106
+ *
107
+ * @param {() => CmpFnResult<R>} fn - The comparison function
108
+ * @param {string[]} extractedStrings - The extracted strings for index mapping
109
+ * @param {StructuredDataOptions} [opt] - Additional options
110
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - The lookup results
111
+ */
112
+ private performLookup;
113
+ /**
114
+ * Performs a lookup with an asynchronous comparison function.
115
+ *
116
+ * @param {() => Promise<CmpFnResult<R>>} fn - The async comparison function
117
+ * @param {string[]} extractedStrings - The extracted strings for index mapping
118
+ * @param {StructuredDataOptions} [opt] - Additional options
119
+ * @returns {Promise<StructuredDataBatchResult<T, R>|T[]>} - The async lookup results
120
+ */
121
+ private performLookupAsync;
122
+ /**
123
+ * Performs a batch comparison against a query string.
124
+ *
125
+ * @param {() => CmpFnResult<R>} fn - The comparison function
126
+ * @param {string} query - The query string to compare against
127
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
128
+ * @returns {StructuredDataBatchResult<T, R>|T[]} - Results with objects or just objects
129
+ */
130
+ lookup(fn: (a: string, b: string[], opt?: CmpStrOptions) => CmpFnResult<R>, query: string, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
131
+ /**
132
+ * Performs a pairwise comparison against another array of objects.
133
+ *
134
+ * @template O - The type of objects in the other array
135
+ * @param {() => CmpFnResult<R>} fn - The comparison function
136
+ * @param {O[]} other - The other array of objects
137
+ * @param {keyof O} otherKey - The property key in the other array
138
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
139
+ * @returns {StructuredDataBatchResult<T, R> | T[]} - Results with objects or just objects
140
+ */
141
+ lookupPairs<O = any>(fn: (a: string[], b: string[], opt?: CmpStrOptions) => CmpFnResult<R>, other: O[], otherKey: keyof O, opt?: StructuredDataOptions): StructuredDataBatchResult<T, R> | T[];
142
+ /**
143
+ * Asynchronously performs a batch comparison against a query string.
144
+ *
145
+ * @param {() => Promise<CmpFnResult<R>>} fn - The async comparison function
146
+ * @param {string} query - The query string to compare against
147
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
148
+ * @returns {Promise<StructuredDataBatchResult<T, R> | T[]>} - Async results
149
+ */
150
+ lookupAsync(fn: (a: string, b: string[], opt?: CmpStrOptions) => Promise<CmpFnResult<R>>, query: string, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
151
+ /**
152
+ * Asynchronously performs a pairwise comparison against another array of objects.
153
+ *
154
+ * @template O - The type of objects in the other array
155
+ * @param {() => Promise<CmpFnResult<R>>} fn - The async comparison function
156
+ * @param {O[]} other - The other array of objects
157
+ * @param {keyof O} otherKey - The property key in the other array
158
+ * @param {StructuredDataOptions} [opt] - Optional lookup options
159
+ * @returns {Promise<StructuredDataBatchResult<T, R> | T[]>} - Async results
160
+ */
161
+ lookupPairsAsync<O = any>(fn: (a: string[], b: string[], opt?: CmpStrOptions) => Promise<CmpFnResult<R>>, other: O[], otherKey: keyof O, opt?: StructuredDataOptions): Promise<StructuredDataBatchResult<T, R> | T[]>;
162
+ }
@@ -45,7 +45,7 @@ export interface ProfilerService<T> {
45
45
  /**
46
46
  * PoolType enumerates the supported buffer types for the Pool utility.
47
47
  */
48
- export type PoolType = 'uint16' | 'number[]' | 'set' | 'map';
48
+ export type PoolType = 'uint16' | 'number[]' | 'string[]' | 'set' | 'map';
49
49
  /**
50
50
  * PoolConfig defines the configuration for a buffer pool.
51
51
  */
@@ -323,3 +323,37 @@ export interface CmpStrResult {
323
323
  target: string;
324
324
  match: number;
325
325
  }
326
+ /**
327
+ * CompareFnResult represents the possible return types for comparison functions.
328
+ *
329
+ * @template R - The type of the raw result
330
+ */
331
+ export type CmpFnResult<R> = MetricResultSingle<R>[] | (CmpStrResult & {
332
+ raw?: R;
333
+ })[] | null | undefined;
334
+ /**
335
+ * StructuredDataResult represents a lookup result with original object attached.
336
+ *
337
+ * @template T - The type of the original object
338
+ * @template R - The type of the metric raw result
339
+ */
340
+ export interface StructuredDataResult<T = any, R = MetricRaw> {
341
+ obj: T;
342
+ key: string | number | symbol;
343
+ result: CmpStrResult;
344
+ raw?: R;
345
+ }
346
+ /**
347
+ * StructuredDataBatchResult is an array of lookup results.
348
+ *
349
+ * @template T - The type of the original object
350
+ * @template R - The type of the metric raw result
351
+ */
352
+ export type StructuredDataBatchResult<T = any, R = MetricRaw> = StructuredDataResult<T, R>[];
353
+ /**
354
+ * StructuredDataOptions configures the lookup behavior.
355
+ */
356
+ export interface StructuredDataOptions extends Omit<CmpStrOptions, 'raw'> {
357
+ sort?: boolean | 'asc' | 'desc';
358
+ objectsOnly?: boolean;
359
+ }