Socket
Socket
Sign inDemoInstall

event-target-shim

Package Overview
Dependencies
0
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.7 to 1.1.0

3

dist/event-target-shim.js

@@ -258,2 +258,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.eventTargetShim = f()}})(function(){var define,module,exports;return (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){

}
else if (arguments.length === 1 && Array.isArray(arguments[0])) {
return defineCustomEventTarget(EventTarget, arguments[0]);
}
else if (arguments.length > 0) {

@@ -260,0 +263,0 @@ var types = Array(arguments.length);

2

dist/event-target-shim.min.js

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

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.eventTargetShim=e()}}(function(){return function e(t,n,r){function o(a,i){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!i&&l)return l(a,!0);if(u)return u(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var u="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){"use strict";var r=n.createUniqueKey="undefined"!=typeof Symbol?Symbol:function(e){return"[["+e+"_"+Math.random().toFixed(8).slice(2)+"]]"};n.LISTENERS=r("listeners"),n.newNode=function(e,t){return{listener:e,kind:t,next:null}}},{}],2:[function(e,t,n){"use strict";function r(e,t){for(var n=e[a][t];null!=n;){if(n.kind===l)return n.listener;n=n.next}return null}function o(e,t,n){if(null!=n&&"function"!=typeof n)throw new TypeError("listener should be a function.");for(var r=null,o=e[a][t];null!=o;)o.kind===l?null==r?e[a][t]=o.next:r.next=o.next:r=o,o=o.next;null!=n&&(null==r?e[a][t]=i(n,l):r.next=i(n,l))}var u=e("./commons"),a=u.LISTENERS,i=u.newNode,l=3;n.defineCustomEventTarget=function(e,t){function n(){e.call(this)}var u={constructor:{value:n,configurable:!0,writable:!0}};return t.forEach(function(e){u["on"+e]={get:function(){return r(this,e)},set:function(t){o(this,e,t)},configurable:!0,enumerable:!0}}),n.prototype=Object.create(e.prototype,u),n}},{"./commons":1}],3:[function(e,t,n){"use strict";var r=e("./commons"),o=e("./custom-event-target"),u=e("./event-wrapper"),a=r.LISTENERS,i=r.newNode,l=o.defineCustomEventTarget,f=u.createEventWrapper,c=u.STOP_IMMEDIATE_PROPAGATION_FLAG,s="undefined"!=typeof window&&"undefined"!=typeof window.EventTarget,p=1,v=2,d=t.exports=function b(){if(!(this instanceof b)){if(arguments.length>0){for(var e=Array(arguments.length),t=0;t<arguments.length;++t)e[t]=arguments[t];return l(b,e)}throw new TypeError("Cannot call a class as a function")}Object.defineProperty(this,a,{value:Object.create(null)})};d.prototype=Object.create((s?window.EventTarget:Object).prototype,{constructor:{value:d,writable:!0,configurable:!0},addEventListener:{value:function(e,t,n){if(null==t)return!1;if("function"!=typeof t)throw new TypeError("listener should be a function.");var r=n?p:v,o=this[a][e];if(null==o)return this[a][e]=i(t,r),!0;for(var u=null;null!=o;){if(o.listener===t&&o.kind===r)return!1;u=o,o=o.next}return u.next=i(t,r),!0},configurable:!0,writable:!0},removeEventListener:{value:function(e,t,n){if(null==t)return!1;for(var r=n?p:v,o=null,u=this[a][e];null!=u;){if(u.listener===t&&u.kind===r)return null==o?this[a][e]=u.next:o.next=u.next,!0;o=u,u=u.next}return!1},configurable:!0,writable:!0},dispatchEvent:{value:function(e){var t=this[a][e.type];if(null==t)return!0;for(var n=f(e,this);null!=t&&(t.listener.call(this,n),!n[c]);)t=t.next;return!n.defaultPrevented},configurable:!0,writable:!0}})},{"./commons":1,"./custom-event-target":2,"./event-wrapper":4}],4:[function(e,t,n){"use strict";var r=e("./commons").createUniqueKey,o=r("stop_immediate_propagation_flag"),u=r("canceled_flag"),a=r("original_event"),i=Object.freeze({stopPropagation:Object.freeze({value:function(){var e=this[a];"function"==typeof e.stopPropagation&&e.stopPropagation()},writable:!0,configurable:!0}),stopImmediatePropagation:Object.freeze({value:function(){this[o]=!0;var e=this[a];"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation()},writable:!0,configurable:!0}),preventDefault:Object.freeze({value:function(){this.cancelable===!0&&(this[u]=!0);var e=this[a];"function"==typeof e.preventDefault&&e.preventDefault()},writable:!0,configurable:!0}),defaultPrevented:Object.freeze({get:function(){return this[u]},enumerable:!0,configurable:!0})});n.STOP_IMMEDIATE_PROPAGATION_FLAG=o,n.createEventWrapper=function(e,t){var n="number"==typeof e.timeStamp?e.timeStamp:Date.now(),r={type:{value:e.type,enumerable:!0},target:{value:t,enumerable:!0},currentTarget:{value:t,enumerable:!0},eventPhase:{value:2,enumerable:!0},bubbles:{value:Boolean(e.bubbles),enumerable:!0},cancelable:{value:Boolean(e.cancelable),enumerable:!0},timeStamp:{value:n,enumerable:!0},isTrusted:{value:!1,enumerable:!0}};return r[o]={value:!1,writable:!0},r[u]={value:!1,writable:!0},r[a]={value:e},"undefined"!=typeof e.detail&&(r.detail={value:e.detail,enumerable:!0}),Object.create(Object.create(e,i),r)}},{"./commons":1}]},{},[3])(3)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.eventTargetShim=e()}}(function(){return function e(t,n,r){function a(u,i){if(!n[u]){if(!t[u]){var l="function"==typeof require&&require;if(!i&&l)return l(u,!0);if(o)return o(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(e){var n=t[u][1][e];return a(n?n:e)},c,c.exports,e,t,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)a(r[u]);return a}({1:[function(e,t,n){"use strict";var r=n.createUniqueKey="undefined"!=typeof Symbol?Symbol:function(e){return"[["+e+"_"+Math.random().toFixed(8).slice(2)+"]]"};n.LISTENERS=r("listeners"),n.newNode=function(e,t){return{listener:e,kind:t,next:null}}},{}],2:[function(e,t,n){"use strict";function r(e,t){for(var n=e[u][t];null!=n;){if(n.kind===l)return n.listener;n=n.next}return null}function a(e,t,n){if(null!=n&&"function"!=typeof n)throw new TypeError("listener should be a function.");for(var r=null,a=e[u][t];null!=a;)a.kind===l?null==r?e[u][t]=a.next:r.next=a.next:r=a,a=a.next;null!=n&&(null==r?e[u][t]=i(n,l):r.next=i(n,l))}var o=e("./commons"),u=o.LISTENERS,i=o.newNode,l=3;n.defineCustomEventTarget=function(e,t){function n(){e.call(this)}var o={constructor:{value:n,configurable:!0,writable:!0}};return t.forEach(function(e){o["on"+e]={get:function(){return r(this,e)},set:function(t){a(this,e,t)},configurable:!0,enumerable:!0}}),n.prototype=Object.create(e.prototype,o),n}},{"./commons":1}],3:[function(e,t,n){"use strict";var r=e("./commons"),a=e("./custom-event-target"),o=e("./event-wrapper"),u=r.LISTENERS,i=r.newNode,l=a.defineCustomEventTarget,f=o.createEventWrapper,c=o.STOP_IMMEDIATE_PROPAGATION_FLAG,s="undefined"!=typeof window&&"undefined"!=typeof window.EventTarget,p=1,v=2,d=t.exports=function b(){if(!(this instanceof b)){if(1===arguments.length&&Array.isArray(arguments[0]))return l(b,arguments[0]);if(arguments.length>0){for(var e=Array(arguments.length),t=0;t<arguments.length;++t)e[t]=arguments[t];return l(b,e)}throw new TypeError("Cannot call a class as a function")}Object.defineProperty(this,u,{value:Object.create(null)})};d.prototype=Object.create((s?window.EventTarget:Object).prototype,{constructor:{value:d,writable:!0,configurable:!0},addEventListener:{value:function(e,t,n){if(null==t)return!1;if("function"!=typeof t)throw new TypeError("listener should be a function.");var r=n?p:v,a=this[u][e];if(null==a)return this[u][e]=i(t,r),!0;for(var o=null;null!=a;){if(a.listener===t&&a.kind===r)return!1;o=a,a=a.next}return o.next=i(t,r),!0},configurable:!0,writable:!0},removeEventListener:{value:function(e,t,n){if(null==t)return!1;for(var r=n?p:v,a=null,o=this[u][e];null!=o;){if(o.listener===t&&o.kind===r)return null==a?this[u][e]=o.next:a.next=o.next,!0;a=o,o=o.next}return!1},configurable:!0,writable:!0},dispatchEvent:{value:function(e){var t=this[u][e.type];if(null==t)return!0;for(var n=f(e,this);null!=t&&(t.listener.call(this,n),!n[c]);)t=t.next;return!n.defaultPrevented},configurable:!0,writable:!0}})},{"./commons":1,"./custom-event-target":2,"./event-wrapper":4}],4:[function(e,t,n){"use strict";var r=e("./commons").createUniqueKey,a=r("stop_immediate_propagation_flag"),o=r("canceled_flag"),u=r("original_event"),i=Object.freeze({stopPropagation:Object.freeze({value:function(){var e=this[u];"function"==typeof e.stopPropagation&&e.stopPropagation()},writable:!0,configurable:!0}),stopImmediatePropagation:Object.freeze({value:function(){this[a]=!0;var e=this[u];"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation()},writable:!0,configurable:!0}),preventDefault:Object.freeze({value:function(){this.cancelable===!0&&(this[o]=!0);var e=this[u];"function"==typeof e.preventDefault&&e.preventDefault()},writable:!0,configurable:!0}),defaultPrevented:Object.freeze({get:function(){return this[o]},enumerable:!0,configurable:!0})});n.STOP_IMMEDIATE_PROPAGATION_FLAG=a,n.createEventWrapper=function(e,t){var n="number"==typeof e.timeStamp?e.timeStamp:Date.now(),r={type:{value:e.type,enumerable:!0},target:{value:t,enumerable:!0},currentTarget:{value:t,enumerable:!0},eventPhase:{value:2,enumerable:!0},bubbles:{value:Boolean(e.bubbles),enumerable:!0},cancelable:{value:Boolean(e.cancelable),enumerable:!0},timeStamp:{value:n,enumerable:!0},isTrusted:{value:!1,enumerable:!0}};return r[a]={value:!1,writable:!0},r[o]={value:!1,writable:!0},r[u]={value:e},"undefined"!=typeof e.detail&&(r.detail={value:e.detail,enumerable:!0}),Object.create(Object.create(e,i),r)}},{"./commons":1}]},{},[3])(3)});

@@ -76,2 +76,5 @@ /**

}
else if (arguments.length === 1 && Array.isArray(arguments[0])) {
return defineCustomEventTarget(EventTarget, arguments[0]);
}
else if (arguments.length > 0) {

@@ -78,0 +81,0 @@ var types = Array(arguments.length);

{
"name": "event-target-shim",
"version": "1.0.7",
"version": "1.1.0",
"description": "An implementation of W3C EventTarget interface.",

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

@@ -21,2 +21,4 @@ # event-target-shim

Or download from `dist` directory.
## Usage

@@ -27,5 +29,7 @@

```js
// import.
//-----------------------------------------------------------------------------
// import (with browserify, webpack, etc...).
const EventTarget = require("event-target-shim");
//-----------------------------------------------------------------------------
// define a custom type.

@@ -35,2 +39,3 @@ class Foo extends EventTarget {

//-----------------------------------------------------------------------------
// add event listeners.

@@ -48,2 +53,3 @@ let foo = new Foo();

//-----------------------------------------------------------------------------
// dispatch an event.

@@ -55,5 +61,7 @@ let event = document.createEvent("CustomEvent");

//-----------------------------------------------------------------------------
// dispatch an event simply (non standard).
foo.dispatchEvent({type: "foo", hello: "hello"});
//-----------------------------------------------------------------------------
// dispatch a cancelable event.

@@ -68,9 +76,15 @@ if (!foo.dispatchEvent({type: "foo", cancelable: true, hello: "hey"})) {

```js
// import.
//-----------------------------------------------------------------------------
// import (with browserify, webpack, etc...).
const EventTarget = require("event-target-shim");
// define a custom type.
//-----------------------------------------------------------------------------
// define a custom type with attribute listeners.
class Foo extends EventTarget("message", "error") {
}
// or non-variadic
class Foo extends EventTarget(["message", "error"]) {
}
//-----------------------------------------------------------------------------
// add event listeners.

@@ -88,2 +102,3 @@ let foo = new Foo();

//-----------------------------------------------------------------------------
// dispatch a event simply (non standard).

@@ -94,2 +109,50 @@ foo.dispatchEvent({type: "message", data: "hello"});

### Use in ES5
- Basic.
```js
function Foo() {
EventTarget.call(this);
}
Foo.prototype = Object.create(EventTarget.prototype, {
constructor: {
value: Foo,
configurable: true,
writable: true
},
//....
});
```
- With attribute listeners.
```js
function Foo() {
EventTarget.call(this);
}
Foo.prototype = Object.create(EventTarget("message", "error").prototype, {
// or
// Foo.prototype = Object.create(EventTarget(["message", "error"]).prototype, {
constructor: {
value: Foo,
configurable: true,
writable: true
},
//....
});
```
### Use with RequireJS
```js
require(["./node_modules/event-target-shim/dist/event-target-shim.min.js"], function(EventTarget) {
//...
});
```
## API

@@ -102,3 +165,3 @@

removeEventListener(type: string, listener?: (event: Event) => void, capture: boolean = false): void;
dispatchEvent(event: Event | {type: string, babbles?: boolean, cancelable?: boolean}): void;
dispatchEvent(event: Event | {type: string, cancelable?: boolean}): void;
}

@@ -105,0 +168,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc