Skip to content

Commit fa8e33d

Browse files
committed
feat: add RegExp support to excludeKeys option for json2csv
1 parent cbe0d6e commit fa8e33d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/json2csv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
8585
return keyPaths.filter((keyPath) => {
8686
for (const excludedKey of options.excludeKeys) {
8787
// Only match if the excludedKey appears at the beginning of the string so we don't accidentally match a key farther down in a key path
88-
const regex = new RegExp(`^${excludedKey}`);
88+
const regex = excludedKey instanceof RegExp ? excludedKey : new RegExp(`^${excludedKey}`);
8989

9090
if (excludedKey === keyPath || keyPath.match(regex)) {
9191
return false; // Exclude the key

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export interface Json2CsvOptions extends SharedConverterOptions {
155155
/**
156156
* Specify the keys that should be excluded from the output.
157157
*/
158-
excludeKeys?: string[];
158+
excludeKeys?: (string | RegExp)[];
159159

160160
/**
161161
* Specify how values should be converted into CSV format. This function is provided a single field value at a time and must return a `String`.

0 commit comments

Comments
 (0)