Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

generate-download-link

samuelkingn81MIT1.0.1

generate link to download text as file

readme

Build Status Coverage Status

NPM

Download Link Generator

With this package, you can easily generate links for downloading content as files. generate-download-link returns a DOM element like the following:

<a href="data:application/octet-stream,DATA" download="FILENAME">TITLE</a>

Specify the

  • Content of the file as a string,
  • The filename to be used
  • The title of the anchor element.

When the element is clicked, a file is downloaded and saved as FILENAME.

Usage

var generateDownloadLink = require('generate-download-link');

var opt = {
    data: 'Here is the content of the file',
    title: 'Click to download your file',
    filename: 'example.txt'
};

var anchor = generateDownloadLink(opt);