Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class CsvFileReader<T> {
- data: T[] = []
- constructor(public file: string) {}
- abstract mapRow(row: string[]): T
- read() {
- this.data = this.file
- .split('\n')
- .map((row: string): string[] => {
- return row.split(',')
- })
- .map(this.mapRow)
- }
- }
- type matchData = [string, string, string, number, number, string]
- class MatchReader extends CsvFileReader<matchData> {
- mapRow(row: string[]): matchData {
- return [
- row[0],
- row[1],
- row[2],
- +row[3],
- +row[4],
- row[6],
- ]
- }
- }
- const reader = new MatchReader("a,b,c,15,7,-,X");
- reader.read();
- console.log(reader);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement