Skip to content

downloadString

Downloads a string as a file by wrapping it in a Blob with a custom MIME type and forwarding to downloadBlob.

Importing

ts
import { downloadString } from '@basmilius/utils';

Usage

ts
import { downloadString } from '@basmilius/utils';

const csv = 'name,age\nAda,36\n';
downloadString(csv, 'people.csv', 'text/csv');

const json = JSON.stringify({hello: 'world'});
downloadString(json, 'hello.json', 'application/json');

Parameters

NameTypeDescription
datastringThe string content to download.
filenamestringThe suggested filename.
typestringThe MIME type for the underlying Blob.

Returns

void — the download is triggered synchronously.

Type signature

ts
declare function downloadString(data: string, filename: string, type: string): void;

See also