Skip to content

Commit

Permalink
extractCommaSeparatedValues: Fixed edge cases where the string had …
Browse files Browse the repository at this point in the history
…spaces in determinate positions
  • Loading branch information
alexiglesias93 committed Oct 27, 2021
1 parent 095d015 commit ac40954
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion helpers/extractCommaSeparatedValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ export function extractCommaSeparatedValues<T extends string>(
): string[] | T[] {
const emptyValue = defaultValue ? [defaultValue] : [];
if (!string) return emptyValue;
const items = string.split(/[ ,]+/);

const items = string.split(',').reduce<string[]>((accumulatedValue, currentValue) => {
const value = currentValue.trim();

if (value) accumulatedValue.push(value);

return accumulatedValue;
}, []);

if (compareSource) {
const matches = items.filter((item) => isKeyOf(item, compareSource)) as T[];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finsweet/ts-utils",
"version": "0.20.0",
"version": "0.20.1",
"description": "Typescript utils for custom Webflow projects.",
"main": "index.ts",
"module": "index.ts",
Expand Down

0 comments on commit ac40954

Please sign in to comment.