@types/d3-dsv
- Version 3.0.7
- Published
- 28.6 kB
- No dependencies
- MIT license
Install
npm i @types/d3-dsv
yarn add @types/d3-dsv
pnpm add @types/d3-dsv
Overview
TypeScript definitions for d3-dsv
Index
Functions
Interfaces
Type Aliases
Functions
function autoType
autoType: <ParsedRow extends object, Columns extends string>( object: DSVRowString<Columns> | readonly string[]) => ParsedRow;
Infers the types of values on the object and coerces them accordingly, returning the mutated object. This function is intended to be used as a row accessor function in conjunction with dsv.parse and dsv.parseRows.
Parameter object
An object (or array) representing a parsed row
function csvFormat
csvFormat: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Formats the specified array of object rows as comma-separated values, returning a string. This operation is the inverse of csvParse. Each row will be separated by a newline (\n), and each column within each row will be separated by the comma-delimiter. Values that contain either the comma-delimiter, a double-quote (") or a newline will be escaped using double-quotes.
If columns is not specified, the list of column names that forms the header row is determined by the union of all properties on all objects in rows; the order of columns is nondeterministic.
Equivalent to
dsvFormat(",").format
.Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
function csvFormatBody
csvFormatBody: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Equivalent to dsvFormat(",").formatBody.
Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
function csvFormatRow
csvFormatRow: (row: readonly string[]) => string;
Equivalent to dsvFormat(",").formatRow.
Parameter row
An array of strings representing a row.
function csvFormatRows
csvFormatRows: (rows: readonly string[][]) => string;
Formats the specified array of array of string rows as comma-separated values, returning a string. This operation is the reverse of csvParseRows. Each row will be separated by a newline (\n), and each column within each row will be separated by the comma-delimiter. Values that contain either the comma-delimiter, a double-quote (") or a newline will be escaped using double-quotes.
To convert an array of objects to an array of arrays while explicitly specifying the columns, use array.map. If you like, you can also array.concat this result with an array of column names to generate the first row.
Equivalent to
dsvFormat(",").formatRows
.Parameter rows
An array of array of string rows.
function csvFormatValue
csvFormatValue: (value: string) => string;
Equivalent to dsvFormat(",").formatValue.
Parameter value
A value.
function csvParse
csvParse: { <Columns extends string>(csvString: string): DSVRowArray<Columns>; <ParsedRow extends object, Columns extends string>( csvString: string, row: ( rawRow: DSVRowString<Columns>, index: number, columns: Columns[] ) => ParsedRow ): DSVParsedArray<ParsedRow>;};
Parses the specified string, which must be in the comma-separated values format, returning an array of objects representing the parsed rows.
Unlike csvParseRows, this method requires that the first line of the CSV content contains a comma-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
Equivalent to
dsvFormat(",").parse
. Note: requires unsafe-eval content security policy.Parameter csvString
A string, which must be in the comma-separated values format.
Parses the specified string, which must be in the comma-separated values format, returning an array of objects representing the parsed rows.
Unlike csvParseRows, this method requires that the first line of the CSV content contains a comma-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
Equivalent to
dsvFormat(",").parse
. Note: requires unsafe-eval content security policy.Parameter csvString
A string, which must be in the comma-separated values format.
Parameter row
A row conversion function which is invoked for each row, being passed an object representing the current row (d), the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
function csvParseRows
csvParseRows: { (csvString: string): string[][]; <ParsedRow extends object>( csvString: string, row: (rawRow: string[], index: number) => ParsedRow ): ParsedRow[];};
Parses the specified string, which must be in the comma-separated values format, returning an array of arrays representing the parsed rows.
Unlike csvParse, this method treats the header line as a standard row, and should be used whenever CSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
If a row conversion function is not specified, field values are strings. For safety, there is no automatic conversion to numbers, dates, or other types. In some cases, JavaScript may coerce strings to numbers for you automatically (for example, using the + operator), but better is to specify a row conversion function.
Equivalent to
dsvFormat(",").parseRows
.Parameter csvString
A string, which must be in the comma-separated values format.
Parses the specified string, which must be in the comma-separated values format, returning an array of arrays representing the parsed rows.
Unlike csvParse, this method treats the header line as a standard row, and should be used whenever CSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
Equivalent to
dsvFormat(",").parseRows
.Parameter csvString
A string, which must be in the comma-separated values format.
Parameter row
A row conversion function which is invoked for each row, being passed an array representing the current row (d), the index (i) starting at zero for the first row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
function dsvFormat
dsvFormat: (delimiter: string) => DSV;
Constructs a new DSV parser and formatter for the specified delimiter.
Parameter delimiter
A delimiter character. The delimiter must be a single character (i.e., a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not.
function tsvFormat
tsvFormat: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Formats the specified array of object rows as tab-separated values, returning a string. This operation is the inverse of tsvParse. Each row will be separated by a newline (\n), and each column within each row will be separated by the tab-delimiter. Values that contain either the tab-delimiter, a double-quote (") or a newline will be escaped using double-quotes.
If columns is not specified, the list of column names that forms the header row is determined by the union of all properties on all objects in rows; the order of columns is nondeterministic.
Equivalent to
dsvFormat("\t").format
.Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
function tsvFormatBody
tsvFormatBody: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Equivalent to dsvFormat("\t").formatBody.
Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
function tsvFormatRow
tsvFormatRow: (row: readonly string[]) => string;
Equivalent to dsvFormat("\t").formatRow.
Parameter row
An array of strings representing a row.
function tsvFormatRows
tsvFormatRows: (rows: readonly string[][]) => string;
Formats the specified array of array of string rows as tab-separated values, returning a string. This operation is the reverse of tsvParseRows. Each row will be separated by a newline (\n), and each column within each row will be separated by the tab-delimiter. Values that contain either the tab-delimiter, a double-quote (") or a newline will be escaped using double-quotes.
To convert an array of objects to an array of arrays while explicitly specifying the columns, use array.map. If you like, you can also array.concat this result with an array of column names to generate the first row.
Equivalent to
dsvFormat("\t").formatRows
.Parameter rows
An array of array of string rows.
function tsvFormatValue
tsvFormatValue: (value: string) => string;
Equivalent to dsvFormat("\t").formatValue.
Parameter value
A value.
function tsvParse
tsvParse: { <Columns extends string>(tsvString: string): DSVRowArray<Columns>; <ParsedRow extends object, Columns extends string>( tsvString: string, row: ( rawRow: DSVRowString<Columns>, index: number, columns: Columns[] ) => ParsedRow ): DSVParsedArray<ParsedRow>;};
Parses the specified string, which must be in the tab-separated values format, returning an array of objects representing the parsed rows.
Unlike tsvParseRows, this method requires that the first line of the TSV content contains a tab-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
Equivalent to
dsvFormat("\t").parse
. Note: requires unsafe-eval content security policy.Parameter tsvString
A string, which must be in the tab-separated values format.
Parses the specified string, which must be in the tab-separated values format, returning an array of objects representing the parsed rows.
Unlike tsvParseRows, this method requires that the first line of the TSV content contains a tab-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
Equivalent to
dsvFormat("\t").parse
. Note: requires unsafe-eval content security policy.Parameter tsvString
A string, which must be in the tab-separated values format.
Parameter row
A row conversion function which is invoked for each row, being passed an object representing the current row (d), the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
function tsvParseRows
tsvParseRows: { (tsvString: string): string[][]; <ParsedRow extends object>( tsvString: string, row: (rawRow: string[], index: number) => ParsedRow ): ParsedRow[];};
Parses the specified string, which must be in the tab-separated values format, returning an array of arrays representing the parsed rows.
Unlike tsvParse, this method treats the header line as a standard row, and should be used whenever TSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
If a row conversion function is not specified, field values are strings. For safety, there is no automatic conversion to numbers, dates, or other types. In some cases, JavaScript may coerce strings to numbers for you automatically (for example, using the + operator), but better is to specify a row conversion function.
Equivalent to
dsvFormat("\t").parseRows
.Parameter tsvString
A string, which must be in the tab-separated values format.
Parses the specified string, which must be in the tab-separated values format, returning an array of arrays representing the parsed rows.
Unlike tsvParse, this method treats the header line as a standard row, and should be used whenever TSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
Equivalent to
dsvFormat("\t").parseRows
.Parameter tsvString
A string, which must be in the tab-separated values format.
Parameter row
A row conversion function which is invoked for each row, being passed an array representing the current row (d), the index (i) starting at zero for the first row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
Interfaces
interface DSV
interface DSV {}
A DSV parser and formatter
method format
format: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Formats the specified array of object rows as delimiter-separated values, returning a string. This operation is the inverse of dsv.parse. Each row will be separated by a newline (\n), and each column within each 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.
If columns is not specified, the list of column names that forms the header row is determined by the union of all properties on all objects in rows; the order of columns is nondeterministic.
Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
method formatBody
formatBody: <T extends object>( rows: readonly T[], columns?: ReadonlyArray<keyof T>) => string;
Equivalent to dsv.format, but omits the header row. This is useful, for example, when appending rows to an existing file.
Parameter rows
Array of object rows.
Parameter columns
An array of strings representing the column names.
method formatRow
formatRow: (row: readonly 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.
Parameter row
An array of strings representing a row.
method formatRows
formatRows: (rows: readonly string[][]) => string;
Formats the specified array of array of string rows as delimiter-separated values, returning a string. This operation is the reverse of dsv.parseRows. Each row will be separated by a newline (\n), and each column within each 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.
To convert an array of objects to an array of arrays while explicitly specifying the columns, use array.map. If you like, you can also array.concat this result with an array of column names to generate the first row.
Parameter rows
An array of array of string rows.
method formatValue
formatValue: (value: 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.
Parameter value
A value.
method parse
parse: { <Columns extends string>(dsvString: string): DSVRowArray<Columns>; <ParsedRow extends object, Columns extends string>( dsvString: string, row: ( rawRow: DSVRowString<Columns>, index: number, columns: Columns[] ) => ParsedRow ): DSVParsedArray<ParsedRow>;};
Parses the specified string, which must be in the delimiter-separated values format with the appropriate delimiter, returning an array of objects representing the parsed rows.
Unlike dsv.parseRows, this method requires that the first line of the DSV content contains a delimiter-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
If the column names are not unique, only the last value is returned for each name; to access all values, use dsv.parseRows instead.
Note: requires unsafe-eval content security policy.
Parameter dsvString
A string, which must be in the delimiter-separated values format with the appropriate delimiter.
Parses the specified string, which must be in the delimiter-separated values format with the appropriate delimiter, returning an array of objects representing the parsed rows.
Unlike dsv.parseRows, this method requires that the first line of the DSV content contains a delimiter-separated list of column names; these column names become the attributes on the returned objects.
The returned array also exposes a columns property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
If the column names are not unique, only the last value is returned for each name; to access all values, use dsv.parseRows instead.
Note: requires unsafe-eval content security policy.
Parameter dsvString
A string, which must be in the delimiter-separated values format with the appropriate delimiter.
Parameter row
A row conversion function which is invoked for each row, being passed an object representing the current row (d), the index (i) starting at zero for the first non-header row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
method parseRows
parseRows: { (dsvString: string): string[][]; <ParsedRow extends object>( dsvString: string, row: (rawRow: string[], index: number) => ParsedRow ): ParsedRow[];};
Parses the specified string, which must be in the delimiter-separated values format with the appropriate delimiter, returning an array of arrays representing the parsed rows.
Unlike dsv.parse, this method treats the header line as a standard row, and should be used whenever DSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
If a row conversion function is not specified, field values are strings. For safety, there is no automatic conversion to numbers, dates, or other types. In some cases, JavaScript may coerce strings to numbers for you automatically (for example, using the + operator), but better is to specify a row conversion function.
Parameter dsvString
A string, which must be in the delimiter-separated values format with the appropriate delimiter.
Parses the specified string, which must be in the delimiter-separated values format with the appropriate delimiter, returning an array of arrays representing the parsed rows.
Unlike dsv.parse, this method treats the header line as a standard row, and should be used whenever DSV content does not contain a header. Each row is represented as an array rather than an object. Rows may have variable length.
Parameter dsvString
A string, which must be in the delimiter-separated values format with the appropriate delimiter.
Parameter row
A row conversion function which is invoked for each row, being passed an array representing the current row (d), the index (i) starting at zero for the first row, and the array of column names. If the returned value is null or undefined, the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object. In effect, row is similar to applying a map and filter operator to the returned rows.
interface DSVParsedArray
interface DSVParsedArray<T> extends Array<T> {}
An array object representing all parsed rows. The array is enhanced with a property listing the names of the parsed columns.
property columns
columns: Array<keyof T>;
List of column names.
interface DSVRowAny
interface DSVRowAny {}
An object representing a DSV parsed row with values represented as an arbitrary datatype, depending on the performed parsed row mapping.
Deprecated
Use
object
instead.
index signature
[key: string]: any;
interface DSVRowArray
interface DSVRowArray<Columns extends string = string> extends Array<DSVRowString<Columns>> {}
An array object representing all deserialized rows. The array is enhanced with a property listing the names of the parsed columns.
property columns
columns: Columns[];
List of column names.
Type Aliases
type DSVRaw
type DSVRaw<T extends object> = { [key in keyof T]: string;};
An object in raw format before parsing, that is with only string values.
type DSVRowString
type DSVRowString<Columns extends string = string> = { [key in Columns]: string;};
An object representing a DSV parsed row with values represented as strings.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/d3-dsv
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/d3-dsv)
- HTML<a href="https://www.jsdocs.io/package/@types/d3-dsv"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2602 ms. - Missing or incorrect documentation? Open an issue for this package.