Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unload

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unload - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

21

dist/unload.js

@@ -232,5 +232,10 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

var unloaded = false;
var debug = false;
var count = 0;
var cache = {};
exports.debug = function() {
debug = true;
};
/**

@@ -259,3 +264,9 @@ * start listening with the handler

});
debug && console.log('unload.stopListening()');
debug && console.dir(cache[count]);
};
retFn.run = function() {
fnWrapped();
};

@@ -268,2 +279,5 @@ cache[count] = {

debug && console.log('unload.add()');
debug && console.dir(cache[count]);
return retFn;

@@ -278,3 +292,3 @@ };

});
}
};

@@ -285,3 +299,3 @@ exports.removeAll = function() {

});
}
};

@@ -313,3 +327,3 @@ return exports;

});
}
};
process.on('beforeExit', ret.beforeExit);

@@ -355,3 +369,2 @@

case 'exit':
console.log('remove');
process.removeListener(key, fn);

@@ -358,0 +371,0 @@ break;

2

dist/unload.min.js

@@ -1,1 +0,1 @@

!function e(n,t,r){function o(u,c){if(!t[u]){if(!n[u]){var f="function"==typeof require&&require;if(!c&&f)return f(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=t[u]={exports:{}};n[u][0].call(a.exports,function(e){var t=n[u][1][e];return o(t?t:e)},a,a.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,n,t){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(n){try{return l.call(null,e,0)}catch(n){return l.call(this,e,0)}}}function u(e){if(v===clearTimeout)return clearTimeout(e);if((v===o||!v)&&clearTimeout)return v=clearTimeout,clearTimeout(e);try{return v(e)}catch(n){try{return v.call(null,e)}catch(n){return v.call(this,e)}}}function c(){p&&d&&(p=!1,d.length?m=d.concat(m):w=-1,m.length&&f())}function f(){if(!p){var e=i(c);p=!0;for(var n=m.length;n;){for(d=m,m=[];++w<n;)d&&d[w].run();w=-1,n=m.length}d=null,p=!1,u(e)}}function s(e,n){this.fun=e,this.array=n}function a(){}var l,v,h=n.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:r}catch(e){l=r}try{v="function"==typeof clearTimeout?clearTimeout:o}catch(e){v=o}}();var d,m=[],p=!1,w=-1;h.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)n[t-1]=arguments[t];m.push(new s(e,n)),1!==m.length||p||i(f)},s.prototype.run=function(){this.fun.apply(null,this.array)},h.title="browser",h.browser=!0,h.env={},h.argv=[],h.version="",h.versions={},h.on=a,h.addListener=a,h.once=a,h.off=a,h.removeListener=a,h.removeAllListeners=a,h.emit=a,h.binding=function(e){throw new Error("process.binding is not supported")},h.cwd=function(){return"/"},h.chdir=function(e){throw new Error("process.chdir is not supported")},h.umask=function(){return 0}},{}],2:[function(e,n,t){n.exports=function(){var e={};return e.add=function(e){var n={};return"object"==typeof window&&window.addEventListener&&"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",e,!1),n.beforeunload=e),n},e.remove=function(e,n){Object.keys(n).forEach(function(e){var t=n[e];switch(e){case"beforeunload":window.removeEventListener("beforeunload",t,!1)}})},e}()},{}],3:[function(e,n,t){var r=e("./index.js");window.unload=r},{"./index.js":4}],4:[function(e,n,t){n.exports=function(e){var n={},t=!1,r=0,o={};return n.add=function(n){r++;var i=function(e,r,o){if(!t)return t=!0,n(e,r,o)},u={};Object.keys(e).forEach(function(n){u[n]=e[n].add(i)});var c=function(){Object.keys(u).forEach(function(n){e[n].remove(i,u[n])})};return o[r]={fn:n,remove:c,listeners:u},c},n.runAll=function(){t||(t=!0,Object.keys(o).forEach(function(e){o[e].fn()}))},n.removeAll=function(){Object.keys(o).forEach(function(e){o[e].remove()})},n}({node:e("./nodeJS.js"),browser:e("./browser.js")})},{"./browser.js":2,"./nodeJS.js":5}],5:[function(e,n,t){(function(e){n.exports=function(){var n={};return n.add=function(n){var t={};return"object"==typeof e&&e.on&&"function"==typeof e.on&&(t.beforeExit=function(t){var r=n(t);Promise.resolve(r).then(function(){e.exit()})},e.on("beforeExit",t.beforeExit),t.exit=function(e){var t=n(e);Promise.resolve(t)},e.on("exit",t.exit),t.SIGINT=function(t){var r=n(t);Promise.resolve(r).then(function(){e.exit()})},e.on("SIGINT",t.SIGINT),t.uncaughtException=function(t){var r=n(t);Promise.resolve(r).then(function(){e.exit()})},e.on("uncaughtException",t.uncaughtException)),t},n.remove=function(n,t){Object.keys(t).forEach(function(n){var r=t[n];switch(n){case"beforeExit":case"SIGINT":case"uncaughtException":case"exit":console.log("remove"),e.removeListener(n,r)}})},n}()}).call(this,e("_process"))},{_process:1}]},{},[3]);
!function n(e,t,r){function o(u,c){if(!t[u]){if(!e[u]){var f="function"==typeof require&&require;if(!c&&f)return f(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=t[u]={exports:{}};e[u][0].call(a.exports,function(n){var t=e[u][1][n];return o(t?t:n)},a,a.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e,t){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(n){if(l===setTimeout)return setTimeout(n,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(n,0);try{return l(n,0)}catch(e){try{return l.call(null,n,0)}catch(e){return l.call(this,n,0)}}}function u(n){if(d===clearTimeout)return clearTimeout(n);if((d===o||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(n);try{return d(n)}catch(e){try{return d.call(null,n)}catch(e){return d.call(this,n)}}}function c(){m&&v&&(m=!1,v.length?p=v.concat(p):w=-1,p.length&&f())}function f(){if(!m){var n=i(c);m=!0;for(var e=p.length;e;){for(v=p,p=[];++w<e;)v&&v[w].run();w=-1,e=p.length}v=null,m=!1,u(n)}}function s(n,e){this.fun=n,this.array=e}function a(){}var l,d,h=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:r}catch(n){l=r}try{d="function"==typeof clearTimeout?clearTimeout:o}catch(n){d=o}}();var v,p=[],m=!1,w=-1;h.nextTick=function(n){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];p.push(new s(n,e)),1!==p.length||m||i(f)},s.prototype.run=function(){this.fun.apply(null,this.array)},h.title="browser",h.browser=!0,h.env={},h.argv=[],h.version="",h.versions={},h.on=a,h.addListener=a,h.once=a,h.off=a,h.removeListener=a,h.removeAllListeners=a,h.emit=a,h.binding=function(n){throw new Error("process.binding is not supported")},h.cwd=function(){return"/"},h.chdir=function(n){throw new Error("process.chdir is not supported")},h.umask=function(){return 0}},{}],2:[function(n,e,t){e.exports=function(){var n={};return n.add=function(n){var e={};return"object"==typeof window&&window.addEventListener&&"function"==typeof window.addEventListener&&(window.addEventListener("beforeunload",n,!1),e.beforeunload=n),e},n.remove=function(n,e){Object.keys(e).forEach(function(n){var t=e[n];switch(n){case"beforeunload":window.removeEventListener("beforeunload",t,!1)}})},n}()},{}],3:[function(n,e,t){var r=n("./index.js");window.unload=r},{"./index.js":4}],4:[function(n,e,t){e.exports=function(n){var e={},t=!1,r=!1,o=0,i={};return e.debug=function(){r=!0},e.add=function(e){o++;var u=function(n,r,o){if(!t)return t=!0,e(n,r,o)},c={};Object.keys(n).forEach(function(e){c[e]=n[e].add(u)});var f=function(){Object.keys(c).forEach(function(e){n[e].remove(u,c[e])}),r&&console.log("unload.stopListening()"),r&&console.dir(i[o])};return f.run=function(){u()},i[o]={fn:e,remove:f,listeners:c},r&&console.log("unload.add()"),r&&console.dir(i[o]),f},e.runAll=function(){t||(t=!0,Object.keys(i).forEach(function(n){i[n].fn()}))},e.removeAll=function(){Object.keys(i).forEach(function(n){i[n].remove()})},e}({node:n("./nodeJS.js"),browser:n("./browser.js")})},{"./browser.js":2,"./nodeJS.js":5}],5:[function(n,e,t){(function(n){e.exports=function(){var e={};return e.add=function(e){var t={};return"object"==typeof n&&n.on&&"function"==typeof n.on&&(t.beforeExit=function(t){var r=e(t);Promise.resolve(r).then(function(){n.exit()})},n.on("beforeExit",t.beforeExit),t.exit=function(n){var t=e(n);Promise.resolve(t)},n.on("exit",t.exit),t.SIGINT=function(t){var r=e(t);Promise.resolve(r).then(function(){n.exit()})},n.on("SIGINT",t.SIGINT),t.uncaughtException=function(t){var r=e(t);Promise.resolve(r).then(function(){n.exit()})},n.on("uncaughtException",t.uncaughtException)),t},e.remove=function(e,t){Object.keys(t).forEach(function(e){var r=t[e];switch(e){case"beforeExit":case"SIGINT":case"uncaughtException":case"exit":n.removeListener(e,r)}})},e}()}).call(this,n("_process"))},{_process:1}]},{},[3]);
{
"name": "unload",
"version": "1.3.4",
"version": "1.3.5",
"description": "Execute code when the js-process exits. On all javascript-environments",

@@ -5,0 +5,0 @@ "scripts": {

# javascript: unload
Run a piece of code whenever the javascript-process stops/exits/quits. On **browsers, nodejs, election, react-native, .net-core**. It also ensures that the exit-function is called only **once**.
Run a piece of code whenever the javascript-process stops/exits/quits. On **browsers, nodejs, electron, react-native, .net-core**. It also ensures that the exit-function is called only **once**.

@@ -5,0 +5,0 @@ You should use this module when your write a npm-library where you dont know in which environments the users will run it.

@@ -6,5 +6,10 @@ module.exports = (function(

var unloaded = false;
var debug = false;
var count = 0;
var cache = {};
exports.debug = function() {
debug = true;
};
/**

@@ -33,3 +38,9 @@ * start listening with the handler

});
debug && console.log('unload.stopListening()');
debug && console.dir(cache[count]);
};
retFn.run = function() {
fnWrapped();
};

@@ -42,2 +53,5 @@ cache[count] = {

debug && console.log('unload.add()');
debug && console.dir(cache[count]);
return retFn;

@@ -52,3 +66,3 @@ };

});
}
};

@@ -59,3 +73,3 @@ exports.removeAll = function() {

});
}
};

@@ -62,0 +76,0 @@ return exports;

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

});
}
};
process.on('beforeExit', ret.beforeExit);

@@ -59,3 +59,2 @@

case 'exit':
console.log('remove');
process.removeListener(key, fn);

@@ -62,0 +61,0 @@ break;

@@ -5,5 +5,5 @@ module.exports = (function(request) {

return request(pingHost).then(c => parseInt(c));
}
};
})(
require('request-promise-native')
);

@@ -7,2 +7,6 @@ var mocha = require('mocha');

var request = require('request-promise-native');
var unload = require('../src/index.js');
describe('nodejs.test.js', function() {

@@ -21,3 +25,3 @@ var startCounter = 0;

});
}
};
check();

@@ -35,3 +39,3 @@ });

it('exception', function(done) {
exec("node ./test/helper/node.js exception", function(error, stdout, stderr) {
exec('node ./test/helper/node.js exception', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -45,3 +49,3 @@ assert.equal(startCounter + 1, c);

it('runout', function(done) {
exec("node ./test/helper/node.js runout", function(error, stdout, stderr) {
exec('node ./test/helper/node.js runout', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -55,3 +59,3 @@ assert.equal(startCounter + 1, c);

it('stopBefore', function(done) {
exec("node ./test/helper/node.js stopBefore", function(error, stdout, stderr) {
exec('node ./test/helper/node.js stopBefore', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -64,3 +68,3 @@ assert.equal(startCounter, c);

it('exit', function(done) {
exec("node ./test/helper/node.js exit", function(error, stdout, stderr) {
exec('node ./test/helper/node.js exit', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -72,2 +76,15 @@ assert.equal(startCounter, c);

});
it('force run', function(done) {
var stopListening = unload.add(function(e) {
return request('http://localhost:23230/');
});
stopListening.run();
setTimeout(function() {
pingCount().then(function(c) {
assert.equal(startCounter + 1, c);
startCounter = c;
done();
});
}, 300);
});
});

@@ -77,3 +94,3 @@

it('should run all', function(done) {
exec("node ./test/helper/node.js runAll", function(error, stdout, stderr) {
exec('node ./test/helper/node.js runAll', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -87,3 +104,3 @@ assert.equal(startCounter + 1, c);

it('should run all twice only once', function(done) {
exec("node ./test/helper/node.js runAlltwice", function(error, stdout, stderr) {
exec('node ./test/helper/node.js runAlltwice', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -100,3 +117,3 @@ assert.equal(startCounter + 1, c);

it('should remove all', function(done) {
exec("node ./test/helper/node.js removeAll", function(error, stdout, stderr) {
exec('node ./test/helper/node.js removeAll', function(error, stdout, stderr) {
pingCount().then(function(c) {

@@ -103,0 +120,0 @@ assert.equal(startCounter, c);

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