New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flak

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flak - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## [0.2.0] - 2017-08-11
- Added `onCatchAll`, now is possible catch all events
- Fixed bad arguments in `fireAsync`
## [0.1.3] - 2017-08-10

@@ -9,0 +13,0 @@ - Removed unnecessary files for npm

81

dist/flak.js

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

// [AIV] Flak Build version: 0.1.3
// [AIV] Flak Build version: 0.2.0
var flak =

@@ -183,4 +183,6 @@ /******/ (function(modules) { // webpackBootstrap

eventListener.apply(this, args);
this._catchAll.call(this, args);
} else {
eventListener.apply(this, args);
this._catchAll.call(this, args);
}

@@ -210,2 +212,12 @@ }

/**
* Callback catch all
* @private
* @ignore
*/
}, {
key: '_catchAll',
value: function _catchAll() {}
/**
* Adds event listener for eventName

@@ -221,3 +233,3 @@ * @param eventName {string} event name

* console.log(param);
* })
* });
*/

@@ -260,3 +272,3 @@

* console.log(param);
* })
* });
*/

@@ -299,3 +311,3 @@

* @param eventName {string} event name
* @param [args] {*} ...arguments
* @param args {*} ...arguments
* @example

@@ -314,4 +326,5 @@ * emitter.fireAsync('myEvent', param1, param2, ...);

args.unshift(eventName);
setTimeout(function () {
_this.fire(eventName, args);
_this.fire.apply(_this, args);
}, this.opts.asyncDelay);

@@ -326,4 +339,4 @@ }

* @example
* emitter.off('myEvent') // remove event
* emitter.off('myEvent', listener) // remove specific listener
* emitter.off('myEvent'); // remove event
* emitter.off('myEvent', listener); // remove specific listener
*/

@@ -407,3 +420,3 @@

*
* emitter.getListenersCount('event') // 2
* emitter.getListenersCount('event'); // 2
*/

@@ -435,3 +448,3 @@

* Get events list
* @returns {Array}
* @returns {Object}
*/

@@ -486,13 +499,37 @@

/**
* This event is triggered when an event is created
* Triggered when an event is fired
* @param callback {Function} callback function
* @returns {Flak}
* @example
* emitter.onCatchAll(args=>{
* // args is an array of params
* console.log(args);
* });
*
* emitter.on('myEvent', param=>{
* console.log(param);
* });
*
* emitter.fire('myEvent');
*/
}, {
key: 'onCatchAll',
value: function onCatchAll(callback) {
this._catchAll = callback;
return this;
}
/**
* Triggered when an event is created
* @param callback {Function} callback function
* @returns {Flak}
* @example
* emitter.onCreated(obj=>{
* console.log(obj) //-> eventName, listener, opts
* })
* console.log(obj); //-> eventName, listener, opts
* });
*
* emitter.on('myEvent', (param)=>{
* console.log(param)
* })
* console.log(param);
* });
*/

@@ -508,3 +545,3 @@

/**
* This event is triggered when an event is removed
* Triggered when an event is removed
* @param callback {Function} callback function

@@ -514,6 +551,6 @@ * @returns {Flak}

* emitter.onRemoved(obj=>{
* console.log(obj) //-> eventName, (listener)
* })
* console.log(obj); //-> eventName, (listener)
* });
*
* emitter.off('myEvent')
* emitter.off('myEvent');
*/

@@ -547,10 +584,10 @@

/**
* Get prototype class
* Get object type
* @param object {*}
* @param className {string}
* @param type {string}
* @returns {boolean}
*/
helper.is = function (object, className) {
helper.is = function (object, type) {
var objectToString = Object.prototype.toString.call(object);
return objectToString.toLowerCase() === '[object ' + className + ']'.toLowerCase();
return objectToString.toLowerCase() === '[object ' + type + ']'.toLowerCase();
};

@@ -557,0 +594,0 @@

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

// [AIV] Flak Build version: 0.1.3
var flak=function(e){function t(r){if(n[r])return n[r].exports;var s=n[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var n={};return t.m=e,t.c=n,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";e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=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}}(),i=n(2),o=n(3),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),this.defaultClassOpts={maxListeners:10,asyncDelay:10},this.defaultListenerOpts={maxCalls:0,prepend:!1},this.opts=i.defaults(t,this.defaultClassOpts),this.events={}}return s(e,[{key:"_createEvent",value:function(e,t,n){if(this.events[e]||(this.events[e]=[]),this.opts.maxListeners){var r=this.opts.maxListeners;if(this.events[e].length>=r)throw new Error(o[3]+r)}t.opts=i.defaults(n,this.defaultListenerOpts),t.info={calls:0},n.prepend?this.events[e].unshift(t):this.events[e].push(t),this._created.call(this,e,t,n)}},{key:"_callEvent",value:function(e,t,n){if(t.opts.maxCalls){if(t.info.calls++>=t.opts.maxCalls)return void this.off(e,t);t.apply(this,n)}else t.apply(this,n)}},{key:"_created",value:function(){}},{key:"_removed",value:function(){}},{key:"on",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!i.is(e,"string"))throw new Error(o[0]);if(e=e.trim(),!e.length)throw new Error(o[4]);if(i.is(t,"array")){for(var r in t)if(t.hasOwnProperty(r)){if(!i.is(t[r],"function"))throw new Error(o[1]);this._createEvent(e,t[r],n)}}else{if(!i.is(t,"function"))throw new Error(o[1]);this._createEvent(e,t,n)}return this}},{key:"once",value:function(e,t){return this.on(e,t,{maxCalls:1})}},{key:"fire",value:function(e){if(this.exists(e)){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var s=0;s<this.events[e].length;s++)this._callEvent(e,this.events[e][s],n)}return this}},{key:"fireAsync",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];setTimeout(function(){t.fire(e,r)},this.opts.asyncDelay)}},{key:"off",value:function(e,t){if(!i.is(e,"string"))throw new Error(o[0]);if(this.events[e])if("function"==typeof t)for(var n=0;n<this.events[e].length;n++)this.events[e][n]===t&&(this.events[e].splice(n,1),this._removed.call(this,e,t));else delete this.events[e],this._removed.call(this,e);return this}},{key:"prependListener",value:function(e,t){return this.on(e,t,{prepend:!0})}},{key:"prependOnceListener",value:function(e,t){return this.on(e,t,{maxCalls:1,prepend:!0})}},{key:"clear",value:function(){return this.events=[],this}},{key:"getListenersCount",value:function(e){return this.getListeners(e).length}},{key:"getListeners",value:function(e){if(!i.is(e,"string"))throw new Error(o[0]);if(!this.exists(e))throw new Error(o[5]);return this.events[e]}},{key:"getEvents",value:function(){return this.events}},{key:"exists",value:function(e){if(!i.is(e,"string"))throw new Error(o[0]);return!i.is(this.events[e],"undefined")}},{key:"getMaxListeners",value:function(){return this.opts.maxListeners}},{key:"setMaxListeners",value:function(e){if(!i.is(e,"number"))throw new Error(o[2]);return this.opts.maxListeners=e,this}},{key:"onCreated",value:function(e){return this._created=e,this}},{key:"onRemoved",value:function(e){return this._removed=e,this}}]),e}();e.exports=u,e.exports._error=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s={};s.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},s.defaults=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e.hasOwnProperty(n)?"object"===r(e[n])&&s.defaults(e[n],t[n]):e[n]=t[n]);return e},e.exports=s},function(e,t,n){"use strict";e.exports=["event name is required and must be a string","listener is required and must be a function or an array of function","value must be a number","increase maxListeners per event: ","event name not valid","event not found"]}]);
// [AIV] Flak Build version: 0.2.0
var flak=function(e){function t(r){if(n[r])return n[r].exports;var s=n[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var n={};return t.m=e,t.c=n,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";e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=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}}(),i=n(2),o=n(3),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),this.defaultClassOpts={maxListeners:10,asyncDelay:10},this.defaultListenerOpts={maxCalls:0,prepend:!1},this.opts=i.defaults(t,this.defaultClassOpts),this.events={}}return s(e,[{key:"_createEvent",value:function(e,t,n){if(this.events[e]||(this.events[e]=[]),this.opts.maxListeners){var r=this.opts.maxListeners;if(this.events[e].length>=r)throw new Error(o[3]+r)}t.opts=i.defaults(n,this.defaultListenerOpts),t.info={calls:0},n.prepend?this.events[e].unshift(t):this.events[e].push(t),this._created.call(this,e,t,n)}},{key:"_callEvent",value:function(e,t,n){if(t.opts.maxCalls){if(t.info.calls++>=t.opts.maxCalls)return void this.off(e,t);t.apply(this,n),this._catchAll.call(this,n)}else t.apply(this,n),this._catchAll.call(this,n)}},{key:"_created",value:function(){}},{key:"_removed",value:function(){}},{key:"_catchAll",value:function(){}},{key:"on",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!i.is(e,"string"))throw new Error(o[0]);if(e=e.trim(),!e.length)throw new Error(o[4]);if(i.is(t,"array")){for(var r in t)if(t.hasOwnProperty(r)){if(!i.is(t[r],"function"))throw new Error(o[1]);this._createEvent(e,t[r],n)}}else{if(!i.is(t,"function"))throw new Error(o[1]);this._createEvent(e,t,n)}return this}},{key:"once",value:function(e,t){return this.on(e,t,{maxCalls:1})}},{key:"fire",value:function(e){if(this.exists(e)){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];for(var s=0;s<this.events[e].length;s++)this._callEvent(e,this.events[e][s],n)}return this}},{key:"fireAsync",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];r.unshift(e),setTimeout(function(){t.fire.apply(t,r)},this.opts.asyncDelay)}},{key:"off",value:function(e,t){if(!i.is(e,"string"))throw new Error(o[0]);if(this.events[e])if("function"==typeof t)for(var n=0;n<this.events[e].length;n++)this.events[e][n]===t&&(this.events[e].splice(n,1),this._removed.call(this,e,t));else delete this.events[e],this._removed.call(this,e);return this}},{key:"prependListener",value:function(e,t){return this.on(e,t,{prepend:!0})}},{key:"prependOnceListener",value:function(e,t){return this.on(e,t,{maxCalls:1,prepend:!0})}},{key:"clear",value:function(){return this.events=[],this}},{key:"getListenersCount",value:function(e){return this.getListeners(e).length}},{key:"getListeners",value:function(e){if(!i.is(e,"string"))throw new Error(o[0]);if(!this.exists(e))throw new Error(o[5]);return this.events[e]}},{key:"getEvents",value:function(){return this.events}},{key:"exists",value:function(e){if(!i.is(e,"string"))throw new Error(o[0]);return!i.is(this.events[e],"undefined")}},{key:"getMaxListeners",value:function(){return this.opts.maxListeners}},{key:"setMaxListeners",value:function(e){if(!i.is(e,"number"))throw new Error(o[2]);return this.opts.maxListeners=e,this}},{key:"onCatchAll",value:function(e){return this._catchAll=e,this}},{key:"onCreated",value:function(e){return this._created=e,this}},{key:"onRemoved",value:function(e){return this._removed=e,this}}]),e}();e.exports=u,e.exports._error=o},function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s={};s.is=function(e,t){return Object.prototype.toString.call(e).toLowerCase()==="[object "+t+"]".toLowerCase()},s.defaults=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e.hasOwnProperty(n)?"object"===r(e[n])&&s.defaults(e[n],t[n]):e[n]=t[n]);return e},e.exports=s},function(e,t,n){"use strict";e.exports=["event name is required and must be a string","listener is required and must be a function or an array of function","value must be a number","increase maxListeners per event: ","event name not valid","event not found"]}]);
{
"name": "flak",
"version": "0.1.3",
"version": "0.2.0",
"description": "JavaScript event emitter for browser and server",

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

<div align="center">
<br/><br/>
<img width="320" src="https://raw.githubusercontent.com/fabioricali/flak/master/extra/logo.png" title="flak"/>
<img width="250" src="https://raw.githubusercontent.com/fabioricali/flak/master/extra/logo.png" title="flak"/>
<br/><br/>

@@ -49,2 +49,7 @@ JavaScript event emitter for browser and server.

// Catch all events
emitter.onCatchAll(params=>{
console.log(params);
});
// Fire event

@@ -51,0 +56,0 @@ emitter.fire('myEvent1', true, {a: 1});

@@ -92,4 +92,6 @@ const helper = require('./helper');

eventListener.apply(this, args);
this._catchAll.call(this, args);
} else {
eventListener.apply(this, args);
this._catchAll.call(this, args);
}

@@ -113,2 +115,9 @@ }

/**
* Callback catch all
* @private
* @ignore
*/
_catchAll() {}
/**
* Adds event listener for eventName

@@ -124,3 +133,3 @@ * @param eventName {string} event name

* console.log(param);
* })
* });
*/

@@ -162,3 +171,3 @@ on(eventName, listener, opts = {}) {

* console.log(param);
* })
* });
*/

@@ -192,3 +201,3 @@ once(eventName, listener) {

* @param eventName {string} event name
* @param [args] {*} ...arguments
* @param args {*} ...arguments
* @example

@@ -198,4 +207,5 @@ * emitter.fireAsync('myEvent', param1, param2, ...);

fireAsync(eventName, ...args) {
args.unshift(eventName);
setTimeout(() => {
this.fire(eventName, args);
this.fire.apply(this, args);
}, this.opts.asyncDelay);

@@ -210,4 +220,4 @@ }

* @example
* emitter.off('myEvent') // remove event
* emitter.off('myEvent', listener) // remove specific listener
* emitter.off('myEvent'); // remove event
* emitter.off('myEvent', listener); // remove specific listener
*/

@@ -281,3 +291,3 @@ off(eventName, listener) {

*
* emitter.getListenersCount('event') // 2
* emitter.getListenersCount('event'); // 2
*/

@@ -305,3 +315,3 @@ getListenersCount(eventName) {

* Get events list
* @returns {Array}
* @returns {Object}
*/

@@ -346,13 +356,34 @@ getEvents() {

/**
* This event is triggered when an event is created
* Triggered when an event is fired
* @param callback {Function} callback function
* @returns {Flak}
* @example
* emitter.onCatchAll(args=>{
* // args is an array of params
* console.log(args);
* });
*
* emitter.on('myEvent', param=>{
* console.log(param);
* });
*
* emitter.fire('myEvent');
*/
onCatchAll(callback) {
this._catchAll = callback;
return this;
}
/**
* Triggered when an event is created
* @param callback {Function} callback function
* @returns {Flak}
* @example
* emitter.onCreated(obj=>{
* console.log(obj) //-> eventName, listener, opts
* })
* console.log(obj); //-> eventName, listener, opts
* });
*
* emitter.on('myEvent', (param)=>{
* console.log(param)
* })
* console.log(param);
* });
*/

@@ -365,3 +396,3 @@ onCreated(callback) {

/**
* This event is triggered when an event is removed
* Triggered when an event is removed
* @param callback {Function} callback function

@@ -371,6 +402,6 @@ * @returns {Flak}

* emitter.onRemoved(obj=>{
* console.log(obj) //-> eventName, (listener)
* })
* console.log(obj); //-> eventName, (listener)
* });
*
* emitter.off('myEvent')
* emitter.off('myEvent');
*/

@@ -377,0 +408,0 @@ onRemoved(callback) {

const helper = {};
/**
* Get prototype class
* Get object type
* @param object {*}
* @param className {string}
* @param type {string}
* @returns {boolean}
*/
helper.is = (object, className) => {
helper.is = (object, type) => {
let objectToString = Object.prototype.toString.call(object);
return objectToString.toLowerCase() === '[object ' + className + ']'.toLowerCase();
return objectToString.toLowerCase() === '[object ' + type + ']'.toLowerCase();
};

@@ -13,0 +13,0 @@

Sorry, the diff of this file is not supported yet

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