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 3.0.2 to 4.0.0

index.d.ts

242

dist/event-target-shim.js

@@ -17,3 +17,4 @@ /**

* @property {boolean} canceled The flag to prevent default.
* @property {boolean} stopped The flag to stop propagation immediately.
* @property {boolean} stopped The flag to stop propagation.
* @property {boolean} immediateStopped The flag to stop propagation immediately.
* @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.

@@ -46,3 +47,7 @@ * @property {number} timeStamp The unix time.

const retv = privateData.get(event);
console.assert(retv != null, "'this' is expected an Event object, but got", event);
console.assert(
retv != null,
"'this' is expected an Event object, but got",
event,
);
return retv

@@ -52,2 +57,29 @@ }

/**
* https://dom.spec.whatwg.org/#set-the-canceled-flag
* @param data {PrivateData} private data.
*/
function setCancelFlag(data) {
if (data.passiveListener != null) {
if (
typeof console !== "undefined" &&
typeof console.error === "function"
) {
console.error(
"Unable to preventDefault inside passive event listener invocation.",
data.passiveListener,
);
}
return
}
if (!data.event.cancelable) {
return
}
data.canceled = true;
if (typeof data.event.preventDefault === "function") {
data.event.preventDefault();
}
}
/**
* @see https://dom.spec.whatwg.org/#interface-event

@@ -70,2 +102,3 @@ * @private

stopped: false,
immediateStopped: false,
passiveListener: null,

@@ -171,2 +204,4 @@ timeStamp: event.timeStamp || Date.now(),

const data = pd(this);
data.stopped = true;
if (typeof data.event.stopPropagation === "function") {

@@ -185,2 +220,3 @@ data.event.stopPropagation();

data.stopped = true;
data.immediateStopped = true;
if (typeof data.event.stopImmediatePropagation === "function") {

@@ -212,15 +248,3 @@ data.event.stopImmediatePropagation();

preventDefault() {
const data = pd(this);
if (data.passiveListener != null) {
console.warn("Event#preventDefault() was called from a passive listener:", data.passiveListener);
return
}
if (!data.event.cancelable) {
return
}
data.canceled = true;
if (typeof data.event.preventDefault === "function") {
data.event.preventDefault();
}
setCancelFlag(pd(this));
},

@@ -251,6 +275,64 @@

},
/**
* The target of this event.
* @type {EventTarget}
* @deprecated
*/
get srcElement() {
return pd(this).eventTarget
},
/**
* The flag to stop event bubbling.
* @type {boolean}
* @deprecated
*/
get cancelBubble() {
return pd(this).stopped
},
set cancelBubble(value) {
if (!value) {
return
}
const data = pd(this);
data.stopped = true;
if (typeof data.event.cancelBubble === "boolean") {
data.event.cancelBubble = true;
}
},
/**
* The flag to indicate cancellation state.
* @type {boolean}
* @deprecated
*/
get returnValue() {
return !pd(this).canceled
},
set returnValue(value) {
if (!value) {
setCancelFlag(pd(this));
}
},
/**
* Initialize this event object. But do nothing under event dispatching.
* @param {string} type The event type.
* @param {boolean} [bubbles=false] The flag to be possible to bubble up.
* @param {boolean} [cancelable=false] The flag to be possible to cancel.
* @deprecated
*/
initEvent() {
// Do nothing.
},
};
// `constructor` is not enumerable.
Object.defineProperty(Event.prototype, "constructor", { value: Event, configurable: true, writable: true });
Object.defineProperty(Event.prototype, "constructor", {
value: Event,
configurable: true,
writable: true,
});

@@ -328,7 +410,9 @@ // Ensure `event instanceof window.Event` is `true`.

const descriptor = Object.getOwnPropertyDescriptor(proto, key);
const isFunc = (typeof descriptor.value === "function");
const isFunc = typeof descriptor.value === "function";
Object.defineProperty(
CustomEvent.prototype,
key,
isFunc ? defineCallDescriptor(key) : defineRedirectDescriptor(key)
isFunc
? defineCallDescriptor(key)
: defineRedirectDescriptor(key),
);

@@ -373,3 +457,3 @@ }

/**
* Get the stopped flag of a given event.
* Get the immediateStopped flag of a given event.
* @param {Event} event The event to get.

@@ -380,3 +464,3 @@ * @returns {boolean} The flag to stop propagation immediately.

function isStopped(event) {
return pd(event).stopped
return pd(event).immediateStopped
}

@@ -456,3 +540,5 @@

if (listeners == null) {
throw new TypeError("'this' is expected an EventTarget object, but got another value.")
throw new TypeError(
"'this' is expected an EventTarget object, but got another value.",
)
}

@@ -496,11 +582,8 @@ return listeners

prev.next = node.next;
}
else if (node.next !== null) {
} else if (node.next !== null) {
listeners.set(eventName, node.next);
}
else {
} else {
listeners.delete(eventName);
}
}
else {
} else {
prev = node;

@@ -523,4 +606,3 @@ }

listeners.set(eventName, newNode);
}
else {
} else {
prev.next = newNode;

@@ -542,3 +624,7 @@ }

function defineEventAttribute(eventTargetPrototype, eventName) {
Object.defineProperty(eventTargetPrototype, `on${eventName}`, defineEventAttributeDescriptor(eventName));
Object.defineProperty(
eventTargetPrototype,
`on${eventName}`,
defineEventAttributeDescriptor(eventName),
);
}

@@ -559,3 +645,7 @@

CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
constructor: { value: CustomEventTarget, configurable: true, writable: true },
constructor: {
value: CustomEventTarget,
configurable: true,
writable: true,
},
});

@@ -610,7 +700,7 @@

* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
* @returns {boolean} `true` if the listener was added actually.
* @returns {void}
*/
addEventListener(eventName, listener, options) {
if (listener == null) {
return false
return
}

@@ -623,4 +713,6 @@ if (typeof listener !== "function" && !isObject(listener)) {

const optionsIsObj = isObject(options);
const capture = optionsIsObj ? Boolean(options.capture) : Boolean(options);
const listenerType = (capture ? CAPTURE : BUBBLE);
const capture = optionsIsObj
? Boolean(options.capture)
: Boolean(options);
const listenerType = capture ? CAPTURE : BUBBLE;
const newNode = {

@@ -638,3 +730,3 @@ listener,

listeners.set(eventName, newNode);
return true
return
}

@@ -645,5 +737,8 @@

while (node != null) {
if (node.listener === listener && node.listenerType === listenerType) {
if (
node.listener === listener &&
node.listenerType === listenerType
) {
// Should ignore duplication.
return false
return
}

@@ -656,3 +751,2 @@ prev = node;

prev.next = newNode;
return true
},

@@ -665,12 +759,14 @@

* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
* @returns {boolean} `true` if the listener was removed actually.
* @returns {void}
*/
removeEventListener(eventName, listener, options) {
if (listener == null) {
return false
return
}
const listeners = getListeners(this);
const capture = isObject(options) ? Boolean(options.capture) : Boolean(options);
const listenerType = (capture ? CAPTURE : BUBBLE);
const capture = isObject(options)
? Boolean(options.capture)
: Boolean(options);
const listenerType = capture ? CAPTURE : BUBBLE;

@@ -680,13 +776,14 @@ let prev = null;

while (node != null) {
if (node.listener === listener && node.listenerType === listenerType) {
if (
node.listener === listener &&
node.listenerType === listenerType
) {
if (prev !== null) {
prev.next = node.next;
}
else if (node.next !== null) {
} else if (node.next !== null) {
listeners.set(eventName, node.next);
}
else {
} else {
listeners.delete(eventName);
}
return true
return
}

@@ -697,4 +794,2 @@

}
return false
},

@@ -707,5 +802,5 @@

*/
dispatchEvent(event) { //eslint-disable-line complexity
dispatchEvent(event) {
if (event == null || typeof event.type !== "string") {
throw new TypeError("\"event.type\" should be a string.")
throw new TypeError('"event.type" should be a string.')
}

@@ -732,11 +827,8 @@

prev.next = node.next;
}
else if (node.next !== null) {
} else if (node.next !== null) {
listeners.set(eventName, node.next);
}
else {
} else {
listeners.delete(eventName);
}
}
else {
} else {
prev = node;

@@ -746,16 +838,21 @@ }

// Call this listener
setPassiveListener(wrappedEvent, (node.passive ? node.listener : null));
setPassiveListener(
wrappedEvent,
node.passive ? node.listener : null,
);
if (typeof node.listener === "function") {
try {
node.listener.call(this, wrappedEvent);
}
catch (err) {
/*eslint-disable no-console */
if (typeof console !== "undefined" && typeof console.error === "function") {
} catch (err) {
if (
typeof console !== "undefined" &&
typeof console.error === "function"
) {
console.error(err);
}
/*eslint-enable no-console */
}
}
else if (node.listenerType !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
} else if (
node.listenerType !== ATTRIBUTE &&
typeof node.listener.handleEvent === "function"
) {
node.listener.handleEvent(wrappedEvent);

@@ -780,6 +877,13 @@ }

// `constructor` is not enumerable.
Object.defineProperty(EventTarget.prototype, "constructor", { value: EventTarget, configurable: true, writable: true });
Object.defineProperty(EventTarget.prototype, "constructor", {
value: EventTarget,
configurable: true,
writable: true,
});
// Ensure `eventTarget instanceof window.EventTarget` is `true`.
if (typeof window !== "undefined" && typeof window.EventTarget !== "undefined") {
if (
typeof window !== "undefined" &&
typeof window.EventTarget !== "undefined"
) {
Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);

@@ -786,0 +890,0 @@ }

@@ -5,3 +5,3 @@ /**

* See LICENSE file in root directory for full license.
*/(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.EventTargetShim={})})(this,function(a){'use strict';function b(a){var b=s.get(a);return console.assert(null!=b,'\'this\' is expected an Event object, but got',a),b}function c(a,b){s.set(this,{eventTarget:a,event:b,eventPhase:2,currentTarget:a,canceled:!1,stopped:!1,passiveListener:null,timeStamp:b.timeStamp||Date.now()}),Object.defineProperty(this,'isTrusted',{value:!1,enumerable:!0});for(var c,e=Object.keys(b),f=0;f<e.length;++f)c=e[f],c in this||Object.defineProperty(this,c,d(c))}function d(a){return{get:function(){return b(this).event[a]},set:function(c){b(this).event[a]=c},configurable:!0,enumerable:!0}}function e(a){return{value:function(){var c=b(this).event;return c[a].apply(c,arguments)},configurable:!0,enumerable:!0}}function f(a,b){function c(b,c){a.call(this,b,c)}var f=Object.keys(b);if(0===f.length)return a;c.prototype=Object.create(a.prototype,{constructor:{value:c,configurable:!0,writable:!0}});for(var g,h=0;h<f.length;++h)if(g=f[h],!(g in a.prototype)){var j=Object.getOwnPropertyDescriptor(b,g),k='function'==typeof j.value;Object.defineProperty(c.prototype,g,k?e(g):d(g))}return c}function g(a){if(null==a||a===Object.prototype)return c;var b=t.get(a);return null==b&&(b=f(g(Object.getPrototypeOf(a)),a),t.set(a,b)),b}function h(a,b){var c=g(Object.getPrototypeOf(b));return new c(a,b)}function i(a){return b(a).stopped}function j(a,c){b(a).eventPhase=c}function k(a,c){b(a).currentTarget=c}function l(a,c){b(a).passiveListener=c}function m(a){return null!==a&&'object'===('undefined'==typeof a?'undefined':u(a))}function n(a){var b=v.get(a);if(null==b)throw new TypeError('\'this\' is expected an EventTarget object, but got another value.');return b}function o(a){return{get:function(){for(var b=n(this),c=b.get(a);null!=c;){if(3===c.listenerType)return c.listener;c=c.next}return null},set:function(b){'function'==typeof b||m(b)||(b=null);for(var c=n(this),d=null,e=c.get(a);null!=e;)3===e.listenerType?null===d?null===e.next?c.delete(a):c.set(a,e.next):d.next=e.next:d=e,e=e.next;if(null!==b){var f={listener:b,listenerType:3,passive:!1,once:!1,next:null};null===d?c.set(a,f):d.next=f}},configurable:!0,enumerable:!0}}function p(a,b){Object.defineProperty(a,'on'+b,o(b))}function q(a){function b(){r.call(this)}b.prototype=Object.create(r.prototype,{constructor:{value:b,configurable:!0,writable:!0}});for(var c=0;c<a.length;++c)p(b.prototype,a[c]);return b}function r(){if(this instanceof r)return void v.set(this,new Map);if(1===arguments.length&&Array.isArray(arguments[0]))return q(arguments[0]);if(0<arguments.length){for(var a=Array(arguments.length),b=0;b<arguments.length;++b)a[b]=arguments[b];return q(a)}throw new TypeError('Cannot call a class as a function')}var s=new WeakMap,t=new WeakMap;c.prototype={get type(){return b(this).event.type},get target(){return b(this).eventTarget},get currentTarget(){return b(this).currentTarget},composedPath:function(){var a=b(this).currentTarget;return null==a?[]:[a]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return b(this).eventPhase},stopPropagation:function(){var a=b(this);'function'==typeof a.event.stopPropagation&&a.event.stopPropagation()},stopImmediatePropagation:function(){var a=b(this);a.stopped=!0,'function'==typeof a.event.stopImmediatePropagation&&a.event.stopImmediatePropagation()},get bubbles(){return!!b(this).event.bubbles},get cancelable(){return!!b(this).event.cancelable},preventDefault:function(){var a=b(this);return null==a.passiveListener?void(!a.event.cancelable||(a.canceled=!0,'function'==typeof a.event.preventDefault&&a.event.preventDefault())):void console.warn('Event#preventDefault() was called from a passive listener:',a.passiveListener)},get defaultPrevented(){return b(this).canceled},get composed(){return!!b(this).event.composed},get timeStamp(){return b(this).timeStamp}},Object.defineProperty(c.prototype,'constructor',{value:c,configurable:!0,writable:!0}),'undefined'!=typeof window&&'undefined'!=typeof window.Event&&(Object.setPrototypeOf(c.prototype,window.Event.prototype),t.set(window.Event.prototype,c));var u='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},v=new WeakMap;if(r.prototype={addEventListener:function(a,b,c){if(null==b)return!1;if('function'!=typeof b&&!m(b))throw new TypeError('\'listener\' should be a function or an object.');var d=n(this),e=m(c),f=e?!!c.capture:!!c,g=f?1:2,h={listener:b,listenerType:g,passive:e&&!!c.passive,once:e&&!!c.once,next:null},i=d.get(a);if(void 0===i)return d.set(a,h),!0;for(var j=null;null!=i;){if(i.listener===b&&i.listenerType===g)return!1;j=i,i=i.next}return j.next=h,!0},removeEventListener:function(a,b,c){if(null==b)return!1;for(var d=n(this),e=m(c)?!!c.capture:!!c,f=e?1:2,g=null,h=d.get(a);null!=h;){if(h.listener===b&&h.listenerType===f)return null===g?null===h.next?d.delete(a):d.set(a,h.next):g.next=h.next,!0;g=h,h=h.next}return!1},dispatchEvent:function(a){if(null==a||'string'!=typeof a.type)throw new TypeError('"event.type" should be a string.');var b=n(this),c=a.type,d=b.get(c);if(null==d)return!0;for(var e=h(this,a),f=null;null!=d;){if(d.once?null===f?null===d.next?b.delete(c):b.set(c,d.next):f.next=d.next:f=d,l(e,d.passive?d.listener:null),'function'==typeof d.listener)try{d.listener.call(this,e)}catch(a){'undefined'!=typeof console&&'function'==typeof console.error&&console.error(a)}else 3!==d.listenerType&&'function'==typeof d.listener.handleEvent&&d.listener.handleEvent(e);if(i(e))break;d=d.next}return l(e,null),j(e,0),k(e,null),!e.defaultPrevented}},Object.defineProperty(r.prototype,'constructor',{value:r,configurable:!0,writable:!0}),'undefined'!=typeof window&&'undefined'!=typeof window.EventTarget&&Object.setPrototypeOf(r.prototype,window.EventTarget.prototype),a.defineEventAttribute=p,a.EventTarget=r,a.default=r,Object.defineProperty(a,'__esModule',{value:!0}),'undefined'==typeof module&&'undefined'==typeof define){const a=Function('return this')();a.EventTargetShim=r,a.EventTargetShim.defineEventAttribute=p}});
*/(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a.EventTargetShim={})})(this,function(a){"use strict";function b(a){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},b(a)}function c(a){var b=u.get(a);return console.assert(null!=b,"'this' is expected an Event object, but got",a),b}function d(a){return null==a.passiveListener?void(!a.event.cancelable||(a.canceled=!0,"function"==typeof a.event.preventDefault&&a.event.preventDefault())):void("undefined"!=typeof console&&"function"==typeof console.error&&console.error("Unable to preventDefault inside passive event listener invocation.",a.passiveListener))}function e(a,b){u.set(this,{eventTarget:a,event:b,eventPhase:2,currentTarget:a,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:b.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});for(var c,d=Object.keys(b),e=0;e<d.length;++e)c=d[e],c in this||Object.defineProperty(this,c,f(c))}function f(a){return{get:function(){return c(this).event[a]},set:function(b){c(this).event[a]=b},configurable:!0,enumerable:!0}}function g(a){return{value:function(){var b=c(this).event;return b[a].apply(b,arguments)},configurable:!0,enumerable:!0}}function h(a,b){function c(b,c){a.call(this,b,c)}var d=Object.keys(b);if(0===d.length)return a;c.prototype=Object.create(a.prototype,{constructor:{value:c,configurable:!0,writable:!0}});for(var e,h=0;h<d.length;++h)if(e=d[h],!(e in a.prototype)){var j=Object.getOwnPropertyDescriptor(b,e),k="function"==typeof j.value;Object.defineProperty(c.prototype,e,k?g(e):f(e))}return c}function i(a){if(null==a||a===Object.prototype)return e;var b=v.get(a);return null==b&&(b=h(i(Object.getPrototypeOf(a)),a),v.set(a,b)),b}function j(a,b){var c=i(Object.getPrototypeOf(b));return new c(a,b)}function k(a){return c(a).immediateStopped}function l(a,b){c(a).eventPhase=b}function m(a,b){c(a).currentTarget=b}function n(a,b){c(a).passiveListener=b}function o(a){return null!==a&&"object"===b(a)}function p(a){var b=w.get(a);if(null==b)throw new TypeError("'this' is expected an EventTarget object, but got another value.");return b}function q(a){return{get:function(){for(var b=p(this),c=b.get(a);null!=c;){if(3===c.listenerType)return c.listener;c=c.next}return null},set:function(b){"function"==typeof b||o(b)||(b=null);for(var c=p(this),d=null,e=c.get(a);null!=e;)3===e.listenerType?null===d?null===e.next?c.delete(a):c.set(a,e.next):d.next=e.next:d=e,e=e.next;if(null!==b){var f={listener:b,listenerType:3,passive:!1,once:!1,next:null};null===d?c.set(a,f):d.next=f}},configurable:!0,enumerable:!0}}function r(a,b){Object.defineProperty(a,"on".concat(b),q(b))}function s(a){function b(){t.call(this)}b.prototype=Object.create(t.prototype,{constructor:{value:b,configurable:!0,writable:!0}});for(var c=0;c<a.length;++c)r(b.prototype,a[c]);return b}function t(){if(this instanceof t)return void w.set(this,new Map);if(1===arguments.length&&Array.isArray(arguments[0]))return s(arguments[0]);if(0<arguments.length){for(var a=Array(arguments.length),b=0;b<arguments.length;++b)a[b]=arguments[b];return s(a)}throw new TypeError("Cannot call a class as a function")}var u=new WeakMap,v=new WeakMap;e.prototype={get type(){return c(this).event.type},get target(){return c(this).eventTarget},get currentTarget(){return c(this).currentTarget},composedPath:function(){var a=c(this).currentTarget;return null==a?[]:[a]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return c(this).eventPhase},stopPropagation:function(){var a=c(this);a.stopped=!0,"function"==typeof a.event.stopPropagation&&a.event.stopPropagation()},stopImmediatePropagation:function(){var a=c(this);a.stopped=!0,a.immediateStopped=!0,"function"==typeof a.event.stopImmediatePropagation&&a.event.stopImmediatePropagation()},get bubbles(){return!!c(this).event.bubbles},get cancelable(){return!!c(this).event.cancelable},preventDefault:function(){d(c(this))},get defaultPrevented(){return c(this).canceled},get composed(){return!!c(this).event.composed},get timeStamp(){return c(this).timeStamp},get srcElement(){return c(this).eventTarget},get cancelBubble(){return c(this).stopped},set cancelBubble(a){if(a){var b=c(this);b.stopped=!0,"boolean"==typeof b.event.cancelBubble&&(b.event.cancelBubble=!0)}},get returnValue(){return!c(this).canceled},set returnValue(a){a||d(c(this))},initEvent:function(){}},Object.defineProperty(e.prototype,"constructor",{value:e,configurable:!0,writable:!0}),"undefined"!=typeof window&&"undefined"!=typeof window.Event&&(Object.setPrototypeOf(e.prototype,window.Event.prototype),v.set(window.Event.prototype,e));var w=new WeakMap,x=1,y=2;if(t.prototype={addEventListener:function(a,b,c){if(null!=b){if("function"!=typeof b&&!o(b))throw new TypeError("'listener' should be a function or an object.");var d=p(this),e=o(c),f=e?!!c.capture:!!c,g=f?x:y,h={listener:b,listenerType:g,passive:e&&!!c.passive,once:e&&!!c.once,next:null},i=d.get(a);if(void 0===i)return void d.set(a,h);for(var j=null;null!=i;){if(i.listener===b&&i.listenerType===g)return;j=i,i=i.next}j.next=h}},removeEventListener:function(a,b,c){if(null!=b)for(var d=p(this),e=o(c)?!!c.capture:!!c,f=e?x:y,g=null,h=d.get(a);null!=h;){if(h.listener===b&&h.listenerType===f)return void(null===g?null===h.next?d.delete(a):d.set(a,h.next):g.next=h.next);g=h,h=h.next}},dispatchEvent:function(a){if(null==a||"string"!=typeof a.type)throw new TypeError("\"event.type\" should be a string.");var b=p(this),c=a.type,d=b.get(c);if(null==d)return!0;for(var e=j(this,a),f=null;null!=d;){if(d.once?null===f?null===d.next?b.delete(c):b.set(c,d.next):f.next=d.next:f=d,n(e,d.passive?d.listener:null),"function"==typeof d.listener)try{d.listener.call(this,e)}catch(a){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(a)}else d.listenerType!==3&&"function"==typeof d.listener.handleEvent&&d.listener.handleEvent(e);if(k(e))break;d=d.next}return n(e,null),l(e,0),m(e,null),!e.defaultPrevented}},Object.defineProperty(t.prototype,"constructor",{value:t,configurable:!0,writable:!0}),"undefined"!=typeof window&&"undefined"!=typeof window.EventTarget&&Object.setPrototypeOf(t.prototype,window.EventTarget.prototype),a.defineEventAttribute=r,a.EventTarget=t,a.default=t,Object.defineProperty(a,"__esModule",{value:!0}),"undefined"==typeof module&&"undefined"==typeof define){const a=Function("return this")();a.EventTargetShim=t,a.EventTargetShim.defineEventAttribute=r}});
//# sourceMappingURL=event-target-shim.umd.js.map
{
"name": "event-target-shim",
"version": "3.0.2",
"version": "4.0.0",
"description": "An implementation of WHATWG EventTarget interface.",
"main": "dist/event-target-shim",
"types": "index.d.ts",
"files": [
"dist"
"dist",
"index.d.ts"
],
"engines": {
"node": ">=4"
"node": ">=6"
},

@@ -24,4 +26,5 @@ "scripts": {

"test:karma": "karma start scripts/karma.conf.js --single-run",
"test:types": "tsc",
"watch": "run-p watch:*",
"watch:mocha": "mocha test/index.mjs --compilers mjs:babel-register --watch --growl",
"watch:mocha": "mocha test/index.mjs --require ./scripts/babel-register.js --watch --watch-extensions js,mjs --growl",
"watch:karma": "karma start scripts/karma.conf.js --watch",

@@ -31,10 +34,11 @@ "codecov": "codecov"

"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"codecov": "^3.0.2",
"eslint": "^4.7.2",
"eslint-config-mysticatea": "^13.0.0",
"karma": "^2.0.4",
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@babel/register": "^7.0.0",
"@mysticatea/eslint-plugin": "^7.0.0",
"@mysticatea/spy": "^0.1.2",
"assert": "^1.4.1",
"codecov": "^3.1.0",
"eslint": "^5.9.0",
"karma": "^3.1.1",
"karma-chrome-launcher": "^2.2.0",

@@ -46,16 +50,16 @@ "karma-coverage": "^1.1.2",

"karma-mocha": "^1.3.0",
"karma-rollup-preprocessor": "^6.0.0",
"karma-rollup-preprocessor": "^6.1.1",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3",
"nyc": "^12.0.2",
"opener": "^1.4.3",
"npm-run-all": "^4.1.5",
"nyc": "^13.1.0",
"opener": "^1.5.1",
"rimraf": "^2.6.2",
"rollup": "^0.61.2",
"rollup-plugin-babel": "^3.0.5",
"rollup-plugin-babel-minify": "^5.0.0",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup": "^0.66.6",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-babel-minify": "^6.2.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-watch": "^4.3.1",
"spy": "^1.0.0"
"typescript": "~3.2.1"
},

@@ -62,0 +66,0 @@ "repository": {

@@ -152,2 +152,55 @@ # event-target-shim

### Typescript
Currently typescript does not support type mutation by method, therefore the previous example will **not work** without the following modifications:
#### Working example #1
```ts
import { EventTarget, defineEventAttribute } from "event-target-shim";
// Define a derived class.
class Foo extends EventTarget<"onhello"> {
// ...
}
// Define `foo.onhello` property.
defineEventAttribute(Foo.prototype, "hello")
// Register event listeners.
const foo = new Foo()
foo.addEventListener("hello", (e) => {
console.log("hello", e)
})
foo.onhello = (e) => {
console.log("onhello", e)
}
// Dispatching events
foo.dispatchEvent(new CustomEvent("hello", { detail: "detail" }))
```
In the future, if typescript adds support to string literal mutation (joining, slicing and etc.), it should be possible to automatically infer `onhello` type from `hello`. However, until then you are stuck with this:
#### Working example #2
```ts
import { EventTarget, defineEventAttribute } from "event-target-shim";
// Define a derived class.
class Foo extends EventTarget<"onhello">("hello") {
// ...
}
// Register event listeners.
const foo = new Foo()
foo.addEventListener("hello", (e) => {
console.log("hello", e)
})
foo.onhello = (e) => {
console.log("onhello", e)
}
// Dispatching events
foo.dispatchEvent(new CustomEvent("hello", { detail: "detail" }))
```
### ES5

@@ -154,0 +207,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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