@truto/truto-jsonata 1.0.46 → 1.0.48

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.
@@ -50683,18 +50683,88 @@ var digest = async (text, algorithm = "SHA-256", stringType = "hex") => {
50683
50683
  };
50684
50684
  var digest_default = digest;
50685
50685
 
50686
+ // node_modules/n-gram/index.js
50687
+ var bigram = nGram(2);
50688
+ var trigram = nGram(3);
50689
+ function nGram(n2) {
50690
+ if (typeof n2 !== "number" || Number.isNaN(n2) || n2 < 1 || n2 === Number.POSITIVE_INFINITY) {
50691
+ throw new Error("`" + n2 + "` is not a valid argument for `n-gram`");
50692
+ }
50693
+ return grams;
50694
+ function grams(value) {
50695
+ const nGrams = [];
50696
+ if (value === null || value === undefined) {
50697
+ return nGrams;
50698
+ }
50699
+ const source = typeof value.slice === "function" ? value : String(value);
50700
+ let index = source.length - n2 + 1;
50701
+ if (index < 1) {
50702
+ return nGrams;
50703
+ }
50704
+ while (index--) {
50705
+ nGrams[index] = source.slice(index, index + n2);
50706
+ }
50707
+ return nGrams;
50708
+ }
50709
+ }
50710
+
50711
+ // node_modules/dice-coefficient/index.js
50712
+ function diceCoefficient(value, other2) {
50713
+ const left = toPairs(value);
50714
+ const right = toPairs(other2);
50715
+ let index = -1;
50716
+ let intersections = 0;
50717
+ while (++index < left.length) {
50718
+ const leftPair = left[index];
50719
+ let offset2 = -1;
50720
+ while (++offset2 < right.length) {
50721
+ const rightPair = right[offset2];
50722
+ if (leftPair === rightPair) {
50723
+ intersections++;
50724
+ right[offset2] = "";
50725
+ break;
50726
+ }
50727
+ }
50728
+ }
50729
+ return 2 * intersections / (left.length + right.length);
50730
+ }
50731
+ function toPairs(value) {
50732
+ if (Array.isArray(value)) {
50733
+ return value.map((bigram2) => normalize(bigram2));
50734
+ }
50735
+ const normal = normalize(value);
50736
+ return normal.length === 1 ? [normal] : bigram(normal);
50737
+ }
50738
+ function normalize(value) {
50739
+ return String(value).toLowerCase();
50740
+ }
50741
+
50742
+ // src/functions/diceCoefficient.ts
50743
+ function getNormalizedString(value) {
50744
+ return value.toLowerCase().replace(/[^a-z0-9]/g, "");
50745
+ }
50746
+ function _diceCoefficient(value, value2) {
50747
+ if (value === value2) {
50748
+ return 1;
50749
+ }
50750
+ const normalizedValue = getNormalizedString(value);
50751
+ const normalizedValue2 = getNormalizedString(value2);
50752
+ return diceCoefficient(normalizedValue, normalizedValue2);
50753
+ }
50754
+ var diceCoefficient_default = _diceCoefficient;
50755
+
50686
50756
  // src/functions/dtFromFormat.ts
50687
- function dtFromFormat(date, format) {
50757
+ function dtFromFormat(date, format, options3) {
50688
50758
  if (format === "RFC2822") {
50689
- return DateTime.fromRFC2822(date);
50759
+ return DateTime.fromRFC2822(date, options3);
50690
50760
  }
50691
50761
  if (format === "ISO") {
50692
- return DateTime.fromISO(date);
50762
+ return DateTime.fromISO(date, options3);
50693
50763
  }
50694
50764
  if (format === "fromSeconds") {
50695
- return DateTime.fromSeconds(parseInt(date));
50765
+ return DateTime.fromSeconds(parseInt(date), options3);
50696
50766
  }
50697
- return DateTime.fromFormat(date, format);
50767
+ return DateTime.fromFormat(date, format, options3);
50698
50768
  }
50699
50769
  var dtFromFormat_default = dtFromFormat;
50700
50770
 
@@ -51490,70 +51560,14 @@ function jsToXml_default(json, options3 = { compact: true, spaces: 4 }) {
51490
51560
  return import_xml_js.js2xml(json, options3);
51491
51561
  }
51492
51562
 
51493
- // node_modules/n-gram/index.js
51494
- var bigram = nGram(2);
51495
- var trigram = nGram(3);
51496
- function nGram(n2) {
51497
- if (typeof n2 !== "number" || Number.isNaN(n2) || n2 < 1 || n2 === Number.POSITIVE_INFINITY) {
51498
- throw new Error("`" + n2 + "` is not a valid argument for `n-gram`");
51499
- }
51500
- return grams;
51501
- function grams(value) {
51502
- const nGrams = [];
51503
- if (value === null || value === undefined) {
51504
- return nGrams;
51505
- }
51506
- const source = typeof value.slice === "function" ? value : String(value);
51507
- let index = source.length - n2 + 1;
51508
- if (index < 1) {
51509
- return nGrams;
51510
- }
51511
- while (index--) {
51512
- nGrams[index] = source.slice(index, index + n2);
51513
- }
51514
- return nGrams;
51515
- }
51516
- }
51517
-
51518
- // node_modules/dice-coefficient/index.js
51519
- function diceCoefficient(value, other2) {
51520
- const left = toPairs(value);
51521
- const right = toPairs(other2);
51522
- let index = -1;
51523
- let intersections = 0;
51524
- while (++index < left.length) {
51525
- const leftPair = left[index];
51526
- let offset2 = -1;
51527
- while (++offset2 < right.length) {
51528
- const rightPair = right[offset2];
51529
- if (leftPair === rightPair) {
51530
- intersections++;
51531
- right[offset2] = "";
51532
- break;
51533
- }
51534
- }
51535
- }
51536
- return 2 * intersections / (left.length + right.length);
51537
- }
51538
- function toPairs(value) {
51539
- if (Array.isArray(value)) {
51540
- return value.map((bigram2) => normalize(bigram2));
51541
- }
51542
- const normal = normalize(value);
51543
- return normal.length === 1 ? [normal] : bigram(normal);
51544
- }
51545
- function normalize(value) {
51546
- return String(value).toLowerCase();
51547
- }
51548
-
51549
51563
  // src/functions/mostSimilar.ts
51550
- function getNormalizedString(value) {
51564
+ function getNormalizedString2(value) {
51551
51565
  return value.toLowerCase().replace(/[^a-z0-9]/g, "");
51552
51566
  }
51553
51567
  function mostSimilar(value, possibleValues, threshold = 0.8) {
51554
- const normalizedValue = getNormalizedString(value);
51568
+ const normalizedValue = getNormalizedString2(value);
51555
51569
  const result = reduce_default(possibleValues, (acc, possibleValue) => {
51556
- const normalizedPossibleValue = getNormalizedString(possibleValue);
51570
+ const normalizedPossibleValue = getNormalizedString2(possibleValue);
51557
51571
  const similarity = diceCoefficient(normalizedValue, normalizedPossibleValue);
51558
51572
  if (similarity > acc.similarity) {
51559
51573
  return { similarity, value: possibleValue };
@@ -67919,6 +67933,7 @@ function registerJsonataExtensions(expression) {
67919
67933
  expression.registerFunction("uuid", uuid_default);
67920
67934
  expression.registerFunction("getArrayBuffer", getArrayBuffer_default);
67921
67935
  expression.registerFunction("mostSimilar", mostSimilar_default);
67936
+ expression.registerFunction("diceCoefficient", diceCoefficient_default);
67922
67937
  expression.registerFunction("sortNodes", sortNodes_default);
67923
67938
  expression.registerFunction("blob", blob_default);
67924
67939
  expression.registerFunction("convertHtmlToMarkdown", convertHtmlToMarkdown_default);
@@ -67989,4 +68004,4 @@ function trutoJsonata(expression) {
67989
68004
  return registerJsonataExtensions(import_jsonata.default(expression));
67990
68005
  }
67991
68006
 
67992
- //# debugId=2B39BDF338CBF36564756E2164756E21
68007
+ //# debugId=D940E4B7DB5FCE8864756E2164756E21