-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Change data input and display format to csv (#3)
Signed-off-by: Stanislaw Mazowiecki <[email protected]>
- Loading branch information
1 parent
872269d
commit 0ad2ae0
Showing
6 changed files
with
56 additions
and
13 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,43 @@ | ||
import { parseCSV } from '@/utils/parseCSV'; | ||
|
||
describe('parseCSV', () => { | ||
it('should return array of strings from separated by commas string ', async () => { | ||
const input = '0.0.123, 0.0.124, 0.0.125, 0.0.126'; | ||
|
||
const result = parseCSV(input); | ||
|
||
expect(result).toEqual(['0.0.123', '0.0.124', '0.0.125', '0.0.126']); | ||
}); | ||
|
||
it('should return array of strings from separated by commas without space string', async () => { | ||
const input = '0.0.123,0.0.124,0.0.125,0.0.126'; | ||
|
||
const result = parseCSV(input); | ||
|
||
expect(result).toEqual(['0.0.123', '0.0.124', '0.0.125', '0.0.126']); | ||
}); | ||
|
||
it('should return array of strings from separated by spaces string ', async () => { | ||
const input = '0.0.123 0.0.124 0.0.125 0.0.126'; | ||
|
||
const result = parseCSV(input); | ||
|
||
expect(result).toEqual(['0.0.123', '0.0.124', '0.0.125', '0.0.126']); | ||
}); | ||
|
||
it('should return array of strings from separated by commas and spaces string ', async () => { | ||
const input = '0.0.123, 0.0.124 0.0.125, 0.0.126'; | ||
|
||
const result = parseCSV(input); | ||
|
||
expect(result).toEqual(['0.0.123', '0.0.124', '0.0.125', '0.0.126']); | ||
}); | ||
|
||
it('should allow line breaks(enter key) between strings', () => { | ||
const input = '0.0.123\n' + '0.0.124'; | ||
|
||
const result = parseCSV(input); | ||
|
||
expect(result).toEqual(['0.0.123', '0.0.124']); | ||
}); | ||
}); |
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,4 @@ | ||
export const parseCSV = (input: string): string[] => { | ||
const splitValues = input.split(/,|\s|\n/); | ||
return splitValues.map((item) => item.trim()).filter((item) => item !== ''); | ||
}; |