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

@idigi/events

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@idigi/events - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

7

package.json
{
"name": "@idigi/events",
"version": "1.0.0",
"version": "1.0.1",
"main": "src/index.js",

@@ -41,8 +41,5 @@ "types": "src/index.d.ts",

"dependencies": {
"@idigi/error": "0.0.5",
"@idigi/logger": "0.0.5",
"@idigi/random": "^0.0.0",
"lodash": "^4.17.20",
"simpl-schema": "^1.10.2"
"lodash": "^4.17.20"
}
}

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

import lodash from"lodash";import Logger from"@idigi/logger";class Events{constructor(opts={}){this.CLASS="";this.info=Object();this.statuses=Object();this.dates=Object();this._eHandlers={};this._eStopped=false;this._eDefs=[{ev:"all"}];for(const[f,v]of Object.entries(opts)){this[Events._public.includes(f)?f:`_${f}`]=v}}get eHandlers(){return this._eHandlers}get eStopped(){return this._eStopped}get eDefs(){return this._eDefs}eResume(){this._eStopped=false}eStop(){this._eStopped=true}_eArgs(args){return args}async _eSync(name,funcs,args,...more){const func=funcs.shift();if(!func)return[];let results=[];try{const res=await func(this._eArgs(args),...more);if(Array.isArray(res))results.push(...res)}catch(error){Logger.error({name:"Events"},`Error in "${name}" consumer`,error)}if(funcs.length){const _results=await this._eSync(name,funcs,args,...more);if(Array.isArray(_results))_results.forEach(result=>results===null||results===void 0?void 0:results.push(result))}return results}async _emit(_eName,_eNames,results,args,...more){if(!this._eHandlers[_eName].length)return;const resx=await this._eSync(_eName,this._eHandlers[_eName].slice(0),Object.assign({_eName:_eName,_eNames:_eNames},args),...more);if(Array.isArray(resx))results.push(...resx)}async emit(eNamex,args={},...more){if(this._eStopped)return[];let results=[];const _eNames=this._eNames([eNamex,this._eDefs]);if(args._eFor)for(const _eName of _eNames)await this._emit(_eName,_eNames,results,args,more);else await Promise.all(_eNames.map(_eName=>this._emit(_eName,_eNames,results,args,more)));return results}async on(eNamex,func){for(const eName of this._eNames([eNamex]))this._eHandlers[eName].push(func)}_eNames(nxs){const res=[];for(const nx of nxs){for(const{ev,reg}of Array.isArray(nx)?nx.map(opts=>typeof opts==="object"?!opts.ev?Object.assign(Object.assign({},opts),{ev:Events.slugify(opts.ev)}):opts:{ev:Events.slugify(opts)}):[typeof nx==="object"?nx:{ev:Events.slugify(nx)}]){if(reg)res.push(...Object.keys(this._eHandlers).filter(n=>n.match(reg)));if(ev){res.push(ev);if(!this._eHandlers[ev])this._eHandlers[ev]=[]}}}return lodash.uniq(res)}static slugify(s,transform="toLowerCase"){const slug=lodash.kebabCase(s);return transform?slug[transform]():slug}slugify(s,transform){return Events.slugify(s,transform)}get name(){return this._name||this.CLASS}set name(s){this._name=s}get slug(){return this._slug||this.slugify(this._name||this.CLASS)}set slug(s){this._slug=this.slugify(s)}get tags(){return this._tags||(this.slug!==""?[this.slug]:[])}set tags(_tags){this._tags=lodash.uniq(_tags.map(t=>this.slugify(t)).filter(t=>t!=""))}toJson(opts={ignores:"_toJsonIgnores|_eStopped|_eHandlers|_eDefs"}){const p=opts.values||this;let re=p;if(Array.isArray(p)){re=[];for(let el of p){if(typeof el==="object"){re.push(typeof el.toJson==="function"?el.toJson(Object.assign(Object.assign({},opts),{values:el})):this.toJson(Object.assign(Object.assign({},opts),{values:el})))}else re.push(el)}}else if(typeof p==="object"){re={};for(let k of lodash.uniq((p._toJsonGets||[]).concat(Object.keys(p)))){let v=p[k];if(opts.ignores&&k.match(new RegExp(opts.ignores,"g"))||p._toJsonIgnores&&k.match(new RegExp(p._toJsonIgnores,"g"))){continue}if(k.match(/^_/)&&p[k.replace(/^_/,"")]!==undefined){k=k.replace(/^_/,"");v=p[k]}const action=(p._toJsonActions||{})[k]||{};this[action.action||"_toJsonObjAssign"]({v:v,k:k,re:re,opts:opts,action:action,"this":p})}}return re}_toJsonObjAssign(o){if(o.v&&typeof o.v==="object"){if(typeof o.v.toJson==="function")o.re[o.k]=o.v.toJson(Object.assign(Object.assign({},o.opts),{values:o.v}));else o.re[o.k]=this.toJson(Object.assign(Object.assign({},o.opts),{values:o.v}))}else o.re[o.k]=o.v;return o.re[o.k]||o.def||{}}_toJsonObjArray(o){if(typeof o.v==="object"&&!Array.isArray(o.v)){const key=o.action.key||"key";o.re[o.k]=Object.entries(o.v).map(([k,v])=>{const r=this._toJsonObjAssign(Object.assign(Object.assign({},o),{re:{},k:k,v:v}));if(typeof r==="object")r[key]=r[key]||k;return r})}}}Events._public=["CLASS","version","colors","statuses","info","i18n","name","slug","position","emoji","icon","pic","desc","type","kind","dates"];export default Events;
import lodash from"lodash";import Random from"@idigi/random";class Events{get eHandlers(){return this._eHandlers}get eStopped(){return this._eStopped}get eDefs(){return this._eDefs}constructor(opts={}){this.CLASS="";this.info=Object();this.statuses=Object();this.dates=Object();this._eHandlers={};this._eStopped=false;this._eDefs=[{ev:"all"}];for(const[f,v]of Object.entries(opts)){this[Events._public.includes(f)?f:`_${f}`]=v}}eResume(){this._eStopped=false}eStop(){this._eStopped=true}_eArgs(args){return args}async _eSync(name,funcs,args,...more){const func=funcs.shift();if(!func)return[];let results=[];try{const res=await func(this._eArgs(args),...more);if(Array.isArray(res))results.push(...res)}catch(error){console.error(`Error in "${name}" consumer`,error)}if(funcs.length){const _results=await this._eSync(name,funcs,args,...more);if(Array.isArray(_results))_results.forEach(result=>results===null||results===void 0?void 0:results.push(result))}return results}async _emit(_eName,_eNames,results,args,...more){if(!this._eHandlers[_eName].length)return;const resx=await this._eSync(_eName,this._eHandlers[_eName].slice(0),Object.assign({_eName:_eName,_eNames:_eNames},args),...more);if(Array.isArray(resx))results.push(...resx)}async emit(eNamex,args={},...more){if(this._eStopped)return[];let results=[];const _eNames=this._eNames([eNamex,this._eDefs]);const _eId=Random.id();if(args._eFor)for(const _eName of _eNames)await this._emit(_eName,_eNames,results,Object.assign({_eId:_eId},args),more);else await Promise.all(_eNames.map(_eName=>this._emit(_eName,_eNames,results,Object.assign({_eId:_eId},args),more)));return results}async on(eNamex,func){for(const eName of this._eNames([eNamex]))this._eHandlers[eName].push(func)}_eNames(nxs){const res=[];for(const nx of nxs){for(const{ev,reg}of Array.isArray(nx)?nx.map(opts=>typeof opts==="object"?!opts.ev?Object.assign(Object.assign({},opts),{ev:Events.slugify(opts.ev)}):opts:{ev:Events.slugify(opts)}):[typeof nx==="object"?nx:{ev:Events.slugify(nx)}]){if(reg)res.push(...Object.keys(this._eHandlers).filter(n=>n.match(reg)));if(ev){res.push(ev);if(!this._eHandlers[ev])this._eHandlers[ev]=[]}}}return lodash.uniq(res)}static slugify(s,transform="toLowerCase"){const slug=lodash.kebabCase(s);return transform?slug[transform]():slug}slugify(s,transform){return Events.slugify(s,transform)}get name(){return this._name||this.CLASS}set name(s){this._name=s}get slug(){return this._slug||this.slugify(this._name||this.CLASS)}set slug(s){this._slug=this.slugify(s)}get tags(){return this._tags||(this.slug!==""?[this.slug]:[])}set tags(_tags){this._tags=lodash.uniq(_tags.map(t=>this.slugify(t)).filter(t=>t!=""))}toJson(opts={ignores:"_toJsonIgnores|_eStopped|_eHandlers|_eDefs"}){const p=opts.values||this;let re=p;if(Array.isArray(p)){re=[];for(let el of p){if(typeof el==="object"){re.push(typeof el.toJson==="function"?el.toJson(Object.assign(Object.assign({},opts),{values:el})):this.toJson(Object.assign(Object.assign({},opts),{values:el})))}else re.push(el)}}else if(typeof p==="object"){re={};for(let k of lodash.uniq((p._toJsonGets||[]).concat(Object.keys(p)))){let v=p[k];if(opts.ignores&&k.match(new RegExp(opts.ignores,"g"))||p._toJsonIgnores&&k.match(new RegExp(p._toJsonIgnores,"g"))){continue}if(k.match(/^_/)&&p[k.replace(/^_/,"")]!==undefined){k=k.replace(/^_/,"");v=p[k]}const action=(p._toJsonActions||{})[k]||{};this[action.action||"_toJsonObjAssign"]({v:v,k:k,re:re,opts:opts,action:action,"this":p})}}return re}_toJsonObjAssign(o){if(o.v&&typeof o.v==="object"){if(typeof o.v.toJson==="function")o.re[o.k]=o.v.toJson(Object.assign(Object.assign({},o.opts),{values:o.v}));else o.re[o.k]=this.toJson(Object.assign(Object.assign({},o.opts),{values:o.v}))}else o.re[o.k]=o.v;return o.re[o.k]||o.def||{}}_toJsonObjArray(o){if(typeof o.v==="object"&&!Array.isArray(o.v)){const key=o.action.key||"key";o.re[o.k]=Object.entries(o.v).map(([k,v])=>{const r=this._toJsonObjAssign(Object.assign(Object.assign({},o),{re:{},k:k,v:v}));if(typeof r==="object")r[key]=r[key]||k;return r})}}}Events._public=["CLASS","version","colors","statuses","info","i18n","name","slug","position","emoji","icon","pic","desc","type","kind","dates"];export default Events;
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