Socket
Socket
Sign inDemoInstall

create-download-link

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-download-link - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.travis.yml

18

index.js

@@ -6,5 +6,8 @@ module.exports = function (opt) {

var filename = opt.filename;
var createLink = function (text, filename) {
var link = 'data:application/octet-stream,' + encodeURIComponent(text);
// creates
// <a href="data:application/octet-stream,data" download="filename">title</a>
var createDownloadableFileLink = function (data, filename) {
var link = 'data:application/octet-stream,' + encodeURIComponent(data);
var anchor = document.createElement('a');

@@ -16,5 +19,10 @@ anchor.setAttribute('href', link);

var anchor = createLink(data, filename);
anchor.appendChild(document.createTextNode(title));
var setTitleTo = function(anchor, title) {
anchor.appendChild(document.createTextNode(title));
return anchor;
};
var anchor = createDownloadableFileLink(data, filename);
anchor = setTitleTo(anchor, title);
return anchor;
};
{
"name": "create-download-link",
"version": "1.0.2",
"version": "1.0.3",
"description": "Create link to download text as file",

@@ -9,2 +9,4 @@ "main": "index.js",

"chai": "3.5.0",
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"jsdom": "8.3.1",

@@ -14,4 +16,8 @@ "jsdom-global": "1.7.0",

},
"engines": {
"node": ">=4.0.0"
},
"scripts": {
"test": "mocha -r jsdom-global/register test.js"
"test": "mocha -r jsdom-global/register test.js",
"coverage": "istanbul cover _mocha -- -r jsdom-global/register test.js"
},

@@ -18,0 +24,0 @@ "repository": {

@@ -0,7 +1,18 @@

[![Build Status](https://travis-ci.org/fhinkel/create-download-link.svg?branch=master)](https://travis-ci.org/fhinkel/create-download-link)
[![Coverage Status](https://coveralls.io/repos/github/fhinkel/create-download-link/badge.svg?branch=master)](https://coveralls.io/github/fhinkel/create-download-link?branch=master)
[![NPM](https://nodei.co/npm/create-download-link.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/create-download-link/)
# create-download-link
*create-download-link* returns an anchor element. When the element is clicked, a file is
downloaded. Specify the content of the file, the filename to be used, and
the title of the anchor element.
*create-download-link* returns the following DOM element:
```html
<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, and
the title of the anchor element. When the element is clicked, a file is
downloaded.
## Example
```javascript

@@ -19,3 +30,2 @@ var createDownloadLink = require('create-download-link');

Include the resulting ```anchor``` in your DOM. It will behave similar to the following link:
[Click to download your file](https://raw.githubusercontent.com/fhinkel/create-download-link/master/example.txt).
var assert = require('chai').assert;
var createDownloadLink = require('./index.js');
describe('When you invoke create-download-link,', function() {
describe('When you invoke create-download-link,', function () {

@@ -20,6 +20,6 @@ before(function () {

it('should have the correct attributes', function () {
assert.equal(this.anchor.getAttribute('href'),'data:application/octet-stream,nice%20data');
assert.equal(this.anchor.getAttribute('download'),'filename.txt');
assert.equal(this.anchor.getAttribute('href'), 'data:application/octet-stream,nice%20data');
assert.equal(this.anchor.getAttribute('download'), 'filename.txt');
});
it('should have a title', function() {
it('should have a title', function () {
assert.equal(this.anchor.childNodes.length, 1);

@@ -29,4 +29,16 @@ assert.equal(this.anchor.firstChild.nodeValue, 'nice title');

});
describe('creation', function () {
it('should fail if data is missing', function () {
});
it('should fail if data is missing', function () {
});
it('should fail if data is missing', function () {
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc