Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.

Commit d32a6c7

Browse files
committed
docs: browser demo fix #302
1 parent 526c07d commit d32a6c7

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Please join and contribute:
1919

2020
## Trunk
2121

22+
* docs: browser demo fix #302
2223
* fix: browserify export parse instead of stringify
2324

2425
## Version 4.15.1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"csv-spectrum": "^1.0.0",
6161
"each": "^1.2.2",
6262
"eslint": "^7.13.0",
63+
"express": "^4.17.1",
6364
"mocha": "^8.2.1",
6465
"pad": "^3.2.0",
6566
"should": "^13.2.3",

samples/browser/index.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Page Title</title>
5+
<script src="lib/index.js"></script>
6+
<style>
7+
div {
8+
width: 60%;
9+
margin: 5rem auto;
10+
text-align: center;
11+
}
12+
textarea {
13+
width: 100%;
14+
height: 200px;
15+
}
16+
input {
17+
margin: 1rem;
18+
}
19+
pre {
20+
text-align: left;
21+
padding: 2rem;
22+
border: 1px solid black;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
<div>
28+
<h1>CSV parse demo</h1>
29+
<label for="input">JSON input:</label>
30+
<textarea id="input">year,phone
31+
XXXX,XXX XXXX
32+
YYYY,YYY YYYY</textarea>
33+
<input id="convert" type="submit" value="convert" />
34+
<pre><code id="output"></code></pre>
35+
<script>
36+
const convertEl = document.getElementById('convert')
37+
const inputEl = document.getElementById('input')
38+
const outputEl = document.getElementById('output')
39+
convertEl.onclick = (e) => {
40+
let input;
41+
parse(inputEl.value, {
42+
columns: true
43+
}, function(err, data){
44+
if(err){
45+
return alert('Invalid CSV: '+err.message)
46+
}
47+
console.log(data)
48+
outputEl.innerHTML = JSON.stringify(data, null, 2)
49+
})
50+
}
51+
</script>
52+
<div>
53+
</body>
54+
</html>

samples/browser/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
const express = require('express')
3+
const app = express()
4+
const port = 3000
5+
6+
app.use(express.static(__dirname))
7+
app.use('/lib', express.static(`${__dirname}/../../lib/browser`))
8+
9+
app.listen(port, () => {
10+
console.log(`Example app listening at http://localhost:${port}`)
11+
})

0 commit comments

Comments
 (0)