Skip to content

Commit feeec3b

Browse files
committed
feat: add arrayIndexesAsKeys option support for #207
1 parent 6fccca0 commit feeec3b

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const errors = {
1818
};
1919

2020
export const defaultJson2CsvOptions: DefaultJson2CsvOptions = {
21+
arrayIndexesAsKeys: false,
2122
checkSchemaDifferences: false,
2223
delimiter : {
2324
field : ',',

src/json2csv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
1212
customValueParser = options.parseValue && typeof options.parseValue === 'function' ? options.parseValue : null,
1313
expandingWithoutUnwinding = options.expandArrayObjects && !options.unwindArrays,
1414
deeksOptions = {
15+
arrayIndexesAsKeys: options.arrayIndexesAsKeys,
1516
expandNestedObjects: options.expandNestedObjects,
1617
expandArrayObjects: expandingWithoutUnwinding,
1718
ignoreEmptyArraysWhenExpanding: expandingWithoutUnwinding,

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ export interface Csv2JsonOptions extends Omit<SharedConverterOptions, 'keys'> {
8787
}
8888

8989
export interface Json2CsvOptions extends SharedConverterOptions {
90+
/** Should array indexes be included in the generated keys?
91+
* @default false
92+
*/
93+
arrayIndexesAsKeys?: boolean;
94+
9095
/**
9196
* Should all documents have the same schema?
9297
* @default false

0 commit comments

Comments
 (0)