Skip to content

Latest commit

 

History

History

download

@thi.ng/download

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Local asset download for web apps, with automatic MIME type detection.

Status

ALPHA - bleeding edge / work-in-progress

Installation

yarn add @thi.ng/download

Package sizes (gzipped): ESM: 0.4KB / CJS: 0.4KB / UMD: 0.5KB

Dependencies

Usage examples

Several demos in this repo's /examples directory are using this package.

A selection:

hdom-canvas-shapes

screenshot

Live demo | Source

rotating-voronoi

screenshot

Live demo | Source

rstream-grid

screenshot

Interactive grid generator, SVG generation & export, undo/redo support

Live demo | Source

wolfram

Live demo | Source

API

Generated API docs

import { download } from "@thi.ng/download";

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
});

Authors

Karsten Schmidt

License

© 2020 Karsten Schmidt // Apache Software License 2.0