From feeec3b829fb82d2e12d443ef4153dfaef345fc4 Mon Sep 17 00:00:00 2001 From: mrodrig Date: Sat, 24 Feb 2024 22:44:52 -0500 Subject: [PATCH] feat: add arrayIndexesAsKeys option support for #207 --- src/constants.ts | 1 + src/json2csv.ts | 1 + src/types.ts | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index 9115a9d..ac59c3b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -18,6 +18,7 @@ export const errors = { }; export const defaultJson2CsvOptions: DefaultJson2CsvOptions = { + arrayIndexesAsKeys: false, checkSchemaDifferences: false, delimiter : { field : ',', diff --git a/src/json2csv.ts b/src/json2csv.ts index 8b1e30f..cd4ae01 100755 --- a/src/json2csv.ts +++ b/src/json2csv.ts @@ -12,6 +12,7 @@ export const Json2Csv = function(options: FullJson2CsvOptions) { customValueParser = options.parseValue && typeof options.parseValue === 'function' ? options.parseValue : null, expandingWithoutUnwinding = options.expandArrayObjects && !options.unwindArrays, deeksOptions = { + arrayIndexesAsKeys: options.arrayIndexesAsKeys, expandNestedObjects: options.expandNestedObjects, expandArrayObjects: expandingWithoutUnwinding, ignoreEmptyArraysWhenExpanding: expandingWithoutUnwinding, diff --git a/src/types.ts b/src/types.ts index fbe42d9..d652fdf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,6 +87,11 @@ export interface Csv2JsonOptions extends Omit { } export interface Json2CsvOptions extends SharedConverterOptions { + /** Should array indexes be included in the generated keys? + * @default false + */ + arrayIndexesAsKeys?: boolean; + /** * Should all documents have the same schema? * @default false