Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

@thi.ng/dl-asset

0.3.4 • Public • Published

dl-asset

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/dl-asset

Package sizes (gzipped, pre-treeshake): ESM: 399 bytes / CJS: 451 bytes / UMD: 556 bytes

Dependencies

Usage examples

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
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

API

Generated API docs

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

Authors

Karsten Schmidt

License

© 2020 Karsten Schmidt // Apache Software License 2.0

Install

npm i @thi.ng/dl-asset

DownloadsWeekly Downloads

74

Version

0.3.4

License

Apache-2.0

Unpacked Size

26.2 kB

Total Files

10

Last publish

Collaborators

  • avatar