UNPKG

14 kBTypeScriptView Raw
1// Last module patch version validated against: 3.0.1
2
3import { DSVParsedArray, DSVRowArray, DSVRowString } from "d3-dsv";
4
5/**
6 * Fetches the binary file at the specified input URL and returns it as a Promise of a Blob.
7 * If init is specified, it is passed along to the underlying call to fetch.
8 *
9 * @param url A valid URL string.
10 * @param init An optional request initialization object.
11 */
12export function blob(url: string, init?: RequestInit): Promise<Blob>;
13
14/**
15 * Fetches the binary file at the specified input URL and returns it as a Promise of an ArrayBuffer.
16 * If init is specified, it is passed along to the underlying call to fetch.
17 *
18 * @param url A valid URL string.
19 * @param init An optional request initialization object.
20 */
21export function buffer(url: string, init?: RequestInit): Promise<ArrayBuffer>;
22
23/**
24 * Fetches the CSV file at the specified input URL and returns
25 * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
26 * objects are represented as strings.
27 *
28 * If init is specified, it is passed along to the underlying call to fetch.
29 *
30 * The generic parameter describes the column names as a union of string literal types.
31 *
32 * @param url A valid URL string.
33 * @param init An optional request initialization object.
34 */
35// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
36export function csv<Columns extends string>(
37 url: string,
38 init?: RequestInit,
39): Promise<DSVRowArray<Columns>>;
40/**
41 * Fetches the CSV file at the specified input URL and returns
42 * a promise of an array of objects representing the parsed rows.
43 *
44 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
45 * see dsv.csvParse for details.
46 *
47 * The first generic parameter describes the type of the object representation of a parsed row.
48 * The second generic parameter describes the column names as a union of string literal types.
49 *
50 * @param url A valid URL string.
51 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
52 * 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,
53 * the row is skipped and will be omitted from the array returned by dsv.csvParse; otherwise, the returned value defines the corresponding row object.
54 * In effect, row is similar to applying a map and filter operator to the returned rows.
55 */
56export function csv<ParsedRow extends object, Columns extends string = string>(
57 url: string,
58 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
59): Promise<DSVParsedArray<ParsedRow>>;
60/**
61 * Fetches the CSV file at the specified input URL and returns
62 * a promise of an array of objects representing the parsed rows.
63 *
64 * The init object is passed along to the underlying call to fetch.
65 *
66 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
67 * see dsv.csvParse for details.
68 *
69 * The first generic parameter describes the type of the object representation of a parsed row.
70 * The second generic parameter describes the column names as a union of string literal types.
71 *
72 * @param url A valid URL string.
73 * @param init An request initialization object.
74 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
75 * 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,
76 * the row is skipped and will be omitted from the array returned by dsv.csvParse; otherwise, the returned value defines the corresponding row object.
77 * In effect, row is similar to applying a map and filter operator to the returned rows.
78 */
79export function csv<ParsedRow extends object, Columns extends string = string>(
80 url: string,
81 init: RequestInit,
82 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
83): Promise<DSVParsedArray<ParsedRow>>;
84
85/**
86 * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
87 * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
88 * objects are represented as strings.
89 *
90 * If init is specified, it is passed along to the underlying call to fetch.
91 *
92 * The generic parameter describes the column names as a union of string literal types.
93 *
94 * @param delimiter The delimiter character used in the DSV file to be fetched.
95 * @param url A valid URL string.
96 * @param init An optional request initialization object.
97 */
98// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
99export function dsv<Columns extends string>(
100 delimiter: string,
101 url: string,
102 init?: RequestInit,
103): Promise<DSVRowArray<Columns>>;
104/**
105 * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
106 * a promise of an array of objects representing the parsed rows.
107 *
108 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
109 * see dsv.parse for details.
110 *
111 * The first generic parameter describes the type of the object representation of a parsed row.
112 * The second generic parameter describes the column names as a union of string literal types.
113 *
114 * @param delimiter The delimiter character used in the DSV file to be fetched.
115 * @param url A valid URL string.
116 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
117 * 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,
118 * the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object.
119 * In effect, row is similar to applying a map and filter operator to the returned rows.
120 */
121export function dsv<ParsedRow extends object, Columns extends string = string>(
122 delimiter: string,
123 url: string,
124 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
125): Promise<DSVParsedArray<ParsedRow>>;
126/**
127 * Fetches the DSV file with the specified delimiter character at the specified input URL and returns
128 * a promise of an array of objects representing the parsed rows.
129 *
130 * The init object is passed along to the underlying call to fetch.
131 *
132 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
133 * see dsv.parse for details.
134 *
135 * The first generic parameter describes the type of the object representation of a parsed row.
136 * The second generic parameter describes the column names as a union of string literal types.
137 *
138 * @param delimiter The delimiter character used in the DSV file to be fetched.
139 * @param url A valid URL string.
140 * @param init An request initialization object.
141 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
142 * 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,
143 * the row is skipped and will be omitted from the array returned by dsv.parse; otherwise, the returned value defines the corresponding row object.
144 * In effect, row is similar to applying a map and filter operator to the returned rows.
145 */
146export function dsv<ParsedRow extends object, Columns extends string = string>(
147 delimiter: string,
148 url: string,
149 init: RequestInit,
150 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
151): Promise<DSVParsedArray<ParsedRow>>;
152
153/**
154 * Fetches the file at the specified input URL as text, parses it as HTML and returns a Promise of an HTML DOM Document.
155 *
156 * If init is specified, it is passed along to the underlying call to fetch.
157 *
158 * @param url A valid URL string.
159 * @param init An optional request initialization object.
160 */
161export function html(url: string, init?: RequestInit): Promise<Document>;
162
163/**
164 * Fetches the image at the specified input URL and returns a promise of an HTML image element.
165 *
166 * If init is specified, sets any additional properties on the image before loading.
167 *
168 * @param url A valid URL string.
169 * @param init An optional object of image properties to set.
170 */
171export function image(url: string, init?: Partial<HTMLImageElement>): Promise<HTMLImageElement>;
172
173/**
174 * Fetches the json file at the specified input URL and returns it as a Promise of a parsed JSON object.
175 *
176 * If init is specified, it is passed along to the underlying call to fetch.
177 *
178 * If the server returns a status code of [204 No Content](https://developer.mozilla.org/docs/Web/HTTP/Status/204)
179 * or [205 Reset Content](https://developer.mozilla.org/docs/Web/HTTP/Status/205), the promise resolves to `undefined`.
180 *
181 * The generic parameter describes the type of the object parsed from the returned JSON.
182 *
183 * @param url A valid URL string.
184 * @param init An optional request initialization object.
185 */
186// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
187export function json<ParsedJSONObject extends any>(
188 url: string,
189 init?: RequestInit,
190): Promise<ParsedJSONObject | undefined>;
191
192/**
193 * Fetches the file at the specified input URL as text, parses it as SVG and returns a Promise of an SVG Document.
194 *
195 * If init is specified, it is passed along to the underlying call to fetch.
196 *
197 * @param url A valid URL string.
198 * @param init An optional request initialization object.
199 */
200export function svg(url: string, init?: RequestInit): Promise<Document>;
201
202/**
203 * Fetches the text file at the specified input URL and returns it as a Promise of a string.
204 *
205 * If init is specified, it is passed along to the underlying call to fetch.
206 *
207 * @param url A valid URL string.
208 * @param init An optional request initialization object.
209 */
210export function text(url: string, init?: RequestInit): Promise<string>;
211
212/**
213 * Fetches the TSV file at the specified input URL and returns
214 * a promise of an array of objects representing the parsed rows.
215 *
216 * If init is specified, it is passed along to the underlying call to fetch.
217 *
218 * The generic parameter describes the column names as a union of string literal types.
219 *
220 * @param url A valid URL string.
221 * @param init An optional request initialization object.
222 */
223// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
224export function tsv<Columns extends string>(
225 url: string,
226 init?: RequestInit,
227): Promise<DSVRowArray<Columns>>;
228/**
229 * Fetches the TSV file at the specified input URL and returns
230 * a promise of an array of objects representing the parsed rows. The values of the properties of the parsed row
231 * objects are represented as strings.
232 *
233 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
234 * see dsv.tsvParse for details.
235 *
236 * The first generic parameter describes the type of the object representation of a parsed row.
237 * The second generic parameter describes the column names as a union of string literal types.
238 *
239 * @param url A valid URL string.
240 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
241 * 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,
242 * the row is skipped and will be omitted from the array returned by dsv.tsvParse; otherwise, the returned value defines the corresponding row object.
243 * In effect, row is similar to applying a map and filter operator to the returned rows.
244 */
245export function tsv<ParsedRow extends object, Columns extends string = string>(
246 url: string,
247 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
248): Promise<DSVParsedArray<ParsedRow>>;
249/**
250 * Fetches the TSV file at the specified input URL and returns
251 * a promise of an array of objects representing the parsed rows.
252 *
253 * The init object is passed along to the underlying call to fetch.
254 *
255 * The specified row conversion function is used to map and filter row objects to a more-specific representation;
256 * see dsv.tsvParse for details.
257 *
258 * The first generic parameter describes the type of the object representation of a parsed row.
259 * The second generic parameter describes the column names as a union of string literal types.
260 *
261 * @param url A valid URL string.
262 * @param init An request initialization object.
263 * @param row A row conversion function which is invoked for each row, being passed an object representing the current row (d),
264 * 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,
265 * the row is skipped and will be omitted from the array returned by dsv.tsvParse; otherwise, the returned value defines the corresponding row object.
266 * In effect, row is similar to applying a map and filter operator to the returned rows.
267 */
268export function tsv<ParsedRow extends object, Columns extends string = string>(
269 url: string,
270 init: RequestInit,
271 row: (rawRow: DSVRowString<Columns>, index: number, columns: Columns[]) => ParsedRow | undefined | null,
272): Promise<DSVParsedArray<ParsedRow>>;
273
274/**
275 * Fetches the file at the specified input URL as text, parses it as XML and returns a Promise of an XML Document.
276 *
277 * If init is specified, it is passed along to the underlying call to fetch.
278 *
279 * @param url A valid URL string.
280 * @param init An optional request initialization object.
281 */
282export function xml(url: string, init?: RequestInit): Promise<XMLDocument>;