Skip to content

Commit 00321fd

Browse files
committed
Write README.md
1 parent b65a53e commit 00321fd

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# `csv-to-xml`
2+
3+
`csv-to-xml` is an easy-to-use library that quickly converts any CSV data in a string or file to its equivalent XML representation.
4+
5+
## Usage
6+
7+
### CSV file
8+
9+
`data.csv`
10+
11+
```txt
12+
Color,Maximum Speed,Age
13+
red,120,2
14+
blue,150,4;
15+
```
16+
17+
### CSV to XML Conversion
18+
19+
`index.js`
20+
21+
```js
22+
import csvToXml from 'csv-to-xml';
23+
import fs from 'fs/promises';
24+
25+
const csv = await fs.readFile('data.csv', {
26+
encoding: 'utf-8',
27+
});
28+
29+
const xml = csvToXml(csv, {
30+
headerList: ['color', 'maxSpeed', 'age'],
31+
});
32+
33+
console.log(xml);
34+
```
35+
36+
### Output
37+
38+
```xml
39+
<row>
40+
<color>red</color>
41+
<maxSpeed>120</maxSpeed>
42+
<age>2</age>
43+
</row>
44+
<row>
45+
<color>blue</color>
46+
<maxSpeed>150</maxSpeed>
47+
<age>4</age>
48+
</row>
49+
```
50+
51+
## API
52+
53+
### `csvToXml(csv: string, options: CSVToXMLOptions): string`
54+
55+
Takes string containing CSV data and returns string containing equivalent XML data.
56+
57+
### `CSVToXMLOptions`
58+
59+
- `eol`: character to be treated as end of a line. If unspecified, EOL character will be auto-detected.
60+
61+
Type: `string`\
62+
Default: `undefined`
63+
64+
- `separator`: character used to separate each CSV column.
65+
66+
Type: `string`\
67+
Default: `','`
68+
69+
- `rowName`: name given to XML element wrapping column XML elements.
70+
71+
Type: `string`\
72+
Default: `'row'`
73+
74+
- `headerList`: List of custom header names to use for the CSV.
75+
76+
Type: `string[]`\
77+
Default: `[]`
78+
79+
- `header`: Whether the CSV data contains a header row or not.
80+
81+
Type: `boolean`\
82+
Default: `true`

0 commit comments

Comments
 (0)