This project is part of the @thi.ng/umbrella monorepo.
Local asset download for web apps, with automatic MIME type detection.
ALPHA - bleeding edge / work-in-progress
Search or submit any issues for this package
yarn add @thi.ng/dl-asset
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/dl-asset?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/dl-asset/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 428 bytes / CJS: 478 bytes / UMD: 593 bytes
Several demos in this repo's /examples directory are using this package.
A selection:
Screenshot | Description | Live demo | Source |
---|---|---|---|
Various hdom-canvas shape drawing examples & SVG conversion / export | Demo | Source | |
Parser grammar livecoding editor/playground & codegen | Demo | Source | |
Animated Voronoi diagram, cubic splines & SVG download | Demo | Source | |
Interactive grid generator, SVG generation & export, undo/redo support | Demo | Source | |
1D Wolfram automata with OBJ point cloud export | Demo | Source |
import { download } from "@thi.ng/dl-asset";
const src = "Hellö wörld!";
// mime type derived from file extension (.txt)
download("hello.txt", src, {
utf8: true,
expire: 1000
});
// with explicit MIME type string
download("hello.txt", src, {
mime: "text/plain",
utf8: true,
expire: 1000
});
...or using MIME type preset from @thi.ng/mime.
import { MIME_TYPES } from "@thi.ng/mime";
download("hello.txt", src, {
mime: MIME_TYPES.text,
utf8: true,
expire: 1000
});
Karsten Schmidt
If this project contributes to an academic publication, please cite it as:
@misc{thing-dl-asset,
title = "@thi.ng/dl-asset",
author = "Karsten Schmidt",
note = "https://thi.ng/dl-asset",
year = 2020
}
© 2020 - 2021 Karsten Schmidt // Apache Software License 2.0