@truto/truto-jsonata 1.0.47 → 1.0.49
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/README.md +86 -1
- package/dist/browser/index.js +5574 -2202
- package/dist/browser/index.js.map +59 -21
- package/dist/cjs/index.cjs +5574 -2202
- package/dist/cjs/index.cjs.map +59 -21
- package/dist/esm/index.js +38 -6
- package/dist/esm/index.js.map +6 -5
- package/dist/functions/diceCoefficient.d.ts +2 -0
- package/dist/functions/digest.d.ts +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -999,7 +999,13 @@ Blob (13 bytes) {
|
|
|
999
999
|
<details>
|
|
1000
1000
|
<summary>digest(text, algorithm = 'SHA-256', stringType = 'hex')</summary>
|
|
1001
1001
|
|
|
1002
|
-
Generates a cryptographic hash of the input text using a specified hashing algorithm and output format.
|
|
1002
|
+
Generates a cryptographic hash of the input text using a specified hashing algorithm and output format.
|
|
1003
|
+
|
|
1004
|
+
**Supported Algorithms:**
|
|
1005
|
+
- SHA algorithms (SHA-1, SHA-256, SHA-384, SHA-512) use the [Web Crypto API's `crypto.subtle.digest()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest). See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#supported_algorithms) for the complete list of supported algorithms.
|
|
1006
|
+
- MD5 uses the `md5.js` library (since MD5 is not supported by Web Crypto API).
|
|
1007
|
+
|
|
1008
|
+
**Output Formats:** 'hex', 'base64', and 'base64-urlSafe'.
|
|
1003
1009
|
|
|
1004
1010
|
**Example:**
|
|
1005
1011
|
|
|
@@ -1037,7 +1043,39 @@ const expression3 = trutoJsonata("$digest(text, algorithm, stringType)");
|
|
|
1037
1043
|
expression3.evaluate({ text: text3, algorithm: algorithm3, stringType: stringType3 }).then(result => {
|
|
1038
1044
|
console.log(result);
|
|
1039
1045
|
// Output: "Xh3mV+fAAG7ScGPjo4PElmR3obnFzGrxnbwGpEE4lI4="
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
// Example 4: MD5 Algorithm, Hex Output
|
|
1049
|
+
const text4 = '42';
|
|
1050
|
+
const algorithm4 = 'MD5';
|
|
1051
|
+
const stringType4 = 'hex';
|
|
1040
1052
|
|
|
1053
|
+
const expression4 = trutoJsonata("$digest(text, algorithm, stringType)");
|
|
1054
|
+
expression4.evaluate({ text: text4, algorithm: algorithm4, stringType: stringType4 }).then(result => {
|
|
1055
|
+
console.log(result);
|
|
1056
|
+
// Output: "a1d0c6e83f027327d8461063f4ac58a6"
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
// Example 5: MD5 Algorithm, Base64 Output
|
|
1060
|
+
const text5 = '42';
|
|
1061
|
+
const algorithm5 = 'MD5';
|
|
1062
|
+
const stringType5 = 'base64';
|
|
1063
|
+
|
|
1064
|
+
const expression5 = trutoJsonata("$digest(text, algorithm, stringType)");
|
|
1065
|
+
expression5.evaluate({ text: text5, algorithm: algorithm5, stringType: stringType5 }).then(result => {
|
|
1066
|
+
console.log(result);
|
|
1067
|
+
// Output: "odDG6D8CcyfYRgYj9KxYpg=="
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
// Example 6: MD5 Algorithm, Base64 URL-Safe Output
|
|
1071
|
+
const text6 = '42';
|
|
1072
|
+
const algorithm6 = 'MD5';
|
|
1073
|
+
const stringType6 = 'base64-urlSafe';
|
|
1074
|
+
|
|
1075
|
+
const expression6 = trutoJsonata("$digest(text, algorithm, stringType)");
|
|
1076
|
+
expression6.evaluate({ text: text6, algorithm: algorithm6, stringType: stringType6 }).then(result => {
|
|
1077
|
+
console.log(result);
|
|
1078
|
+
// Output: "odDG6D8CcyfYRgYj9KxYpg"
|
|
1041
1079
|
});
|
|
1042
1080
|
|
|
1043
1081
|
```
|
|
@@ -2116,6 +2154,53 @@ expression.evaluate({ input, possibleValues, threshold }).then(result => { conso
|
|
|
2116
2154
|
|
|
2117
2155
|
</details>
|
|
2118
2156
|
|
|
2157
|
+
<details>
|
|
2158
|
+
<summary>diceCoefficient(value1, value2)</summary>
|
|
2159
|
+
|
|
2160
|
+
Calculates the Dice Coefficient similarity score between two strings. The Dice Coefficient measures the similarity of two strings based on their bigrams (pairs of adjacent characters). The function normalizes both strings (converts to lowercase and removes non-alphanumeric characters) before comparison.
|
|
2161
|
+
|
|
2162
|
+
**Parameters:**
|
|
2163
|
+
|
|
2164
|
+
- **value1**: The first string to compare.
|
|
2165
|
+
- **value2**: The second string to compare.
|
|
2166
|
+
|
|
2167
|
+
**Returns:**
|
|
2168
|
+
|
|
2169
|
+
A number between `0.0` (completely different) and `1.0` (identical), representing the similarity score.
|
|
2170
|
+
|
|
2171
|
+
**Example Usage:**
|
|
2172
|
+
|
|
2173
|
+
```javascript
|
|
2174
|
+
import trutoJsonata from '@truto/truto-jsonata';
|
|
2175
|
+
|
|
2176
|
+
// Example 1: Identical strings return 1.0
|
|
2177
|
+
const expression1 = trutoJsonata("$diceCoefficient('hello', 'hello')");
|
|
2178
|
+
expression1.evaluate({}).then(result => { console.log(result); });
|
|
2179
|
+
// Output: 1.0
|
|
2180
|
+
|
|
2181
|
+
// Example 2: Similar strings return a score between 0 and 1
|
|
2182
|
+
const expression2 = trutoJsonata("$diceCoefficient('apple', 'appl')");
|
|
2183
|
+
expression2.evaluate({}).then(result => { console.log(result); });
|
|
2184
|
+
// Output: 0.8 (or similar value depending on similarity)
|
|
2185
|
+
|
|
2186
|
+
// Example 3: Case-insensitive comparison
|
|
2187
|
+
const expression3 = trutoJsonata("$diceCoefficient('Hello', 'HELLO')");
|
|
2188
|
+
expression3.evaluate({}).then(result => { console.log(result); });
|
|
2189
|
+
// Output: 1.0
|
|
2190
|
+
|
|
2191
|
+
// Example 4: Non-alphanumeric characters are ignored
|
|
2192
|
+
const expression4 = trutoJsonata("$diceCoefficient('hello-world', 'hello world')");
|
|
2193
|
+
expression4.evaluate({}).then(result => { console.log(result); });
|
|
2194
|
+
// Output: 1.0
|
|
2195
|
+
|
|
2196
|
+
// Example 5: Completely different strings return 0.0
|
|
2197
|
+
const expression5 = trutoJsonata("$diceCoefficient('hello', 'xyz')");
|
|
2198
|
+
expression5.evaluate({}).then(result => { console.log(result); });
|
|
2199
|
+
// Output: 0.0
|
|
2200
|
+
```
|
|
2201
|
+
|
|
2202
|
+
</details>
|
|
2203
|
+
|
|
2119
2204
|
<details>
|
|
2120
2205
|
<summary>sortNodes(array, idKey = 'id',
|
|
2121
2206
|
parentIdKey = 'parent_id',
|