memorio 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /// <reference path="./types/memorio.d.ts" />
2
+ /// <reference path="./types/observer.d.ts" />
3
+ /// <reference path="./types/state.d.ts" />
4
+ /// <reference path="./types/store.d.ts" />
package/index.js CHANGED
@@ -1,13 +1,4 @@
1
- "use strict";(()=>{Object.defineProperty(globalThis,"memorio",{value:{},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(globalThis,"events",{value:{},writable:!0,configurable:!1,enumerable:!1});Object.defineProperty(memorio,"setProps",{value:(e,r,a)=>{Object.defineProperty(e,r.name,a||{writable:!1,configurable:!1,enumerable:!1}),a?.lock&&Object.freeze(e[r.name])},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(memorio,"setDescription",{value:(e,r)=>{Object.defineProperties(memorio,{[e.name]:{value:r,writable:!1,configurable:!1,enumerable:!1}}),Object.keys(r).forEach(function(a){Object.defineProperties(memorio[e.name],{[a]:{writable:!1,configurable:!1,enumerable:!1}})}),memorio.setProps(memorio,e,{writable:!1,configurable:!1,enumerable:!1})}});var u={name:"obj",active:!0,subCommand:[{name:"toArray",version:"0.0.1",example:"memorio.obj.toArray([obj])",description:"Convert an object to an array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"replaceNullObjects",version:"0.0.1",example:"memorio.obj.replaceNullObjects([obj])",description:"Replace null values in an object with empty objects.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"serialize",version:"0.0.1",example:"memorio.obj.serialize([obj])",description:"Serialize an object to a JSON string.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"deSerialize",version:"0.0.1",example:"memorio.obj.deSerialize([obj])",description:"Deserialize a JSON string to an object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"find",version:"0.0.1",example:"memorio.obj.find([array, key, value])",description:"Find an object in an array by key and value.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"toXML",version:"0.0.1",example:"memorio.obj.toXML([obj])",description:"Convert an object to an XML string.",author:"Dario Passariello",creationDate:"20240315",lastMod:"20240315",type:"function",active:!0,subCommand:[]},{name:"instance",version:"0.0.1",example:"memorio.obj.instance([obj])",description:"Create an instance of an object.",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:!0,subCommand:[]},{name:"updateByKey",version:"0.0.1",example:"memorio.obj.updateByKey([obj, key, newValue])",description:"Update an object's property by key.",author:"Dario Passariello",creationDate:"20240929",lastMod:"20240929",type:"function",active:!0,subCommand:[]},{name:"findindex",version:"0.0.1",example:"memorio.obj.findindex([obj, key])",description:"Find the index of an object in an array by key.",author:"Dario Passariello",creationDate:"20240929",lastMod:"20240929",type:"function",active:!0,subCommand:[]},{name:"parse",version:"0.0.1",example:"memorio.obj.parse(val)",description:"Check if value is an object or another type. Return object after parse or a different type. Used instead of JSON.parse to avoid crash.",author:"Dario Passariello",creationDate:"20241027",lastMod:"20240927",type:"function",active:!0,subCommand:[]},{name:"diff",version:"0.0.1",example:"memorio.obj.diff([obj1, obj2])",description:"Show the differences between two objects.",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,subCommand:[]},{name:"shallow",version:"0.0.1",example:"memorio.obj.shallow([object])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
2
- Generate a shallow copy of an object
3
- Example: memorio.obj.shallow([object])
4
- `,subCommand:[]},{name:"deepCopy",version:"0.0.1",example:"memorio.obj.deepCopy([object])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
5
- Generate a deepCopy of an object
6
- Example: memorio.obj.deepCopy([object])
7
- `,subCommand:[]}]},d={toArray:e=>Object.entries(e),replaceNullObjects:e=>{let r={...e};return Object.keys(e).forEach(a=>{e[a]===null&&(r[a]="")}),r},serialize:e=>{if(typeof e=="function")return e.toString();if(typeof e=="object"){let r={};for(let[a,t]of Object.entries(e))r[a]=memorio.obj.serialize(t);return r}return e},deSerialize:e=>{if(typeof e=="string"&&e.toLowerCase().startsWith("function("))return Function('"use strict"; return '+e)();if(typeof e=="object"){let r={};for(let[a,t]of Object.entries(e))r[a]=memorio.obj.deSerialize(t);return r}return e},sort:e=>Object.keys(e).sort().reduce((r,a)=>(r[a]=e[a],r),{}),toXML:e=>{let r=(a,t="")=>{let o="";for(let n in a)if(a.hasOwnProperty(n)){let i=a[n];typeof i=="object"&&i!==null?o+=`${t}<${n}>
8
- ${r(i,t+" ")}${t}</${n}>
9
- `:o+=`${t}<${n}>${i}</${n}>
10
- `}return o};return r(e)},find:(e,r,a)=>e.find(t=>t[r]===a),instance:e=>Object.create(e),updateByKey:(e,r,a)=>(e.hasOwnProperty(r)&&(e[r]=a),e),findindex:(e,r)=>e.findIndex(a=>a[r]!==void 0),parse:e=>{try{return JSON.parse(e)}catch{return e}},isObject:e=>typeof e=="object"&&e!==null,diff:(e,r)=>{let a={};for(let t in e)e.hasOwnProperty(t)&&e[t]!==r[t]&&(a[t]={obj1:e[t],obj2:r[t]});for(let t in r)r.hasOwnProperty(t)&&e[t]!==r[t]&&(a[t]={obj1:e[t],obj2:r[t]});return a},path:(e,r,a=".")=>r.concat(e).join(a),shallow:e=>Object.assign({},e),deepCopy:e=>structuredClone(e)};memorio.setDescription(u,d);var y={name:"array",active:!0,subCommand:[{name:"find",version:"0.0.1",example:"memorio.array.find([array, item])",description:"Find an item in the array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20240619",type:"function",active:!0,subCommand:[]},{name:"unique",version:"0.0.1",example:"memorio.array.unique([array])",description:"Return a new array with unique items.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"delete",version:"0.0.1",example:"memorio.array.delete([array, item])",description:"Delete an item from the array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"merge",version:"0.0.1",example:"memorio.array.merge([array1, array2])",description:"Merge two arrays into one.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"mergeByKey",version:"0.0.1",example:"memorio.array.mergeByKey([arrayA, arrayB, key])",author:"Dario Passariello",creationDate:"20230603",lastMod:"20230603",type:"function",active:!0,description:`
1
+ "use strict";(()=>{var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var m=(e,r)=>()=>(e&&(r=e(e=0)),r);var l=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var S=(e,r,a,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of x(r))!w.call(e,o)&&o!==a&&u(e,o,{get:()=>r[o],enumerable:!(t=P(r,o))||t.enumerable});return e};var M=e=>S(u({},"__esModule",{value:!0}),e);var y,d=m(()=>{y={name:"memorio",version:"0.2.0",description:"Memorio, State + Observer and Store for a easy life ",license:"MIT",deprecated:!1,preferGlobal:!0,target:"web",copyright:"Dario Passariello, BigLogic ca - a51.dev is a BigLogic project",homepage:"https://a51.gitbook.io/memorio",author:{name:"Dario Passariello",url:"https://dario.passariello.ca/",email:"dariopassariello@gmail.com"},support:{name:"Dario Passariello",url:"https://github.com/passariello/",email:"dariopassariello@gmail.com"},main:"index.js",contributors:[{name:"Dario Passariello",email:"dariopassarielloa@gmail.com"},{name:"Valeria Cala Scaglitta",email:"valeriacalascaglitta@gmail.com"}],globals:{memorio:{}},keywords:["biglogic","a51","memorio","state","store","observer","dario","passariello"],repository:{type:"git",url:"git+https://github.com/a51-dev/a51.memorio.git",help:"https://github.com/a51-dev/a51.memorio#readme"},bugs:{url:"https://github.com/a51-dev/a51.memorio/issues"},funding:[{type:"patreon",url:"https://www.patreon.com/passariello"}],typing:["types/*"],scripts:{build:"node ./esbuild.config.mjs",watch:"esbuild init.ts --bundle --outdir=dist --serve","-----------":"",tsc:"tsc -b .",eslint:"eslint .","----------":"","publish:npm":"npm run build && npm publish ./dist"},devDependencies:{"@eslint/js":"9.33.0","@types/jest":"^30.0.0","@types/node":"^24.3.0","@typescript-eslint/eslint-plugin":"8.39.1","@typescript-eslint/parser":"8.39.1",esbuild:"^0.25.9","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.33.0","ts-loader":"^9.5.2","ts-node":"10.9.2",tslib:"^2.8.1",typescript:"5.9.2"}}});var E={};var f=m(()=>{"use strict";d();Object.defineProperty(global,"memorio",{value:{},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(global,"events",{value:{},writable:!0,configurable:!1,enumerable:!1});global.memorio.version=y.version});var p=l(()=>{"use strict";Object.defineProperty(global.memorio,"setProps",{value:(e,r,a)=>{Object.defineProperty(e,r.name,a||{writable:!1,configurable:!1,enumerable:!1}),a?.lock&&Object.freeze(e[r.name])},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(global.memorio,"setDescription",{value:(e,r)=>{Object.defineProperties(global.memorio,{[e.name]:{value:r,writable:!1,configurable:!1,enumerable:!1}}),Object.keys(r).forEach(function(a){Object.defineProperties(global.memorio[e.name],{[a]:{writable:!1,configurable:!1,enumerable:!1}})}),global.memorio.setProps(global.memorio,e,{writable:!1,configurable:!1,enumerable:!1})}})});var b=l(()=>{"use strict";var k={name:"array",active:!0,subCommand:[{name:"find",version:"0.0.1",example:"memorio.array.find([array, item])",description:"Find an item in the array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20240619",type:"function",active:!0,subCommand:[]},{name:"unique",version:"0.0.1",example:"memorio.array.unique([array])",description:"Return a new array with unique items.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"delete",version:"0.0.1",example:"memorio.array.delete([array, item])",description:"Delete an item from the array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"merge",version:"0.0.1",example:"memorio.array.merge([array1, array2])",description:"Merge two arrays into one.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"mergeByKey",version:"0.0.1",example:"memorio.array.mergeByKey([arrayA, arrayB, key])",author:"Dario Passariello",creationDate:"20230603",lastMod:"20230603",type:"function",active:!0,description:`
11
2
  Example:
12
3
  const array = [
13
4
  {"date":1230,"value":1},
@@ -67,4 +58,13 @@ ${r(i,t+" ")}${t}</${n}>
67
58
  `,subCommand:[]},{name:"groupBy",version:"0.0.1",example:"memorio.array.groupBy([array, key])",author:"Dario Passariello",creationDate:"20250414",lastMod:"20250414",type:"function",active:!0,description:`
68
59
  Generate groups of array by a specific key
69
60
  Example: memorio.array.groupBy([array, key])
70
- `,subCommand:[]}]},f={find:(e,r)=>{if(Array.isArray(e)){for(let a of e){if(a[r]===r)return a;if(a.children){let t=memorio.array.find(r,a.children);if(t)return t}}return!1}},unique:e=>{if(Array.isArray(e))return[...new Set(e)]},delete:(e,r)=>{Array.isArray(e)&&e.some(function a(t,o,n){if(t[r]===r)return n.splice(o,1),!0;for(let i of Object.keys(t)){let s=t[i];if(Array.isArray(s))return s.some(a)}})},merge:(e,r)=>{if(!e||!r)return r||e;for(let a of Object.keys(e))e[a]instanceof Object&&r[a]&&Object.assign(e[a],memorio.array.merge(r[a],e[a]));return Object.assign(r||{},e)},mergeByKey:(e,r,a)=>e.map(t=>{let o=r.find(n=>t[a]===n[a]);return o?Object.assign({},t,o):t}),asc:e=>{if(Array.isArray(e))return e.sort((r,a)=>r-a)},desc:e=>{if(Array.isArray(e))return e.sort((r,a)=>a-r)},duplicates:e=>{if(!Array.isArray(e))return;let r=new Set,a=new Set;for(let t of e)r.has(t)?a.add(t):r.add(t);return Array.from(a)},even:e=>{if(Array.isArray(e))return e.filter(r=>r%2===0)},odd:e=>{if(Array.isArray(e))return e.filter(r=>r%2!==0)},toObj:e=>{if(Array.isArray(e))return Object.assign({},e)},sumColumn:(e=[],r=0)=>Array.isArray(e)?typeof r>"u"?"provide a column":e.reduce((a,t)=>a+(t[r]||0),0):"provide a multidimensional array",shuffle:e=>{if(Array.isArray(e)){for(let r=e.length-1;r>0;r--){let a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[e[a],e[r]]}return e}},generate:e=>{if(Number.isNaN(e))return;let r=Array.from({length:e},(a,t)=>t+1);return memorio.array.shuffle(r)},testArrayInt:e=>{if(!Array.isArray(e))return;let r=[];for(let a=1;a<=e.length;a++)e.includes(a)||r.push(a);return r},rand32:e=>{let r=performance.now(),a=[];a.nums=[],a.time=[];for(var t=0;t<e;++t)a.nums.push(crypto.getRandomValues(new Uint32Array(1))[0]);let o=performance.now();return a.time.push(o-r),a},findindex:(e,r)=>e.findIndex(a=>a.name===r),pathToJson:(e,r="/")=>{let a={},t;for(let o of e){t=a;let n=o.split(r);for(let i of n.slice(1,-1)){if(i==="")return;i in t||(t[i]={}),t=t[i]}t[n[n.length-1]]=null}return a},deepClone:e=>JSON.parse(JSON.stringify(e)),match:(e,r)=>e.filter(a=>r.includes(a)),shallow:e=>Object.assign([],e),deepCopy:e=>structuredClone(e),groupBy:(e,r)=>e.reduce((a,t)=>({...a,[t[r]]:[...a[r]||[],t]}),{})};memorio.setDescription(y,f);var p={name:"dispatch",active:!0,subCommand:[{name:"set",version:"0.0.1",example:"memorio.dispatch.set([name, value])",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Dispatches a custom event with the specified name and value.",subCommand:[]},{name:"listen",version:"0.0.1",example:"memorio.dispatch.listen([eventNames, callback=null], flag = true)",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Listens for the specified event names and executes the callback when the event is triggered.",subCommand:[]},{name:"remove",version:"0.0.1",example:"memorio.dispatch.remove([eventNames, callback=null], flag = true)",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Removes the event listener for the specified event names.",subCommand:[]}]},b={set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,a=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let t=o=>r?setTimeout(()=>r(o),0):null;globalThis.events[e]=t},remove:e=>{globalThis.events.name=""}};memorio.setDescription(p,b);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(store,{get:{value(e){if(e)try{let r=localStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.error(`Error parsing store item "${e}":`,r)}}},set:{value(e,r){if(e)try{r==null?localStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?localStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.error("It's not secure to store functions.")}catch(a){console.error(`Error setting store item "${e}":`,a)}}},remove:{value(e){if(e&&localStorage.getItem(e))return localStorage.removeItem(e),!0}},delete:{value(e){store.remove(e)}},removeAll:{value(){return localStorage.clear(),!0}},clearAll:{value(){return store.removeAll(),!0}},quota:{value(){"storage"in navigator&&"estimate"in navigator.storage&&navigator.storage.estimate().then(({usage:e,quota:r})=>{e&&r&&console.debug(`Using ${e/1024} out of ${r/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let r in localStorage)if(localStorage.hasOwnProperty(r)){let a=localStorage.getItem(r);a&&(e+=a.length)}return e}}});Object.freeze(store);var c=(e,r,a=[])=>{let t=o=>{let n=o.split("-");n.forEach((i,s)=>{let l=n.slice(0,s+1).join("-");memorio.dispatch.set(l,{detail:{name:l}})})};return new Proxy(e,{get(o,n){if(Object.isFrozen(o[n]))return o[n];try{let i=Reflect.get(o,n);return i&&typeof i=="object"&&["Array","Object"].includes(i.constructor.name)?c(i,r,a.concat(n)):i}catch(i){return console.error("Error: ",i),!1}},set(o,n,i){if(o[n]&&typeof o[n]=="object"&&Object.isFrozen(o[n])){console.error(`Error: state "${n}" is locked`);return}try{let s=memorio.obj.path(n,a);return r({action:"set",path:s,target:o,newValue:i,previousValue:Reflect.get(o,n)}),t("state-"+s.replaceAll(".","-")),Reflect.set(o,n,i),o[n]&&typeof o[n]=="object"&&Reflect.defineProperty(o[n],"lock",{value(){Object.defineProperty(o,n,{writable:!1,enumerable:!1}),Object.freeze(o[n])}}),!0}catch(s){return console.error("Error in set trap:",s),!1}},deleteProperty(o,n){try{let i=memorio.obj.path(n,a);return r({action:"delete",path:i,target:o}),Reflect.deleteProperty(o,n)}catch(i){return console.error("Error in deleteProperty trap:",i),!1}}})};globalThis?.state?globalThis.state=state:globalThis.state=c({},()=>{});var m=new WeakSet;m.add(state);setInterval(()=>{if(!m.has(state)){alert("memorio State is compromised, check if you override it and please reload the page");for(let e=1;e<99999;e++)clearInterval(e);stop()}},1e3);Object.defineProperty(globalThis,"state",{enumerable:!1,configurable:!1});Object.defineProperties(state,{list:{get(){let e=memorio.array.deepClone(state);return console.log(e)}},remove:{value(e){e in state?(delete state[e],console.debug(`State '${e}' deleted`)):console.error(`'${e}' not exist`)},writable:!1,configurable:!1},removeAll:{value(){state.forEach(e=>{delete state[e[0]]})},writable:!1,configurable:!1}});globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1});observer=(e,r=null,a=!0)=>{if((o=>o.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare "state." or "store.". The "${o}" string is incorrect!`),!1):!0)(e)){if(!e&&!r){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&r){console.error('Observer Error: You need to declare what state need to be monitored as string like "state.test".');return}if(e&&!r){memorio.dispatch.listen(String(e),{detail:{name:String(e)}}),console.debug("called: ",e);return}if(e&&r){if(typeof e!="string"||typeof r!="function"){console.error('Observer Error: name of state need to be a "string" like "state.test" and the callback need to be a "function"');return}let o=e.replaceAll(".","-");memorio.dispatch.listen(o,r,a);return}}};Object.defineProperties(observer,{list:{get:()=>globalThis.events},remove:{value:e=>{e&&(globalThis.events[e]="")}},removeAll:{get:()=>{Object.entries(observer.list).forEach(e=>{globalThis.events[e[0]]})}}});Object.freeze(observer);})();
61
+ `,subCommand:[]}]},R={find:(e,r)=>{if(Array.isArray(e)){for(let a of e){if(a[r]===r)return a;if(a.children){let t=global.memorio.array.find(r,a.children);if(t)return t}}return!1}},unique:e=>{if(Array.isArray(e))return[...new Set(e)]},delete:(e,r)=>{Array.isArray(e)&&e.some(function a(t,o,n){if(t[r]===r)return n.splice(o,1),!0;for(let i of Object.keys(t)){let s=t[i];if(Array.isArray(s))return s.some(a)}})},merge:(e,r)=>{if(!e||!r)return r||e;for(let a of Object.keys(e))e[a]instanceof Object&&r[a]&&Object.assign(e[a],global.memorio.array.merge(r[a],e[a]));return Object.assign(r||{},e)},mergeByKey:(e,r,a)=>e.map(t=>{let o=r.find(n=>t[a]===n[a]);return o?Object.assign({},t,o):t}),asc:e=>{if(Array.isArray(e))return e.sort((r,a)=>r-a)},desc:e=>{if(Array.isArray(e))return e.sort((r,a)=>a-r)},duplicates:e=>{if(!Array.isArray(e))return;let r=new Set,a=new Set;for(let t of e)r.has(t)?a.add(t):r.add(t);return Array.from(a)},even:e=>{if(Array.isArray(e))return e.filter(r=>r%2===0)},odd:e=>{if(Array.isArray(e))return e.filter(r=>r%2!==0)},toObj:e=>{if(Array.isArray(e))return Object.assign({},e)},sumColumn:(e=[],r=0)=>Array.isArray(e)?typeof r>"u"?"provide a column":e.reduce((a,t)=>a+(t[r]||0),0):"provide a multidimensional array",shuffle:e=>{if(Array.isArray(e)){for(let r=e.length-1;r>0;r--){let a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[e[a],e[r]]}return e}},generate:e=>{if(Number.isNaN(e))return;let r=Array.from({length:e},(a,t)=>t+1);return global.memorio.array.shuffle(r)},testArrayInt:e=>{if(!Array.isArray(e))return;let r=[];for(let a=1;a<=e.length;a++)e.includes(a)||r.push(a);return r},rand32:e=>{let r=performance.now(),a=[];a.nums=[],a.time=[];for(var t=0;t<e;++t)a.nums.push(crypto.getRandomValues(new Uint32Array(1))[0]);let o=performance.now();return a.time.push(o-r),a},findindex:(e,r)=>e.findIndex(a=>a.name===r),pathToJson:(e,r="/")=>{let a={},t;for(let o of e){t=a;let n=o.split(r);for(let i of n.slice(1,-1)){if(i==="")return;i in t||(t[i]={}),t=t[i]}t[n[n.length-1]]=null}return a},deepClone:e=>JSON.parse(JSON.stringify(e)),match:(e,r)=>e.filter(a=>r.includes(a)),shallow:e=>Object.assign([],e),deepCopy:e=>structuredClone(e),groupBy:(e,r)=>e.reduce((a,t)=>({...a,[t[r]]:[...a[r]||[],t]}),{})};global.memorio.setDescription(k,R)});var g=l(()=>{"use strict";var z={name:"dispatch",active:!0,subCommand:[{name:"set",version:"0.0.1",example:"memorio.dispatch.set([name, value])",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Dispatches a custom event with the specified name and value.",subCommand:[]},{name:"listen",version:"0.0.1",example:"memorio.dispatch.listen([eventNames, callback=null], flag = true)",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Listens for the specified event names and executes the callback when the event is triggered.",subCommand:[]},{name:"remove",version:"0.0.1",example:"memorio.dispatch.remove([eventNames, callback=null], flag = true)",author:"Dario Passariello",creationDate:"20231231",lastMod:"20240612",type:"function",active:!0,description:"Removes the event listener for the specified event names.",subCommand:[]}]},$={set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,a=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let t=o=>r?setTimeout(()=>r(o),1):null;window.addEventListener(e,t),global.events[e]=t},remove:e=>{window.removeEventListener(e,global.events[e]),delete global.events[e]}};global.memorio.setDescription(z,$)});var v=l(()=>{"use strict";var I={name:"obj",active:!0,subCommand:[{name:"toArray",version:"0.0.1",example:"memorio.obj.toArray([obj])",description:"Convert an object to an array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"replaceNullObjects",version:"0.0.1",example:"memorio.obj.replaceNullObjects([obj])",description:"Replace null values in an object with empty objects.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"serialize",version:"0.0.1",example:"memorio.obj.serialize([obj])",description:"Serialize an object to a JSON string.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"deSerialize",version:"0.0.1",example:"memorio.obj.deSerialize([obj])",description:"Deserialize a JSON string to an object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"find",version:"0.0.1",example:"memorio.obj.find([array, key, value])",description:"Find an object in an array by key and value.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,subCommand:[]},{name:"toXML",version:"0.0.1",example:"memorio.obj.toXML([obj])",description:"Convert an object to an XML string.",author:"Dario Passariello",creationDate:"20240315",lastMod:"20240315",type:"function",active:!0,subCommand:[]},{name:"instance",version:"0.0.1",example:"memorio.obj.instance([obj])",description:"Create an instance of an object.",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:!0,subCommand:[]},{name:"updateByKey",version:"0.0.1",example:"memorio.obj.updateByKey([obj, key, newValue])",description:"Update an object's property by key.",author:"Dario Passariello",creationDate:"20240929",lastMod:"20240929",type:"function",active:!0,subCommand:[]},{name:"findindex",version:"0.0.1",example:"memorio.obj.findindex([obj, key])",description:"Find the index of an object in an array by key.",author:"Dario Passariello",creationDate:"20240929",lastMod:"20240929",type:"function",active:!0,subCommand:[]},{name:"parse",version:"0.0.1",example:"memorio.obj.parse(val)",description:"Check if value is an object or another type. Return object after parse or a different type. Used instead of JSON.parse to avoid crash.",author:"Dario Passariello",creationDate:"20241027",lastMod:"20240927",type:"function",active:!0,subCommand:[]},{name:"diff",version:"0.0.1",example:"memorio.obj.diff([obj1, obj2])",description:"Show the differences between two objects.",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,subCommand:[]},{name:"shallow",version:"0.0.1",example:"memorio.obj.shallow([object])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
62
+ Generate a shallow copy of an object
63
+ Example: memorio.obj.shallow([object])
64
+ `,subCommand:[]},{name:"deepCopy",version:"0.0.1",example:"memorio.obj.deepCopy([object])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
65
+ Generate a deepCopy of an object
66
+ Example: memorio.obj.deepCopy([object])
67
+ `,subCommand:[]}]},N={toArray:e=>Object.entries(e),replaceNullObjects:e=>{let r={...e};return Object.keys(e).forEach(a=>{e[a]===null&&(r[a]="")}),r},serialize:e=>{if(typeof e=="function")return e.toString();if(typeof e=="object"){let r={};for(let[a,t]of Object.entries(e))r[a]=global.memorio.obj.serialize(t);return r}return e},deSerialize:e=>{if(typeof e=="string"&&e.toLowerCase().startsWith("function("))return Function("'use strict'; return "+e)();if(typeof e=="object"){let r={};for(let[a,t]of Object.entries(e))r[a]=global.memorio.obj.deSerialize(t);return r}return e},sort:e=>Object.keys(e).sort().reduce((r,a)=>(r[a]=e[a],r),{}),toXML:e=>{let r=(a,t="")=>{let o="";for(let n in a)if(a.hasOwnProperty(n)){let i=a[n];typeof i=="object"&&i!==null?o+=`${t}<${n}>
68
+ ${r(i,t+" ")}${t}</${n}>
69
+ `:o+=`${t}<${n}>${i}</${n}>
70
+ `}return o};return r(e)},find:(e,r,a)=>e.find(t=>t[r]===a),instance:e=>Object.create(e),updateByKey:(e,r,a)=>(e.hasOwnProperty(r)&&(e[r]=a),e),findindex:(e,r)=>e.findIndex(a=>a[r]!==void 0),parse:e=>{try{return JSON.parse(e)}catch{return e}},isObject:e=>typeof e=="object"&&e!==null,diff:(e,r)=>{let a={};for(let t in e)e.hasOwnProperty(t)&&e[t]!==r[t]&&(a[t]={obj1:e[t],obj2:r[t]});for(let t in r)r.hasOwnProperty(t)&&e[t]!==r[t]&&(a[t]={obj1:e[t],obj2:r[t]});return a},path:(e,r,a=".")=>r.concat(e).join(a),shallow:e=>Object.assign({},e),deepCopy:e=>structuredClone(e)};global.memorio.setDescription(I,N)});var D=l(()=>{"use strict";var h=(e,r,a=[])=>{let t=o=>{let n=o.split(".");n.forEach((i,s)=>{let c=n.slice(0,s+1).join(".");global.memorio.dispatch.set(c,{detail:{name:c}})})};return new Proxy(e,{get(o,n){if(Object.isFrozen(o[n]))return o[n];try{let i=Reflect.get(o,n);return i&&typeof i=="object"&&["Array","Object"].includes(i.constructor.name)?h(i,r,a.concat(n)):i}catch(i){return console.error("Error: ",i),!1}},set(o,n,i){if(o[n]&&typeof o[n]=="object"&&Object.isFrozen(o[n])){console.error(`Error: state '${n}' is locked`);return}try{let s=global.memorio.obj.path(n,a);return r({action:"set",path:s,target:o,newValue:i,previousValue:Reflect.get(o,n)}),t("state."+s),Reflect.set(o,n,i),o[n]&&typeof o[n]=="object"&&Reflect.defineProperty(o[n],"lock",{value(){Object.defineProperty(o,n,{writable:!1,enumerable:!1}),Object.freeze(o[n])}}),!0}catch(s){return console.error("Error in set trap:",s),!1}},deleteProperty(o,n){try{let i=global.memorio.obj.path(n,a);return r({action:"delete",path:i,target:o}),Reflect.deleteProperty(o,n)}catch(i){return console.error("Error in deleteProperty trap:",i),!1}}})};global?.state?global.state=state:global.state=h({},()=>{});var j=new WeakSet;j.add(state);setInterval(()=>{if(!j.has(state)){alert("memorio State is compromised, check if you override it and please reload the page");for(let e=1;e<99999;e++)clearInterval(e);stop()}},1e3);Object.defineProperty(global,"state",{enumerable:!1,configurable:!1});Object.defineProperties(state,{list:{get(){let e=global.memorio.array.deepClone(state);return console.log(e)}},remove:{value(e){e in state?(delete state[e],console.debug(`State '${e}' deleted`)):console.error(`'${e}' not exist`)},writable:!1,configurable:!1},removeAll:{value(){state.forEach(e=>{delete state[e[0]]})},writable:!1,configurable:!1}})});var O=l(()=>{"use strict";global.observer||(global.observer=null);Object.defineProperty(global,"observer",{enumerable:!1});observer=(e,r=null,a=!0)=>{if((o=>o.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${o}' string is incorrect!`),!1):!0)(e)){if(!e&&!r){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&r){console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'.");return}if(e&&!r){global.memorio.dispatch.listen(String(e),{detail:{name:String(e)}}),console.debug("called: ",e);return}if(e&&r){if(typeof e!="string"||typeof r!="function"){console.error("Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'");return}global.memorio.dispatch.listen(e,r,a);return}}};Object.defineProperties(observer,{list:{get:()=>global.events},remove:{value:e=>{e&&(global.events[e]="")}},removeAll:{get:()=>{Object.entries(observer.list).forEach(e=>{global.events[e[0]]})}}});Object.freeze(observer)});var C=l(()=>{"use strict";Object.defineProperty(global,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(store,{get:{value(e){if(e)try{let r=localStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.error(`Error parsing store item '${e}':`,r)}}},set:{value(e,r){if(e)try{r==null?localStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?localStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.error("It's not secure to store functions.")}catch(a){console.error(`Error setting store item '${e}':`,a)}}},remove:{value(e){if(e&&localStorage.getItem(e))return localStorage.removeItem(e),!0}},delete:{value(e){store.remove(e)}},removeAll:{value(){return localStorage.clear(),!0}},clearAll:{value(){return store.removeAll(),!0}},quota:{value(){"storage"in navigator&&"estimate"in navigator.storage&&navigator.storage.estimate().then(({usage:e,quota:r})=>{e&&r&&console.debug(`Using ${e/1024} out of ${r/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let r in localStorage)if(localStorage.hasOwnProperty(r)){let a=localStorage.getItem(r);a&&(e+=a.length)}return e}}});Object.freeze(store)});f();p();b();g();v();D();O();C();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memorio",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "Memorio, State + Observer and Store for a easy life ",
5
5
  "license": "MIT",
6
6
  "deprecated": false,
@@ -60,8 +60,8 @@
60
60
  "types/*"
61
61
  ],
62
62
  "scripts": {
63
- "watch": "esbuild init.ts --bundle --outdir=dist --serve",
64
63
  "build": "node ./esbuild.config.mjs",
64
+ "watch": "esbuild init.ts --bundle --outdir=dist --serve",
65
65
  "-----------": "",
66
66
  "tsc": "tsc -b .",
67
67
  "eslint": "eslint .",
@@ -69,6 +69,9 @@
69
69
  "publish:npm": "npm run build && npm publish ./dist"
70
70
  },
71
71
  "devDependencies": {
72
+ "@eslint/js": "9.33.0",
73
+ "@types/jest": "^30.0.0",
74
+ "@types/node": "^24.3.0",
72
75
  "@typescript-eslint/eslint-plugin": "8.39.1",
73
76
  "@typescript-eslint/parser": "8.39.1",
74
77
  "esbuild": "^0.25.9",
@@ -1,4 +1,10 @@
1
1
 
2
+
3
+ declare module 'memorio' {
4
+ const resource: { [key: string]: any }
5
+ export = resource
6
+ }
7
+
2
8
  interface _memorio {
3
9
  setProps: any,
4
10
  obj: any,
@@ -7,16 +13,16 @@ interface _memorio {
7
13
  setDescription: any
8
14
  }
9
15
 
10
- declare var memorio: _memorio
11
16
  type memorio = _memorio
17
+ declare var memorio: any
12
18
 
13
- declare var arguments: any
14
19
  type arguments = any
20
+ declare var arguments: any
15
21
 
16
22
  /////////////////////////////////////////////
17
23
 
18
24
  interface Descr {
19
25
  name: string,
20
26
  active: boolean,
21
- subCommand: Array<SubCommand>,
27
+ subCommand: object,
22
28
  }