Skip to content

Commit

Permalink
resolve deepMergeStrings unique values
Browse files Browse the repository at this point in the history
  • Loading branch information
SutuSebastian committed Oct 29, 2024
1 parent c3bd201 commit de5450b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/ui/src/helpers/deep-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ export function deepMergeStrings(merge: (values: string[]) => string) {
return deepmergeCustom({
mergeOthers: (values, utils) => {
if (values.some((value) => typeof value === "string")) {
return merge([...new Set(values.filter((value) => typeof value === "string"))]);
const strings = values.filter((value) => typeof value === "string");
const stringMap = new Set<string>();
const uniqueStrings: string[] = [];

for (const string of strings) {
const parts = [...new Set(string.split(/\s+/))];

uniqueStrings.push(parts.filter((part) => !stringMap.has(part)).join(" "));

for (const part of parts) {
stringMap.add(part);
}
}

return merge(uniqueStrings);
}

return utils.defaultMergeFunctions.mergeOthers(values);
return utils.actions.defaultMerge;
},
});
}

0 comments on commit de5450b

Please sign in to comment.