summaryrefslogtreecommitdiff
path: root/std/encoding/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'std/encoding/README.md')
-rw-r--r--std/encoding/README.md99
1 files changed, 10 insertions, 89 deletions
diff --git a/std/encoding/README.md b/std/encoding/README.md
index 767cbdcb4..ee06aa3ec 100644
--- a/std/encoding/README.md
+++ b/std/encoding/README.md
@@ -2,100 +2,21 @@
## CSV
-- **`readAll(reader: BufReader, opt: ParseOptions = { comma: ",", trimLeadingSpace: false, lazyQuotes: false } ): Promise<[string[][], BufState]>`**:
- Read the whole buffer and output the structured CSV datas
-- **`parse(csvString: string, opt: ParseOption): Promise<unknown[]>`**: See
- [parse](###Parse)
+- **`parseCsv(input: string | BufReader, opt: ParseCsvOptions): Promise<unknown[]>`**:
+ Read the string/buffer into an
-### Parse
-
-Parse the CSV string with the options provided.
-
-#### Options
-
-##### ParseOption
-
-- **`header: boolean | string[] | HeaderOption[];`**: If a boolean is provided,
- the first line will be used as Header definitions. If `string[]` or
- `HeaderOption[]` those names will be used for header definition.
-- **`parse?: (input: unknown) => unknown;`**: Parse function for the row, which
- will be executed after parsing of all columns. Therefore if you don't provide
- header and parse function with headers, input will be `string[]`.
-
-##### HeaderOption
-
-- **`name: string;`**: Name of the header to be used as property.
-- **`parse?: (input: string) => unknown;`**: Parse function for the column. This
- is executed on each entry of the header. This can be combined with the Parse
- function of the rows.
-
-#### Usage
+### Usage
```ts
-// input:
-// a,b,c
-// e,f,g
-
-const r = await parseFile(filepath, {
- header: false
-});
-// output:
-// [["a", "b", "c"], ["e", "f", "g"]]
+const string = "a,b,c\nd,e,f";
-const r = await parseFile(filepath, {
- header: true
-});
-// output:
-// [{ a: "e", b: "f", c: "g" }]
-
-const r = await parseFile(filepath, {
- header: ["this", "is", "sparta"]
-});
-// output:
-// [
-// { this: "a", is: "b", sparta: "c" },
-// { this: "e", is: "f", sparta: "g" }
-// ]
-
-const r = await parseFile(filepath, {
- header: [
- {
- name: "this",
- parse: (e: string): string => {
- return `b${e}$$`;
- }
- },
- {
- name: "is",
- parse: (e: string): number => {
- return e.length;
- }
- },
- {
- name: "sparta",
- parse: (e: string): unknown => {
- return { bim: `boom-${e}` };
- }
- }
- ]
-});
-// output:
-// [
-// { this: "ba$$", is: 1, sparta: { bim: `boom-c` } },
-// { this: "be$$", is: 1, sparta: { bim: `boom-g` } }
-// ]
-
-const r = await parseFile(filepath, {
- header: ["this", "is", "sparta"],
- parse: (e: Record<string, unknown>) => {
- return { super: e.this, street: e.is, fighter: e.sparta };
- }
-});
+console.log(
+ await parseCsv(string, {
+ header: false
+ })
+);
// output:
-// [
-// { super: "a", street: "b", fighter: "c" },
-// { super: "e", street: "f", fighter: "g" }
-// ]
+// [["a", "b", "c"], ["d", "e", "f"]]
```
## TOML