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

event-target-shim

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-target-shim - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

75

dist/event-target-shim.js

@@ -32,2 +32,26 @@ (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){

/**
* A value of kind for listeners which are registered in the capturing phase.
*
* @type {number}
* @private
*/
exports.CAPTURE = 1;
/**
* A value of kind for listeners which are registered in the bubbling phase.
*
* @type {number}
* @private
*/
exports.BUBBLE = 2;
/**
* A value of kind for listeners which are registered as an attribute.
*
* @type {number}
* @private
*/
exports.ATTRIBUTE = 3;
/**
* @typedef object ListenerNode

@@ -66,17 +90,6 @@ * @property {function} listener - A listener function.

var LISTENERS = Commons.LISTENERS;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
/**
* A value of kind for listeners which are registered as an attribute.
*
* @type {number}
* @private
*/
var ATTRIBUTE = 3;
//-----------------------------------------------------------------------------
// Helpers

@@ -112,4 +125,4 @@ //-----------------------------------------------------------------------------

function setAttributeListener(eventTarget, type, listener) {
if (listener != null && typeof listener !== "function") {
throw new TypeError("listener should be a function.");
if (typeof listener !== "function" && typeof listener !== "object") {
listener = null; // eslint-disable-line no-param-reassign
}

@@ -202,6 +215,10 @@

var LISTENERS = Commons.LISTENERS;
var CAPTURE = Commons.CAPTURE;
var BUBBLE = Commons.BUBBLE;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
var defineCustomEventTarget = CustomEventTarget.defineCustomEventTarget;
var createEventWrapper = EventWrapper.createEventWrapper;
var STOP_IMMEDIATE_PROPAGATION_FLAG = EventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;
var STOP_IMMEDIATE_PROPAGATION_FLAG =
EventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;

@@ -223,18 +240,2 @@ //-----------------------------------------------------------------------------

/**
* A value of kind for listeners which are registered in the capturing phase.
*
* @type {number}
* @private
*/
var CAPTURE = 1;
/**
* A value of kind for listeners which are registered in the bubbling phase.
*
* @type {number}
* @private
*/
var BUBBLE = 2;
//-----------------------------------------------------------------------------

@@ -298,4 +299,4 @@ // Public Interface

}
if (typeof listener !== "function") {
throw new TypeError("listener should be a function.");
if (typeof listener !== "function" && typeof listener !== "object") {
throw new TypeError("\"listener\" is not an object.");
}

@@ -371,3 +372,9 @@

while (node != null) {
node.listener.call(this, wrapped);
if (typeof node.listener === "function") {
node.listener.call(this, wrapped);
}
else if (node.kind !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
node.listener.handleEvent(wrapped);
}
if (wrapped[STOP_IMMEDIATE_PROPAGATION_FLAG]) {

@@ -374,0 +381,0 @@ break;

@@ -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 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)});
!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(i,u){if(!n[i]){if(!t[i]){var l="function"==typeof require&&require;if(!u&&l)return l(i,!0);if(a)return a(i,!0);var f=new Error("Cannot find module '"+i+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[i]={exports:{}};t[i][0].call(c.exports,function(e){var n=t[i][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);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.CAPTURE=1,n.BUBBLE=2,n.ATTRIBUTE=3,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[i][t];null!=n;){if(n.kind===u)return n.listener;n=n.next}return null}function o(e,t,n){"function"!=typeof n&&"object"!=typeof n&&(n=null);for(var r=null,o=e[i][t];null!=o;)o.kind===u?null==r?e[i][t]=o.next:r.next=o.next:r=o,o=o.next;null!=n&&(null==r?e[i][t]=l(n,u):r.next=l(n,u))}var a=e("./commons"),i=a.LISTENERS,u=a.ATTRIBUTE,l=a.newNode;n.defineCustomEventTarget=function(e,t){function n(){e.call(this)}var a={constructor:{value:n,configurable:!0,writable:!0}};return t.forEach(function(e){a["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,a),n}},{"./commons":1}],3:[function(e,t,n){"use strict";var r=e("./commons"),o=e("./custom-event-target"),a=e("./event-wrapper"),i=r.LISTENERS,u=r.CAPTURE,l=r.BUBBLE,f=r.ATTRIBUTE,c=r.newNode,s=o.defineCustomEventTarget,p=a.createEventWrapper,v=a.STOP_IMMEDIATE_PROPAGATION_FLAG,d="undefined"!=typeof window&&"undefined"!=typeof window.EventTarget,b=t.exports=function m(){if(!(this instanceof m)){if(1===arguments.length&&Array.isArray(arguments[0]))return s(m,arguments[0]);if(arguments.length>0){for(var e=Array(arguments.length),t=0;t<arguments.length;++t)e[t]=arguments[t];return s(m,e)}throw new TypeError("Cannot call a class as a function")}Object.defineProperty(this,i,{value:Object.create(null)})};b.prototype=Object.create((d?window.EventTarget:Object).prototype,{constructor:{value:b,writable:!0,configurable:!0},addEventListener:{value:function(e,t,n){if(null==t)return!1;if("function"!=typeof t&&"object"!=typeof t)throw new TypeError('"listener" is not an object.');var r=n?u:l,o=this[i][e];if(null==o)return this[i][e]=c(t,r),!0;for(var a=null;null!=o;){if(o.listener===t&&o.kind===r)return!1;a=o,o=o.next}return a.next=c(t,r),!0},configurable:!0,writable:!0},removeEventListener:{value:function(e,t,n){if(null==t)return!1;for(var r=n?u:l,o=null,a=this[i][e];null!=a;){if(a.listener===t&&a.kind===r)return null==o?this[i][e]=a.next:o.next=a.next,!0;o=a,a=a.next}return!1},configurable:!0,writable:!0},dispatchEvent:{value:function(e){var t=this[i][e.type];if(null==t)return!0;for(var n=p(e,this);null!=t&&("function"==typeof t.listener?t.listener.call(this,n):t.kind!==f&&"function"==typeof t.listener.handleEvent&&t.listener.handleEvent(n),!n[v]);)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"),a=r("canceled_flag"),i=r("original_event"),u=Object.freeze({stopPropagation:Object.freeze({value:function(){var e=this[i];"function"==typeof e.stopPropagation&&e.stopPropagation()},writable:!0,configurable:!0}),stopImmediatePropagation:Object.freeze({value:function(){this[o]=!0;var e=this[i];"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation()},writable:!0,configurable:!0}),preventDefault:Object.freeze({value:function(){this.cancelable===!0&&(this[a]=!0);var e=this[i];"function"==typeof e.preventDefault&&e.preventDefault()},writable:!0,configurable:!0}),defaultPrevented:Object.freeze({get:function(){return this[a]},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[a]={value:!1,writable:!0},r[i]={value:e},"undefined"!=typeof e.detail&&(r.detail={value:e.detail,enumerable:!0}),Object.create(Object.create(e,u),r)}},{"./commons":1}]},{},[3])(3)});

@@ -31,2 +31,26 @@ /**

/**
* A value of kind for listeners which are registered in the capturing phase.
*
* @type {number}
* @private
*/
exports.CAPTURE = 1;
/**
* A value of kind for listeners which are registered in the bubbling phase.
*
* @type {number}
* @private
*/
exports.BUBBLE = 2;
/**
* A value of kind for listeners which are registered as an attribute.
*
* @type {number}
* @private
*/
exports.ATTRIBUTE = 3;
/**
* @typedef object ListenerNode

@@ -33,0 +57,0 @@ * @property {function} listener - A listener function.

@@ -15,17 +15,6 @@ /**

var LISTENERS = Commons.LISTENERS;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
/**
* A value of kind for listeners which are registered as an attribute.
*
* @type {number}
* @private
*/
var ATTRIBUTE = 3;
//-----------------------------------------------------------------------------
// Helpers

@@ -61,4 +50,4 @@ //-----------------------------------------------------------------------------

function setAttributeListener(eventTarget, type, listener) {
if (listener != null && typeof listener !== "function") {
throw new TypeError("listener should be a function.");
if (typeof listener !== "function" && typeof listener !== "object") {
listener = null; // eslint-disable-line no-param-reassign
}

@@ -65,0 +54,0 @@

@@ -17,6 +17,10 @@ /**

var LISTENERS = Commons.LISTENERS;
var CAPTURE = Commons.CAPTURE;
var BUBBLE = Commons.BUBBLE;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
var defineCustomEventTarget = CustomEventTarget.defineCustomEventTarget;
var createEventWrapper = EventWrapper.createEventWrapper;
var STOP_IMMEDIATE_PROPAGATION_FLAG = EventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;
var STOP_IMMEDIATE_PROPAGATION_FLAG =
EventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;

@@ -38,18 +42,2 @@ //-----------------------------------------------------------------------------

/**
* A value of kind for listeners which are registered in the capturing phase.
*
* @type {number}
* @private
*/
var CAPTURE = 1;
/**
* A value of kind for listeners which are registered in the bubbling phase.
*
* @type {number}
* @private
*/
var BUBBLE = 2;
//-----------------------------------------------------------------------------

@@ -113,4 +101,4 @@ // Public Interface

}
if (typeof listener !== "function") {
throw new TypeError("listener should be a function.");
if (typeof listener !== "function" && typeof listener !== "object") {
throw new TypeError("\"listener\" is not an object.");
}

@@ -186,3 +174,9 @@

while (node != null) {
node.listener.call(this, wrapped);
if (typeof node.listener === "function") {
node.listener.call(this, wrapped);
}
else if (node.kind !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
node.listener.handleEvent(wrapped);
}
if (wrapped[STOP_IMMEDIATE_PROPAGATION_FLAG]) {

@@ -189,0 +183,0 @@ break;

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

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

# event-target-shim
[![Build Status](https://travis-ci.org/mysticatea/event-target-shim.svg)](https://travis-ci.org/mysticatea/event-target-shim)
[![Build Status](https://travis-ci.org/mysticatea/event-target-shim.svg?branch=master)](https://travis-ci.org/mysticatea/event-target-shim)
[![Coverage Status](https://coveralls.io/repos/mysticatea/event-target-shim/badge.svg?branch=master&service=github)](https://coveralls.io/github/mysticatea/event-target-shim?branch=master)

@@ -15,6 +15,13 @@ [![Dependency Status](https://david-dm.org/mysticatea/event-target-shim.svg)](https://david-dm.org/mysticatea/event-target-shim)

```js
// The prototype of this class has getters and setters of `onmessage` and `onerror`.
class Foo extends EventTarget("message", "error") {
//...
}
```
## Installation
```
npm install event-target-shim
npm install --save event-target-shim
```

@@ -67,2 +74,8 @@

}
//-----------------------------------------------------------------------------
// If `window.EventTarget` exists, `EventTarget` inherits from `window.EventTarget`.
if (foo instanceof window.EventTarget) {
console.log("yay!");
}
```

@@ -147,3 +160,3 @@

```js
require(["./node_modules/event-target-shim/dist/event-target-shim.min.js"], function(EventTarget) {
require(["https://cdn.rawgit.com/mysticatea/event-target-shim/v1.1.0/dist/event-target-shim.min.js"], function(EventTarget) {
//...

@@ -165,17 +178,3 @@ });

declare function EventTarget(...types: string[]): EventTarget;
declare function EventTarget(types: string[]): EventTarget;
```
If `window.EventTarget` exists, `EventTarget` is inherit from `window.EventTarget`.
So,
```js
const EventTarget = require("event-target-shim");
class Foo extends EventTarget {
}
let foo = new Foo();
if (foo instanceof window.EventTarget) {
console.log("yay!");
}
```
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