Skip to content

Commit 2461ef0

Browse files
committed
Added a brower example
1 parent e6434f5 commit 2461ef0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ $ npm install datapackage # v0.8
5959

6060
### Examples
6161

62+
#### Node
6263

6364
Code examples in this readme requires Node v8.3+ or proper modern browser . Also you have to wrap code into async function if there is await keyword used. You could see even more example in [examples](https://github.com/frictionlessdata/datapackage-js/tree/master/examples) directory.
6465

@@ -90,6 +91,35 @@ const dataPackage = await Package.load(descriptor)
9091
const resource = dataPackage.getResource('example')
9192
await resource.read() // [[180, 18, 'Tony'], [192, 32, 'Jacob']]
9293
```
94+
#### Browser
95+
96+
> https://jsfiddle.net/rollninja/hs985buj/3/
97+
98+
After the script registration the library will be available as a global variable `datapackage`:
99+
100+
```html
101+
<!DOCTYPE html>
102+
<html lang="en">
103+
<head>
104+
<meta charset="utf-8">
105+
<title>datapackage-js</title>
106+
</head>
107+
<body>
108+
<script src="//unpkg.com/datapackage/dist/datapackage.min.js"></script>
109+
<script>
110+
const main = async () => {
111+
const resource = await datapackage.Resource.load({path: 'https://raw.githubusercontent.com/frictionlessdata/datapackage-js/master/data/data.csv'})
112+
const rows = await resource.read()
113+
document.body.innerHTML += `<div>${resource.headers}</div>`
114+
for (const row of rows) {
115+
document.body.innerHTML += `<div>${row}</div>`
116+
}
117+
}
118+
main()
119+
</script>
120+
</body>
121+
</html>
122+
```
93123

94124
## Documentation
95125

0 commit comments

Comments
 (0)