Socket
Socket
Sign inDemoInstall

async-script

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-script - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

14

index.js
'use strict';
var one = require('one-time');
/**

@@ -12,2 +14,4 @@ * Async load a script file.

module.exports = function scripts(document, url, fn) {
fn = one(fn);
var script = document.createElement('script');

@@ -21,2 +25,4 @@

function unload() {
fn(new Error('The script has been removed.'));
if (!script) return;

@@ -40,4 +46,4 @@ if (script.parentNode) script.parentNode.removeChild(script);

script.onerror = function onerror() {
fn(new Error('Failed to load the script.'));
unload();
fn(new Error('Failed to load the script.'));
};

@@ -51,4 +57,4 @@

script.onload = function onload() {
fn();
unload();
fn();
};

@@ -63,4 +69,4 @@

if (this.readyState in { loaded: 1, complete: 1 }) {
fn();
unload();
fn();
}

@@ -75,2 +81,4 @@ };

script.src = url;
return unload;
};
{
"name": "async-script",
"version": "0.0.0",
"version": "0.0.1",
"description": "Asyncly load a script",
"main": "index.js",
"scripts": {
"test": "mocha test.js",
"watch": "mocha --watch test.js",
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"
"test": "mochify ./test.js --reporter spec --ui bdd",
"watch": "mocha --watch ./test.js",
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- ./test.js",
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- ./test.js"
},

@@ -33,5 +33,9 @@ "repository": {

"mocha": "2.1.x",
"mochify": "2.1.x",
"pre-commit": "0.0.x"
},
"homepage": "https://github.com/bigpipe/async-script"
"homepage": "https://github.com/bigpipe/async-script",
"dependencies": {
"one-time": "0.0.x"
}
}
describe('async-script', function () {
'use strict';
var assume = require('assume')
var url = 'https://code.jquery.com/jquery-latest.js'
, assume = require('assume')
, script = require('./');

@@ -10,2 +11,23 @@

});
it('loads the script', function (next) {
assume(typeof jQuery).equals('undefined');
script(document, url, function (err) {
if (err) return next(err);
assume(typeof jQuery).does.not.equal('undefined');
next();
});
});
it('returns a unload function when called', function (next) {
var unload = script(document, url, function (err) {
assume(err.message).includes('remove');
next();
});
assume(unload).is.a('function');
unload();
});
});

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