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 2.3.1 to 2.4.0

.github/workflows/FUNDING.yml

264

dist/browserify.js

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

});
exports["default"] = void 0;
exports.addBrowser = addBrowser;
/* global WorkerGlobalScope */
/* global WorkerGlobalScope */
function add(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {// this is run inside of a webworker
function addBrowser(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
/**
* Because killing a worker does directly stop the excution
* of the code, our only chance is to overwrite the close function
* which could work some times.
* @link https://stackoverflow.com/q/72903255/3443137
*/
var oldClose = self.close.bind(self);
self.close = function () {
fn();
return oldClose();
};
} else {

@@ -18,10 +29,13 @@ /**

*/
if (typeof window.addEventListener !== 'function') return;
if (typeof window.addEventListener !== 'function') {
return;
}
/**
* for normal browser-windows, we use the beforeunload-event
*/
window.addEventListener('beforeunload', function () {
fn();
}, true);
/**

@@ -31,3 +45,2 @@ * for iframes, we have to use the unload-event

*/
window.addEventListener('unload', function () {

@@ -37,2 +50,3 @@ fn();

}
/**

@@ -42,9 +56,3 @@ * TODO add fallback for safari-mobile

*/
}
var _default = {
add: add
};
exports["default"] = _default;
},{}],2:[function(require,module,exports){

@@ -54,9 +62,7 @@ "use strict";

var unload = require('./index.js');
window['unload'] = unload;
},{"./index.js":3}],3:[function(require,module,exports){
(function (process){(function (){
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -69,22 +75,25 @@ value: true

exports.runAll = runAll;
var _detectNode = _interopRequireDefault(require("detect-node"));
var _browser = _interopRequireDefault(require("./browser.js"));
var _node = _interopRequireDefault(require("./node.js"));
var USE_METHOD = _detectNode["default"] ? _node["default"] : _browser["default"];
var _browser = require("./browser.js");
var _node = require("./node.js");
/**
* Use the code directly to prevent import problems
* with the detect-node package.
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
var USE_METHOD = isNode ? _node.addNode : _browser.addBrowser;
var LISTENERS = new Set();
var startedListening = false;
function startListening() {
if (startedListening) return;
if (startedListening) {
return;
}
startedListening = true;
USE_METHOD.add(runAll);
USE_METHOD(runAll);
}
function add(fn) {
startListening();
if (typeof fn !== 'function') throw new Error('Listener is no function');
if (typeof fn !== 'function') {
throw new Error('Listener is no function');
}
LISTENERS.add(fn);

@@ -102,3 +111,2 @@ var addReturn = {

}
function runAll() {

@@ -112,25 +120,197 @@ var promises = [];

}
function removeAll() {
LISTENERS.clear();
}
function getSize() {
return LISTENERS.size;
}
},{"./browser.js":1,"./node.js":5,"@babel/runtime/helpers/interopRequireDefault":4,"detect-node":6}],4:[function(require,module,exports){
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
"default": obj
};
}
}).call(this)}).call(this,require('_process'))
},{"./browser.js":1,"./node.js":4,"_process":5}],4:[function(require,module,exports){
module.exports = _interopRequireDefault;
module.exports["default"] = module.exports, module.exports.__esModule = true;
},{}],5:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
},{}],6:[function(require,module,exports){
module.exports = false;
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}]},{},[2]);

32

dist/es/browser.js
/* global WorkerGlobalScope */
function add(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {// this is run inside of a webworker
export function addBrowser(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
/**
* Because killing a worker does directly stop the excution
* of the code, our only chance is to overwrite the close function
* which could work some times.
* @link https://stackoverflow.com/q/72903255/3443137
*/
var oldClose = self.close.bind(self);
self.close = function () {
fn();
return oldClose();
};
} else {

@@ -9,10 +21,13 @@ /**

*/
if (typeof window.addEventListener !== 'function') return;
if (typeof window.addEventListener !== 'function') {
return;
}
/**
* for normal browser-windows, we use the beforeunload-event
*/
window.addEventListener('beforeunload', function () {
fn();
}, true);
/**

@@ -22,3 +37,2 @@ * for iframes, we have to use the unload-event

*/
window.addEventListener('unload', function () {

@@ -28,2 +42,3 @@ fn();

}
/**

@@ -33,7 +48,2 @@ * TODO add fallback for safari-mobile

*/
}
export default {
add: add
};
}
var unload = require('./index.js');
window['unload'] = unload;

@@ -1,17 +0,25 @@

import isNode from 'detect-node';
import BrowserMethod from './browser.js';
import NodeMethod from './node.js';
var USE_METHOD = isNode ? NodeMethod : BrowserMethod;
import { addBrowser } from './browser.js';
import { addNode } from './node.js';
/**
* Use the code directly to prevent import problems
* with the detect-node package.
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
var USE_METHOD = isNode ? addNode : addBrowser;
var LISTENERS = new Set();
var startedListening = false;
function startListening() {
if (startedListening) return;
if (startedListening) {
return;
}
startedListening = true;
USE_METHOD.add(runAll);
USE_METHOD(runAll);
}
export function add(fn) {
startListening();
if (typeof fn !== 'function') throw new Error('Listener is no function');
if (typeof fn !== 'function') {
throw new Error('Listener is no function');
}
LISTENERS.add(fn);

@@ -18,0 +26,0 @@ var addReturn = {

@@ -1,9 +0,6 @@

// set to true to log events
var DEBUG = false;
function add(fn) {
export function addNode(fn) {
process.on('exit', function () {
DEBUG && console.log('node: exit');
return fn();
});
/**

@@ -15,28 +12,20 @@ * on the following events,

*/
process.on('beforeExit', function () {
DEBUG && console.log('node: beforeExit');
return fn().then(function () {
return process.exit();
});
}); // catches ctrl+c event
});
// catches ctrl+c event
process.on('SIGINT', function () {
DEBUG && console.log('node: SIGNINT');
return fn().then(function () {
return process.exit();
});
}); // catches uncaught exceptions
});
// catches uncaught exceptions
process.on('uncaughtException', function (err) {
DEBUG && console.log('node: uncaughtException');
return fn().then(function () {
console.trace(err);
process.exit(1);
process.exit(101);
});
});
}
export default {
add: add
};
}

@@ -6,7 +6,18 @@ "use strict";

});
exports["default"] = void 0;
exports.addBrowser = addBrowser;
/* global WorkerGlobalScope */
/* global WorkerGlobalScope */
function add(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {// this is run inside of a webworker
function addBrowser(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
/**
* Because killing a worker does directly stop the excution
* of the code, our only chance is to overwrite the close function
* which could work some times.
* @link https://stackoverflow.com/q/72903255/3443137
*/
var oldClose = self.close.bind(self);
self.close = function () {
fn();
return oldClose();
};
} else {

@@ -17,10 +28,13 @@ /**

*/
if (typeof window.addEventListener !== 'function') return;
if (typeof window.addEventListener !== 'function') {
return;
}
/**
* for normal browser-windows, we use the beforeunload-event
*/
window.addEventListener('beforeunload', function () {
fn();
}, true);
/**

@@ -30,3 +44,2 @@ * for iframes, we have to use the unload-event

*/
window.addEventListener('unload', function () {

@@ -36,2 +49,3 @@ fn();

}
/**

@@ -41,8 +55,2 @@ * TODO add fallback for safari-mobile

*/
}
var _default = {
add: add
};
exports["default"] = _default;
}
"use strict";
var unload = require('./index.js');
window['unload'] = unload;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -12,22 +10,25 @@ value: true

exports.runAll = runAll;
var _detectNode = _interopRequireDefault(require("detect-node"));
var _browser = _interopRequireDefault(require("./browser.js"));
var _node = _interopRequireDefault(require("./node.js"));
var USE_METHOD = _detectNode["default"] ? _node["default"] : _browser["default"];
var _browser = require("./browser.js");
var _node = require("./node.js");
/**
* Use the code directly to prevent import problems
* with the detect-node package.
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
var isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
var USE_METHOD = isNode ? _node.addNode : _browser.addBrowser;
var LISTENERS = new Set();
var startedListening = false;
function startListening() {
if (startedListening) return;
if (startedListening) {
return;
}
startedListening = true;
USE_METHOD.add(runAll);
USE_METHOD(runAll);
}
function add(fn) {
startListening();
if (typeof fn !== 'function') throw new Error('Listener is no function');
if (typeof fn !== 'function') {
throw new Error('Listener is no function');
}
LISTENERS.add(fn);

@@ -45,3 +46,2 @@ var addReturn = {

}
function runAll() {

@@ -55,9 +55,7 @@ var promises = [];

}
function removeAll() {
LISTENERS.clear();
}
function getSize() {
return LISTENERS.size;
}

@@ -6,11 +6,8 @@ "use strict";

});
exports["default"] = void 0;
// set to true to log events
var DEBUG = false;
function add(fn) {
exports.addNode = addNode;
function addNode(fn) {
process.on('exit', function () {
DEBUG && console.log('node: exit');
return fn();
});
/**

@@ -22,29 +19,20 @@ * on the following events,

*/
process.on('beforeExit', function () {
DEBUG && console.log('node: beforeExit');
return fn().then(function () {
return process.exit();
});
}); // catches ctrl+c event
});
// catches ctrl+c event
process.on('SIGINT', function () {
DEBUG && console.log('node: SIGNINT');
return fn().then(function () {
return process.exit();
});
}); // catches uncaught exceptions
});
// catches uncaught exceptions
process.on('uncaughtException', function (err) {
DEBUG && console.log('node: uncaughtException');
return fn().then(function () {
console.trace(err);
process.exit(1);
process.exit(101);
});
});
}
var _default = {
add: add
};
exports["default"] = _default;
}
{
"name": "unload",
"version": "2.3.1",
"version": "2.4.0",
"description": "Execute code when the js-process exits. On all javascript-environments",

@@ -36,2 +36,3 @@ "author": "pubkey",

},
"funding": "https://github.com/sponsors/pubkey",
"pre-commit": [

@@ -44,46 +45,42 @@ "lint"

"devDependencies": {
"@babel/cli": "7.6.2",
"@babel/core": "7.6.2",
"@babel/cli": "7.20.7",
"@babel/core": "7.20.7",
"@babel/plugin-check-constants": "7.0.0-beta.38",
"@babel/plugin-proposal-object-rest-spread": "7.6.2",
"@babel/plugin-transform-member-expression-literals": "7.2.0",
"@babel/plugin-transform-property-literals": "7.2.0",
"@babel/plugin-transform-runtime": "7.6.2",
"@babel/polyfill": "7.6.0",
"@babel/preset-env": "7.6.2",
"@babel/types": "7.6.1",
"@babel/plugin-proposal-object-rest-spread": "7.20.7",
"@babel/plugin-transform-member-expression-literals": "7.18.6",
"@babel/plugin-transform-property-literals": "7.18.6",
"@babel/plugin-transform-runtime": "7.19.6",
"@babel/polyfill": "7.12.1",
"@babel/preset-env": "7.20.2",
"@babel/types": "7.20.7",
"assert": "2.0.0",
"async-test-util": "1.7.3",
"browserify": "16.5.0",
"async-test-util": "2.0.0",
"browserify": "17.0.0",
"child_process": "1.0.2",
"child-process-promise": "2.2.1",
"child_process": "1.0.2",
"concurrently": "4.1.2",
"cors": "2.8.5",
"cross-env": "6.0.0",
"eslint": "6.4.0",
"express": "4.17.1",
"http-server": "0.11.1",
"karma": "4.3.0",
"karma-browserify": "6.1.0",
"karma-chrome-launcher": "3.1.0",
"karma-mocha": "1.3.0",
"mocha": "6.2.0",
"node": "12.11.0",
"cross-env": "7.0.3",
"eslint": "8.30.0",
"express": "4.17.3",
"http-server": "0.13.0",
"karma": "6.4.1",
"karma-browserify": "8.1.0",
"karma-chrome-launcher": "3.1.1",
"karma-mocha": "2.0.1",
"mocha": "10.2.0",
"node-cmd": "3.0.0",
"npm-run-all": "4.1.5",
"pre-commit": "1.2.2",
"request": "2.88.0",
"request-promise-native": "1.0.7",
"rimraf": "3.0.0",
"request": "2.88.2",
"request-promise-native": "1.0.9",
"rimraf": "3.0.2",
"ts-node": "7.0.1",
"typescript": "3.6.3",
"uglify-js": "3.6.0",
"util": "0.12.1",
"typescript": "3.9.10",
"uglify-js": "3.17.4",
"util": "0.12.5",
"watch": "1.0.2",
"watchify": "3.11.1"
},
"dependencies": {
"@babel/runtime": "^7.6.2",
"detect-node": "2.1.0"
},
"dependencies": {},
"// browser": "this field contains files that will be empty objects in webpack-builds",

@@ -90,0 +87,0 @@ "browser": {

# javascript: unload
Run a piece of code whenever the javascript-process stops/exits/quits. On **browsers, nodejs, electron, react-native**. 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, workers, iframes**. It also ensures that the exit-function is called only **once**.
You should use this module when your write a npm-library where you dont know in which environments the users will run it.
You should use this module when your write a npm library where you dont know in which environments the users will run it.

@@ -69,1 +69,17 @@ # What does `unload` handle?

```
# Sponsored by
<p align="center">
<a href="https://rxdb.info/?utm_source=github&utm_medium=repo&utm_campaign=github-unload">
<img
src="https://github.com/pubkey/rxdb/raw/master/docs-src/files/logo/logo_text.svg"
alt="Sponsored by RxDB"
width="300"
/>
<br />
<br />
<span>The <b>JavaScript Database</b></span>
</a>
</p>
/* global WorkerGlobalScope */
function add(fn) {
export function addBrowser(fn) {
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
// this is run inside of a webworker
/**
* Because killing a worker does directly stop the excution
* of the code, our only chance is to overwrite the close function
* which could work some times.
* @link https://stackoverflow.com/q/72903255/3443137
*/
const oldClose = self.close.bind(self);
self.close = () => {
fn();
return oldClose();
};
} else {

@@ -12,3 +22,5 @@

*/
if (typeof window.addEventListener !== 'function') return;
if (typeof window.addEventListener !== 'function') {
return;
}

@@ -36,5 +48,1 @@ /**

}
export default {
add
};

@@ -1,6 +0,12 @@

import isNode from 'detect-node';
import BrowserMethod from './browser.js';
import NodeMethod from './node.js';
import { addBrowser } from './browser.js';
import { addNode } from './node.js';
const USE_METHOD = isNode ? NodeMethod : BrowserMethod;
/**
* Use the code directly to prevent import problems
* with the detect-node package.
* @link https://github.com/iliakan/detect-node/blob/master/index.js
*/
const isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
const USE_METHOD = isNode ? addNode : addBrowser;
const LISTENERS = new Set();

@@ -10,5 +16,7 @@

function startListening() {
if (startedListening) return;
if (startedListening) {
return;
}
startedListening = true;
USE_METHOD.add(runAll);
USE_METHOD(runAll);
}

@@ -18,4 +26,5 @@

startListening();
if (typeof fn !== 'function')
if (typeof fn !== 'function') {
throw new Error('Listener is no function');
}
LISTENERS.add(fn);

@@ -22,0 +31,0 @@

@@ -1,7 +0,3 @@

// set to true to log events
const DEBUG = false;
function add(fn) {
export function addNode(fn) {
process.on('exit', () => {
DEBUG && console.log('node: exit');
return fn();

@@ -17,3 +13,2 @@ });

process.on('beforeExit', () => {
DEBUG && console.log('node: beforeExit');
return fn().then(() => process.exit());

@@ -23,3 +18,2 @@ });

process.on('SIGINT', () => {
DEBUG && console.log('node: SIGNINT');
return fn().then(() => process.exit());

@@ -29,13 +23,8 @@ });

process.on('uncaughtException', err => {
DEBUG && console.log('node: uncaughtException');
return fn()
.then(() => {
console.trace(err);
process.exit(1);
process.exit(101);
});
});
}
export default {
add
};

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