@idigi/events
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"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; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
5265
- Removed@idigi/error@0.0.5
- Removed@idigi/logger@0.0.5
- Removedsimpl-schema@^1.10.2
- Removed@idigi/error@0.0.5(transitive)
- Removed@idigi/logger@0.0.5(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedansicolors@0.2.1(transitive)
- Removedansistyles@0.1.3(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbunyan@1.8.15(transitive)
- Removedbunyan-format@0.2.1(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcliui@8.0.1(transitive)
- Removedclone@2.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddtrace-provider@0.8.8(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescalade@3.2.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglob@6.0.4(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash.template@4.5.0(transitive)
- Removedlodash.templatesettings@4.2.0(transitive)
- Removedmessage-box@0.2.7(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedmoment@2.30.1(transitive)
- Removedmongo-object@0.1.4(transitive)
- Removedmv@2.1.1(transitive)
- Removednan@2.22.0(transitive)
- Removedncp@2.0.0(transitive)
- Removednode-loggly-bulk@2.2.5(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedobject-keys@0.4.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.13.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrimraf@2.4.5(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafe-json-stringify@1.2.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsimpl-schema@1.13.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtransliteration@2.3.5(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@2.1.2(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@17.7.2(transitive)
- Removedyargs-parser@21.1.1(transitive)