You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/javascript/files.md
+7-18
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,13 @@
2
2
3
3
TK Should this be called “working with data”?
4
4
5
-
You can load files the built-in `FileAttachment` function or the standard [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) API. We recommend `FileAttachment` because it supports many common data formats, including CSV, TSV, JSON, Apache Arrow, and SQLite. For example, here’s how to load a CSV file:
5
+
You can load files the built-in `FileAttachment` function. This is available by default in Markdown, but you can import it like so:
if (!response.ok) thrownewError(`fetch error: ${response.status}`);
46
-
returncsvParse(awaitresponse.text(), autoType);
47
-
});
48
-
```
49
-
50
-
Use `fetch` if you prefer to stick to the web standards, you don’t mind writing a little extra code. 🥴 Also, you’ll need to use `fetch` to load files from imported ES modules; `FileAttachment` only works within Markdown.
51
-
52
-
**Caution:** If you use `fetch` for a local file, the path *must* start with `./`, `../`, or `/`. This allows us to distinguish between local files and absolute URLs. But that’s a little silly, right? Because unlike `import`, you can’t `fetch` a bare module specifier, so we could be more generous and detect URLs using `/^\w+:/` instead.
53
-
54
43
## Supported formats
55
44
56
45
The following type-specific methods are supported:
0 commit comments