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

dom-eventer

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-eventer - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

242

lib/index.js

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

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(t){r(this,e),this._name=t,this._subscriptions={},this._recentId=Date.now()}return i(e,[{key:"use",value:function(e){var t=this;return function(){return t[e].apply(t,arguments)}}},{key:"on",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this.use("listen").apply(this,t)}},{key:"off",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this.use("remove").apply(this,t)}},{key:"once",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this.use("listen").apply(this,[].concat(t,[1]))}},{key:"isValidListener",value:function(e){return"function"==typeof e}},{key:"updateHitCount",value:function(e){if(this._subscriptions[e]){var t=this._subscriptions[e],n=t.hit,r=t.limit;this._subscriptions[e].hit+=1,r&&n===r&&this.remove(e)}}},{key:"listen",value:function(e,t,n,r){var i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=Array.from(arguments);if(o.length<3)throw new Error("`target`, `eventType` and `cb` params are required");if(!this.isValidListener(n))throw new TypeError("listener must be a function");"boolean"==typeof o[3]&&(i=o[3],r=null);var s=t+"."+(this._recentId+1);this._recentId+=1;var u=function(e,t){return function(){t.updateHitCount(e),n.apply(void 0,arguments)}}(s,this);return this._subscriptions[s]={limit:r,hit:0,type:t},e.addEventListener?(e.addEventListener(t,u,i),this._subscriptions[s].remove=function(){e.removeEventListener(t,u,i)}):e.attachEvent&&(e.attachEvent("on"+t,u),this._subscriptions[s].remove=function(){e.detachEvent("on"+t,u)}),s}},{key:"remove",value:function(e){this._subscriptions[e]&&(this._subscriptions[e].remove(),this._subscriptions[e].isRemove=!0)}},{key:"removeAll",value:function(){var e=this;Object.keys(this._subscriptions).forEach(function(t){e.remove(t)})}}]),e}();t.default=o,e.exports=t.default}])});
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DOMEventer = function () {
function DOMEventer(name) {
_classCallCheck(this, DOMEventer);
this._name = name;
this._subscriptions = {};
this._recentId = Date.now();
}
_createClass(DOMEventer, [{
key: 'use',
value: function use(name) {
var _this = this;
return function () {
return _this[name].apply(_this, arguments);
};
}
}, {
key: 'on',
value: function on() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
this.use('listen').apply(this, args);
}
}, {
key: 'off',
value: function off() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
this.use('remove').apply(this, args);
}
}, {
key: 'once',
value: function once() {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
this.use('listen').apply(this, [].concat(args, [1]));
}
}, {
key: 'isValidListener',
value: function isValidListener(cb) {
return typeof cb === 'function';
}
}, {
key: 'updateHitCount',
value: function updateHitCount(id) {
if (this._subscriptions[id]) {
var _subscriptions$id = this._subscriptions[id],
hit = _subscriptions$id.hit,
limit = _subscriptions$id.limit;
this._subscriptions[id].hit += 1;
if (limit && hit === limit) {
this.remove(id);
}
}
}
}, {
key: 'listen',
value: function listen(target, eventType, cb, limit) {
var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
var args = Array.from(arguments);
if (args.length < 3) {
throw new Error('`target`, `eventType` and `cb` params are required');
}
if (!this.isValidListener(cb)) {
throw new TypeError('listener must be a function');
}
if (typeof args[3] === 'boolean') {
capture = args[3];
limit = null;
}
var id = eventType + '.' + (this._recentId + 1);
this._recentId += 1;
var wrapperCb = function (id, that) {
return function () {
// should not be bind.
that.updateHitCount(id);
cb.apply(undefined, arguments);
};
}(id, this);
this._subscriptions[id] = {
limit: limit,
hit: 0,
type: eventType
};
if (target.addEventListener) {
target.addEventListener(eventType, wrapperCb, capture);
this._subscriptions[id].remove = function () {
target.removeEventListener(eventType, wrapperCb, capture);
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, wrapperCb);
this._subscriptions[id].remove = function () {
target.detachEvent('on' + eventType, wrapperCb);
};
}
return id;
}
}, {
key: 'remove',
value: function remove(id) {
if (this._subscriptions[id]) {
this._subscriptions[id].remove();
this._subscriptions[id].isRemove = true;
}
}
}, {
key: 'removeAll',
value: function removeAll() {
var _this2 = this;
var ids = Object.keys(this._subscriptions);
ids.forEach(function (id) {
_this2.remove(id);
});
}
}]);
return DOMEventer;
}();
exports.default = DOMEventer;
module.exports = exports['default'];
/***/ })
/******/ ]);
});

2

package.json
{
"name": "dom-eventer",
"version": "1.1.0",
"version": "1.2.0",
"description": "A utility to control the occurence of DOM eventer",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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