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.1 to 1.0.2

example.txt

2

index.js

@@ -9,3 +9,3 @@ module.exports = function (opt) {

var link = 'data:application/octet-stream,' + encodeURIComponent(text);
var anchor = document.createElement("A");
var anchor = document.createElement('a');
anchor.setAttribute('href', link);

@@ -12,0 +12,0 @@ anchor.setAttribute('download', filename);

{
"name": "create-download-link",
"version": "1.0.1",
"version": "1.0.2",
"description": "Create link to download text as file",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"devDependencies": {
"chai": "3.5.0",
"jsdom": "8.3.1",
"jsdom-global": "1.7.0",
"mocha": "2.4.5"
},
"scripts": {
"test": "node test.js"
"test": "mocha -r jsdom-global/register test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fhinkel/shell-emulator.git"
"url": "git+https://github.com/fhinkel/create-download-link.git"
},

@@ -18,5 +23,5 @@ "author": "",

"bugs": {
"url": "https://github.com/fhinkel/shell-emulator/issues"
"url": "https://github.com/fhinkel/create-download-link/issues"
},
"homepage": "https://github.com/fhinkel/shell-emulator#readme"
"homepage": "https://github.com/fhinkel/create-download-link#readme"
}
# create-download-link
Create a link to download a text file.
Specify the content, filename,
and title of the link via the options argument:
*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.
```javascript
var data = opt.data;
var title = opt.title;
var filename = opt.filename;
```
var createDownloadLink = require('create-download-link');
var opt = {
data: 'Here is the content of the file',
title: 'Click to download your file',
filename: 'example.txt'
};
var anchor = createDownloadLink(opt);
```
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).

@@ -0,20 +1,30 @@

var assert = require('chai').assert;
var createDownloadLink = require('./index.js');
var opt = {
};
describe('When you invoke create-download-link,', function() {
document = {
createElement: function() {
return {
setAttribute: function() {},
appendChild: function() {}
before(function () {
var opt = {
data: 'nice data',
title: 'nice title',
filename: 'filename.txt'
};
},
createTextNode: function () {
}
};
this.anchor = createDownloadLink(opt);
});
createDownloadLink(opt);
describe('the link', function () {
it('should be of type anchor', function () {
assert.equal(this.anchor.nodeName, 'A');
});
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');
});
it('should have a title', function() {
assert.equal(this.anchor.childNodes.length, 1);
assert.equal(this.anchor.firstChild.nodeValue, 'nice title');
});
});
});
console.log('Done testing. All good');
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