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

dom-event-helpers

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-event-helpers - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

README.md

62

package.json
{
"name": "dom-event-helpers",
"version": "0.3.0",
"description": "Super tiny DOM event helpers.",
"repository": "git@github.com:jsor/dom-event-helpers.git",
"version": "1.0.0",
"description": "A super tiny DOM event helper library.",
"repository": "https://github.com/jsor/dom-event-helpers.git",
"author": {

@@ -16,4 +16,56 @@ "name": "Jan Sorgalla",

"helper",
"utility"
]
"utility",
"on",
"off",
"ready"
],
"files": [
"src",
"index.js"
],
"xo": {
"space": 4,
"rules": {
"max-params": [
"warn",
{
"max": 5
}
]
},
"ignores": [
"test/**",
"karma*"
],
"envs": [
"node",
"browser"
]
},
"scripts": {
"lint": "xo",
"dev": "karma start",
"test": "npm run lint && karma start --single-run"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"chai": "^4.1.2",
"istanbul-instrumenter-loader": "^3.0.0",
"karma": "^2.0.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sauce-launcher": "^1.2.0",
"karma-webpack": "^2.0.13",
"mocha": "^4.1.0",
"simulant": "^0.2.2",
"webpack": "^4.1.1",
"xo": "^0.20.3"
}
}

6

src/off.js
import optionsArgument from './options-argument';
export default function off(node, type, listener, options = {capture: false}) {
node.removeEventListener(type, listener, optionsArgument(options));
};
export default function off(target, type, listener, options = {capture: false}) {
target.removeEventListener(type, listener, optionsArgument(options));
}

@@ -5,20 +5,19 @@ import optionsSupport from './options-support';

export default function on(node, type, listener, options = {capture: false}) {
let cb = listener;
let rm;
export default function on(target, type, listener, options = {capture: false}) {
let callback = listener;
const remove = () => {
off(target, type, callback, options);
};
if (options.once && !optionsSupport().once) {
cb = (event) => {
rm();
listener.call(node, event);
callback = event => {
remove();
listener.call(target, event);
};
}
rm = () => {
off(node, type, cb, options);
};
target.addEventListener(type, callback, optionsArgument(options));
node.addEventListener(type, cb, optionsArgument(options));
return rm;
};
return remove;
}
import support from './options-support';
export default function(options = {}) {
export default function optionsArgument(options = {}) {
const {once, passive, capture} = support();

@@ -5,0 +5,0 @@

let supportedOptions;
export default function(force = false) {
if (supportedOptions && !force) {
export default function optionsSupport() {
if (supportedOptions) {
return supportedOptions;

@@ -9,12 +9,12 @@ }

supportedOptions = {
capture: false,
once: false,
passive: false,
capture: false,
passive: false
};
if (!window) {
return supportedOptions;
}
const options = {
get capture() {
supportedOptions.capture = true;
return false;
},
get once() {

@@ -27,6 +27,2 @@ supportedOptions.once = true;

return false;
},
get capture() {
supportedOptions.capture = true;
return false;
}

@@ -33,0 +29,0 @@ };

import optionsArgument from './options-argument';
export default function(listener) {
if (
document.readyState === 'interactive' ||
document.readyState === 'complete'
) {
setTimeout(() => {
listener();
}, 0);
export default function ready(listener) {
const state = document.readyState;
if (state === 'complete' || state === 'interactive') {
setTimeout(listener, 0);
return;

@@ -20,8 +16,10 @@ }

},
optionsArgument({
capture: true,
once: true,
passive: true
})
optionsArgument(
{
capture: true,
once: true,
passive: true
}
)
);
}
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