Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3-dsv] Update types to v1.2 #48330

Merged
merged 1 commit into from Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions types/d3-dsv/d3-dsv-tests.ts
Expand Up @@ -168,6 +168,19 @@ str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d) => [
d.length.toString()
]));

// csvFormatRow(...) ========================================================================

str = d3Dsv.csvFormatRow([
parseRowsMappedArray[0].year ? parseRowsMappedArray[0].year.getFullYear().toString() : '',
parseRowsMappedArray[0].make,
parseRowsMappedArray[0].model,
parseRowsMappedArray[0].length.toString()
]);

// csvFormatValue(...) ========================================================================

str = d3Dsv.csvFormatValue(parseRowsMappedArray[0].make);

// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -255,6 +268,19 @@ str = d3Dsv.tsvFormatRows(parseRowsMappedArray.map((d) => [
d.length.toString()
]));

// tsvFormatRow(...) ========================================================================

str = d3Dsv.tsvFormatRow([
parseRowsMappedArray[0].year ? parseRowsMappedArray[0].year.getFullYear().toString() : '',
parseRowsMappedArray[0].make,
parseRowsMappedArray[0].model,
parseRowsMappedArray[0].length.toString()
]);

// tsvFormatValue(...) ========================================================================

str = d3Dsv.tsvFormatValue(parseRowsMappedArray[0].make);

// ------------------------------------------------------------------------------------------
// Test DSV Generalized Parsers and Formatters
// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -347,6 +373,19 @@ str = dsv.formatRows(parseRowsMappedArray.map((d) => [
d.length.toString()
]));

// formatRow(...) ========================================================================

str = dsv.formatRow([
parseRowsMappedArray[0].year ? parseRowsMappedArray[0].year.getFullYear().toString() : '',
parseRowsMappedArray[0].make,
parseRowsMappedArray[0].model,
parseRowsMappedArray[0].length.toString()
]);

// formatValue(...) ========================================================================

str = dsv.formatValue(parseRowsMappedArray[0].make);

// autoType(...) ==========================================================================

parseMappedArray = d3Dsv.csvParse<ParsedTestObject, Headers>(csvTestStringWithHeader, d3Dsv.autoType);
Expand Down
57 changes: 55 additions & 2 deletions types/d3-dsv/index.d.ts
@@ -1,4 +1,4 @@
// Type definitions for D3JS d3-dsv module 1.1
// Type definitions for D3JS d3-dsv module 1.2
// Project: https://github.com/d3/d3-dsv/, https://d3js.org/d3-dsv
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
// Alex Ford <https://github.com/gustavderdrache>
Expand All @@ -8,7 +8,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

// Last module patch version validated against: 1.1.2
// Last module patch version validated against: 1.2.0

// ------------------------------------------------------------------------------------------
// Shared Types and Interfaces
Expand Down Expand Up @@ -183,6 +183,24 @@ export function csvFormatBody<T extends object>(rows: T[], columns?: Array<keyof
*/
export function csvFormatRows(rows: string[][]): string;

// csvFormatRow(...) ========================================================================

/**
* Equivalent to dsvFormat(",").formatRow.
*
* @param row An array of strings representing a row.
*/
export function csvFormatRow(row: string[]): string;

// csvFormatValue(...) ========================================================================

/**
* Equivalent to dsvFormat(",").formatValue.
*
* @param value A value.
*/
export function csvFormatValue(value: string): string;

// ------------------------------------------------------------------------------------------
// TSV Parsers and Formatters
// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -304,6 +322,24 @@ export function tsvFormatBody<T extends object>(rows: T[], columns?: Array<keyof
*/
export function tsvFormatRows(rows: string[][]): string;

// tsvFormatRow(...) ========================================================================

/**
* Equivalent to dsvFormat("\t").formatRow.
*
* @param row An array of strings representing a row.
*/
export function tsvFormatRow(row: string[]): string;

// tsvFormatValue(...) ========================================================================

/**
* Equivalent to dsvFormat("\t").formatValue.
*
* @param value A value.
*/
export function tsvFormatValue(value: string): string;

// ------------------------------------------------------------------------------------------
// DSV Generalized Parsers and Formatters
// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -407,6 +443,23 @@ export interface DSV {
* @param rows An array of array of string rows.
*/
formatRows(rows: string[][]): string;

/**
* Formats a single array row of strings as delimiter-separated values, returning a string.
* Each column within the row will be separated by the delimiter (such as a comma, ,).
* Values that contain either the delimiter, a double-quote (") or a newline will be escaped using double-quotes.
*
* @param row An array of strings representing a row.
*/
formatRow(row: string[]): string;

/**
* Format a single value or string as a delimiter-separated value, returning a string.
* A value that contains either the delimiter, a double-quote (") or a newline will be escaped using double-quotes.
*
* @param value A value.
*/
formatValue(value: string): string;
}

/**
Expand Down