@truto/truto-jsonata 1.0.44 → 1.0.46

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 CHANGED
@@ -829,6 +829,81 @@ expression.evaluate({}).then(result => { console.log(result); });
829
829
 
830
830
  </details>
831
831
 
832
+ <details>
833
+ <summary> jsonToCsv(json, options)</summary>
834
+
835
+ Converts an array of JSON objects to CSV format. Uses the [@json2csv/plainjs](https://juanjodiaz.github.io/json2csv/#/parsers/parser) library for conversion.
836
+
837
+ **Parameters:**
838
+
839
+ - **json**: An array of objects (or a single object) to convert to CSV. Null and undefined values are automatically filtered out.
840
+ - **options** _(Optional)_: Configuration options for the CSV parser. Supports all options from `@json2csv/plainjs`, including:
841
+ - **delimiter**: Custom delimiter (default: `','`)
842
+ - **header**: Include/exclude header row (default: `true`)
843
+ - **fields**: Array of field objects with `label` and `value` properties for custom headers
844
+ - See [@json2csv/plainjs documentation](https://juanjodiaz.github.io/json2csv/#/parsers/parser?id=parameters) for all available options
845
+
846
+ **Example:**
847
+
848
+ ```javascript
849
+ import trutoJsonata from '@truto/truto-jsonata';
850
+
851
+ // Example 1: Basic conversion
852
+ const data = [
853
+ { name: 'John', age: 30, city: 'New York' },
854
+ { name: 'Jane', age: 25, city: 'Los Angeles' }
855
+ ];
856
+ const expression = trutoJsonata("$jsonToCsv(data, {})");
857
+ expression.evaluate({ data }).then(result => {
858
+ console.log(result);
859
+ // Output: "name","age","city"
860
+ // "John",30,"New York"
861
+ // "Jane",25,"Los Angeles"
862
+ });
863
+
864
+ // Example 2: Custom delimiter
865
+ const expression2 = trutoJsonata("$jsonToCsv(data, { delimiter: ';' })");
866
+ expression2.evaluate({ data }).then(result => {
867
+ console.log(result);
868
+ // Output: "name";"age";"city"
869
+ // "John";30;"New York"
870
+ // "Jane";25;"Los Angeles"
871
+ });
872
+
873
+ // Example 3: Custom headers
874
+ const options = {
875
+ fields: [
876
+ { label: 'Full Name', value: 'name' },
877
+ { label: 'Years', value: 'age' }
878
+ ]
879
+ };
880
+ const expression3 = trutoJsonata("$jsonToCsv(data, options)");
881
+ expression3.evaluate({ data, options }).then(result => {
882
+ console.log(result);
883
+ // Output: "Full Name","Years"
884
+ // "John",30
885
+ // "Jane",25
886
+ });
887
+
888
+ // Example 4: Without header
889
+ const expression4 = trutoJsonata("$jsonToCsv(data, { header: false })");
890
+ expression4.evaluate({ data }).then(result => {
891
+ console.log(result);
892
+ // Output: "John",30,"New York"
893
+ // "Jane",25,"Los Angeles"
894
+ });
895
+
896
+ // Example 5: Empty array returns empty string
897
+ const emptyData = [];
898
+ const expression5 = trutoJsonata("$jsonToCsv(emptyData, {})");
899
+ expression5.evaluate({ emptyData }).then(result => {
900
+ console.log(result);
901
+ // Output: ""
902
+ });
903
+ ```
904
+
905
+ </details>
906
+
832
907
  <details>
833
908
  <summary> getMimeType(fileName)</summary>
834
909
 
@@ -1532,6 +1607,44 @@ Output:
1532
1607
 
1533
1608
  </details>
1534
1609
 
1610
+ <details>
1611
+ <summary>convertMdToPdf(markdown, options = { title: '', pageSize: 'a4', embedImages: false, pageMargins: [40, 60, 40, 60], defaultStyle: { fontSize: 12, lineHeight: 1.4 } })</summary>
1612
+
1613
+ Converts Markdown text to a PDF `Blob` using jsPDF.
1614
+
1615
+ **Example:**
1616
+
1617
+ ```javascript
1618
+ import trutoJsonata from '@truto/truto-jsonata'
1619
+
1620
+ const markdown = `# Title\n\nThis is a paragraph.`
1621
+ const expression = trutoJsonata("$convertMdToPdf(markdown)")
1622
+ expression.evaluate({ markdown }).then(blob => {
1623
+ console.log(blob) // Blob { type: 'application/pdf' }
1624
+ })
1625
+ ```
1626
+
1627
+ **Options:**
1628
+ - `title`: Optional document title
1629
+ - `pageSize`: jsPDF page size (e.g., `'a4'`, `'LETTER'`)
1630
+ - `embedImages`: Reserved for future use
1631
+ - `pageMargins`: `[left, top, right, bottom]` in points
1632
+ - `defaultStyle`: `{ fontSize: number, lineHeight: number }`
1633
+
1634
+ If your transport requires a JSON-serializable value, convert the PDF Blob to a data URI string and decode it later:
1635
+
1636
+ ```javascript
1637
+ import trutoJsonata from '@truto/truto-jsonata'
1638
+
1639
+ const markdown = `# Report\nGenerated content`
1640
+ const expr = trutoJsonata("$getDataUri($convertMdToPdf(markdown), 'application/pdf')")
1641
+ expr.evaluate({ markdown }).then(dataUri => {
1642
+ // dataUri starts with 'data:application/pdf;base64,'
1643
+ console.log(typeof dataUri, dataUri.startsWith('data:application/pdf;base64,'))
1644
+ })
1645
+ ```
1646
+ </details>
1647
+
1535
1648
  ---
1536
1649
 
1537
1650
  ### Array and Object Utilities (Lodash Enhancements)