-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Update the parsing logic to correctly split the values and remove any leading or trailing spaces
- Loading branch information
1 parent
bbe685d
commit 572b6f2
Showing
5 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { parseCommaSeparatedValues } from "./parseCommaSeparatedValues"; | ||
|
||
describe("parseCommaSeparatedValues", () => { | ||
it("should correctly parse a single value with no spaces", () => { | ||
expect(parseCommaSeparatedValues("value")).toEqual(["value"]); | ||
}); | ||
|
||
it("should correctly parse multiple values with spaces", () => { | ||
expect(parseCommaSeparatedValues("apple, banana, cherry")).toEqual([ | ||
"apple", | ||
"banana", | ||
"cherry", | ||
]); | ||
}); | ||
|
||
it("should handle leading and trailing spaces", () => { | ||
expect(parseCommaSeparatedValues(" apple, banana , cherry ")).toEqual([ | ||
"apple", | ||
"banana", | ||
"cherry", | ||
]); | ||
}); | ||
|
||
it("should ignore empty strings between commas", () => { | ||
expect(parseCommaSeparatedValues("apple,,banana, ,cherry")).toEqual([ | ||
"apple", | ||
"banana", | ||
"cherry", | ||
]); | ||
}); | ||
|
||
it("should return an empty array if the input is only commas or spaces", () => { | ||
expect(parseCommaSeparatedValues(" , , , ")).toEqual([]); | ||
}); | ||
|
||
it("should return an empty array if the input is an empty string", () => { | ||
expect(parseCommaSeparatedValues("")).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const parseCommaSeparatedValues = (input: string): string[] => { | ||
return input | ||
.split(",") | ||
.map((s) => s.trim()) | ||
.filter(Boolean); | ||
}; |