@truto/truto-jsonata 1.0.45 → 1.0.47

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