deno.land / std@0.180.0 / encoding / csv.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright 2011 The Go Authors. All rights reserved. BSD license.// https://github.com/golang/go/blob/master/LICENSE// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/** Port of the Go * [encoding/csv](https://github.com/golang/go/blob/go1.12.5/src/encoding/csv/) * library. * * @module */
export { /** * @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead. * * The most essential aspect of a column is accessing the property holding the * data for that column on each object in the data array. If that member is at * the top level, `Column` can simply be a property accessor, which is either a * `string` (if it's a plain object) or a `number` (if it's an array). * * ```ts * const columns = [ * "name", * ]; * ``` * * Each property accessor will be used as the header for the column: * * | name | * | :--: | * | Deno | * * - If the required data is not at the top level (it's nested in other * objects/arrays), then a simple property accessor won't work, so an array of * them will be required. * * ```ts * const columns = [ * ["repo", "name"], * ["repo", "org"], * ]; * ``` * * When using arrays of property accessors, the header names inherit the value * of the last accessor in each array: * * | name | org | * | :--: | :------: | * | deno | denoland | * * - If a different column header is desired, then a `ColumnDetails` object type * can be used for each column: * * - **`header?: string`** is the optional value to use for the column header * name * * - **`prop: PropertyAccessor | PropertyAccessor[]`** is the property accessor * (`string` or `number`) or array of property accessors used to access the * data on each object * * ```ts * const columns = [ * "name", * { * prop: ["runsOn", 0], * header: "language 1", * }, * { * prop: ["runsOn", 1], * header: "language 2", * }, * ]; * ``` * * | name | language 1 | language 2 | * | :--: | :--------: | :--------: | * | Deno | Rust | TypeScript | */
type Column, /** * @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead. * * @param header Explicit column header name. If omitted, * the (final) property accessor is used for this value. * * @param prop Property accessor(s) used to access the value on the object */ type ColumnDetails, /** * @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead.
* * An object (plain or array) **/
type DataItem, ERR_BARE_QUOTE, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ ERR_FIELD_COUNT, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ ERR_INVALID_DELIM, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ ERR_QUOTE, /** * @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. * * CSV parse helper to manipulate data. * Provides an auto/custom mapper for columns. * * @example * ```ts * import { parse } from "https://deno.land/std@$STD_VERSION/encoding/csv.ts"; * const string = "a,b,c\nd,e,f"; * * console.log( * await parse(string, { * skipFirstRow: false, * }), * ); * // output: * // [["a", "b", "c"], ["d", "e", "f"]] * ``` * * @param input Input to parse. * @param opt options of the parser. * @returns If you don't provide `opt.skipFirstRow` and `opt.columns`, it returns `string[][]`. * If you provide `opt.skipFirstRow` or `opt.columns`, it returns `Record<string, unkown>[]`. */ parse, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ ParseError, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ type ParseOptions, /** @deprecated (will be removed after 0.181.0) Import from `csv/parse.ts` instead. */ type ReadOptions, /** * @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead. * * @param data The source data to stringify. It's an array of items which are * plain objects or arrays. * * `DataItem: Record<string, unknown> | unknown[]` * * ```ts * const data = [ * { * name: "Deno", * repo: { org: "denoland", name: "deno" }, * runsOn: ["Rust", "TypeScript"], * }, * ]; * ``` * * @example * ```ts * import { * Column, * stringify, * } from "https://deno.land/std@$STD_VERSION/encoding/csv.ts"; * * type Character = { * age: number; * name: { * first: string; * last: string; * }; * }; * * const data: Character[] = [ * { * age: 70, * name: { * first: "Rick", * last: "Sanchez", * }, * }, * { * age: 14, * name: { * first: "Morty", * last: "Smith", * }, * }, * ]; * * let columns: Column[] = [ * ["name", "first"], * "age", * ]; * * console.log(stringify(data, { columns })); * // first,age * // Rick,70 * // Morty,14 * ``` * * @param options Output formatting options */ stringify, /** @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead. */ StringifyError, /** @deprecated (will be removed after 0.181.0) Import from `csv/stringify.ts` instead. */ type StringifyOptions,} from "../csv/mod.ts";
std

Version Info

Tagged at
a year ago