Skip to content

Commit 33f74d1

Browse files
committed
feat: allow for partial matching of excludeKeys against CSV keys
This will allow for the filtering of keys nested underneath a specific key prefix, such as the use case of not wanting to include the keys present in an array when `expandArrayObjects` is set to `true`. This addresses the use case presented in #244.
1 parent 7b32338 commit 33f74d1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/json2csv.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
8282
function filterExcludedKeys(keyPaths: string[]) {
8383
if (options.excludeKeys) {
8484
return keyPaths.filter((keyPath) => {
85-
return !options.excludeKeys.includes(keyPath);
85+
for (const excludedKey of options.excludeKeys) {
86+
const regex = new RegExp(excludedKey);
87+
if (excludedKey === keyPath || keyPath.match(regex)) {
88+
return false; // Exclude the key
89+
}
90+
}
91+
return true; // Otherwise, include the key
8692
});
8793
}
8894

0 commit comments

Comments
 (0)