Skip to content

Commit

Permalink
midflight, more progress on #247
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodrig committed Feb 23, 2024
1 parent c74972e commit 46db726
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/json2csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
if (options.keys) {
options.keys = keyStrings;

const matchedKeys = keyStrings.flatMap((userProvidedKey) => {
const detectedKeysMatchingProvidedKeys = keyStrings.flatMap((userProvidedKey) => {
const regex = new RegExp(`^${userProvidedKey}`);
const matchedKeys = [];

for (const detectedKey of processed) {
if (userProvidedKey === detectedKey || detectedKey.match(regex)) {
matchedKeys.push(detectedKey);
Expand All @@ -195,6 +196,8 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
return matchedKeys;
});

const matchedKeys = Array.from(new Set(detectedKeysMatchingProvidedKeys));

keyStrings.forEach((providedKey) => {
const regex = new RegExp(`^${providedKey}`);
const anyMatch = utils.anyKeysMatch(matchedKeys, regex);
Expand Down

0 comments on commit 46db726

Please sign in to comment.