Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// ------------------------------------------------------------------------------------------
// tsvParse(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseArray = d3Dsv.tsvParse(tsvTestStringWithHeader);
columns = parseArray.columns;
str = parseArray[0]['Year'];
// date = parseArray[0]['Year']; // fails, return value is string
// with row mapper ---------------------------------------------------------------------------
parseMappedArray = d3Dsv.tsvParse(tsvTestStringWithHeader, (rawRow, index, columns) => {
let rr: d3Dsv.DSVRowString = rawRow;
let i: number = index;
let c: string[] = columns;
let pr: ParsedTestObject;
pr = {
year: new Date(+rr['Year'], 0, 1),
make: rr['Make'],
model: rr['Model'],
length: +rr['Length']
};
return pr;
});
num = parseMappedArray[0].length;
// csvParseRows(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseRowsArray = d3Dsv.csvParseRows(csvTestString);
str = parseRowsArray[0][0]; // 'Year' of first row
// date = parseRowsArray[0][0]; // fails, return value is string
// with row mapper ---------------------------------------------------------------------------
parseRowsMappedArray = d3Dsv.csvParseRows(csvTestString, (rawRow, index) => {
let rr: string[] = rawRow;
let i: number = index;
let pr: ParsedTestObject;
pr = {
year: new Date(+rr[0], 0, 1),
make: rr[1],
model: rr[2],
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
model: rr[2],
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// csvFormat(...) ============================================================================
str = d3Dsv.csvFormat(parseRowsMappedArray);
str = d3Dsv.csvFormat(parseRowsMappedArray, columns);
// csvFormatRows(...) ========================================================================
str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------
// tsvParse(...) ============================================================================
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// csvFormat(...) ============================================================================
str = d3Dsv.csvFormat(parseRowsMappedArray);
str = d3Dsv.csvFormat(parseRowsMappedArray, columns);
// csvFormatRows(...) ========================================================================
str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------
// tsvParse(...) ============================================================================
num = parseMappedArray[0].length;
// tsvParseRows(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseRowsArray = d3Dsv.tsvParseRows(tsvTestString);
str = parseRowsArray[0][0]; // 'Year' of first row
// date = parseRowsArray[0][0]; // fails, return value is string
// with row mapper ---------------------------------------------------------------------------
parseRowsMappedArray = d3Dsv.tsvParseRows(tsvTestString, (rawRow, index) => {
let rr: string[] = rawRow;
let i: number = index;
let pr: ParsedTestObject;
pr = {
year: new Date(+rr[0], 0, 1),
make: rr[1],
model: rr[2],
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
});
columns = parseMappedArray.columns;
date = parseMappedArray[0].year;
str = parseMappedArray[0].make;
str = parseMappedArray[0].model;
num = parseMappedArray[0].length;
// tsvParseRows(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseRowsArray = d3Dsv.tsvParseRows(tsvTestString);
str = parseRowsArray[0][0]; // 'Year' of first row
// date = parseRowsArray[0][0]; // fails, return value is string
// with row mapper ---------------------------------------------------------------------------
parseRowsMappedArray = d3Dsv.tsvParseRows(tsvTestString, (rawRow, index) => {
let rr: string[] = rawRow;
let i: number = index;
let pr: ParsedTestObject;
pr = {
year: new Date(+rr[0], 0, 1),
make: rr[1],
model: rr[2],
model: rr[2],
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// tsvFormat(...) ============================================================================
str = d3Dsv.tsvFormat(parseRowsMappedArray);
str = d3Dsv.tsvFormat(parseRowsMappedArray, columns);
// tsvFormatRows(...) ========================================================================
str = d3Dsv.tsvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test DSV Generalized Parsers and Formatters
// ------------------------------------------------------------------------------------------
// Create custom-delimited Parser/Formatter =================================================
length: +rr[3]
};
return pr;
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// tsvFormat(...) ============================================================================
str = d3Dsv.tsvFormat(parseRowsMappedArray);
str = d3Dsv.tsvFormat(parseRowsMappedArray, columns);
// tsvFormatRows(...) ========================================================================
str = d3Dsv.tsvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test DSV Generalized Parsers and Formatters
// ------------------------------------------------------------------------------------------
// Create custom-delimited Parser/Formatter =================================================
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// csvFormat(...) ============================================================================
str = d3Dsv.csvFormat(parseRowsMappedArray);
str = d3Dsv.csvFormat(parseRowsMappedArray, columns);
// csvFormatRows(...) ========================================================================
str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------
// tsvParse(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseArray = d3Dsv.tsvParse(tsvTestStringWithHeader);
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// tsvFormat(...) ============================================================================
str = d3Dsv.tsvFormat(parseRowsMappedArray);
str = d3Dsv.tsvFormat(parseRowsMappedArray, columns);
// tsvFormatRows(...) ========================================================================
str = d3Dsv.tsvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test DSV Generalized Parsers and Formatters
// ------------------------------------------------------------------------------------------
// Create custom-delimited Parser/Formatter =================================================
let dsv: d3Dsv.DSV;
dsv = d3Dsv.dsvFormat('|');
// parse(...) ============================================================================