memorio 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/index.js +1 -70
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,70 +1 @@
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:`
2
- Example:
3
- const array = [
4
- {"date":1230,"value":1},
5
- {"date":1231,"value":2},
6
- {"date":1232,"value":3, "value1":3, name:"John"},
7
- {"date":1233,"value":4},
8
- {"date":1234,"value":5},
9
- {"date":1235,"value":6}
10
- ]
11
- const newData = [
12
- {"date":1230,"value":1000,'name':'Diana'},
13
- {"date":1232,"value":1000, "value1":20000},
14
- {"date":1234,"value":1000},
15
- {"date":1235,"value":888810000}
16
- ]
17
- Command: memorio.array.mergeByKey( array, newData, 'date' )
18
- Result:
19
- [
20
- {"date": 1230,"value": 1000, name: "Diana" },
21
- {"date": 1231,"value": 2},
22
- {"date": 1232 "value": 1000, "value1": 20000, name: "John" },
23
- {"date": 1233,"value": 4},
24
- {"date": 1234, "value": 1000},
25
- {"date": 1235,"value": 888810000}
26
- ]
27
- `,subCommand:[]},{name:"asc",version:"0.0.1",example:"memorio.array.asc([array])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,description:"Sort an array in ascending order.",subCommand:[]},{name:"desc",version:"0.0.1",example:"memorio.array.desc([array])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,description:"Sort an array in descending order.",subCommand:[]},{name:"duplicates",version:"0.0.1",example:"memorio.array.duplicates([array])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,description:"Find duplicate items in an array.",subCommand:[]},{name:"even",version:"0.0.1",example:"memorio.array.even([array])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,description:"Filter even numbers from an array.",subCommand:[]},{name:"odd",version:"0.0.1",example:"memorio.array.odd([array])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20210101",type:"function",active:!0,description:"Filter odd numbers from an array.",subCommand:[]},{name:"sumColumn",version:"0.0.1",example:"memorio.array.sumColumn([array, column])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20230111",type:"function",active:!0,description:`
28
- Sum the values of a specified column in a multidimensional array.
29
- Example:
30
- const array = [
31
- [12, 23, 34],
32
- [45, 56, 67],
33
- [78, 89, 90]
34
- ]
35
- console.debug(memorio.array.sumColumn(array, 0)) // Result: 135
36
- `,subCommand:[]},{name:"shuffle",version:"0.0.1",example:"memorio.array.shuffle([array])",author:"Dario Passariello",creationDate:"20230527",lastMod:"20230527",type:"function",active:!0,description:"Shuffle the elements of an array.",subCommand:[]},{name:"generate",version:"0.0.1",example:"memorio.array.generate(num)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20230527",type:"function",active:!0,description:"Generate an array of random numbers (max 500000).",subCommand:[]},{name:"testArrayInt",version:"0.0.1",example:"memorio.array.testArrayInt([array])",author:"Dario Passariello",creationDate:"20230527",lastMod:"20230527",type:"function",active:!0,description:`
37
- Test if an array contains consecutive integers.
38
- Examples:
39
- console.debug(memorio.array.testArrayInt([1,2,3,4,6,7])) // Result: [5]
40
- `,subCommand:[]},{name:"rand32",version:"0.0.1",example:"memorio.array.rand32(num)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20230527",type:"function",active:!0,description:`
41
- Generate an array of random 32-bit unsigned integers.
42
- Example:
43
- console.debug(memorio.array.rand32(500000))
44
- `,subCommand:[]},{name:"deepClone",version:"0.0.1",example:"memorio.array.deepClone(array|object)",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
45
- Generate a deep clone of an array or object.
46
- Example:
47
- memorio.array.deepClone([array|object])
48
- `,subCommand:[]},{name:"match",version:"0.0.1",example:"memorio.array.match([arrayOfWords, arrayToCheck])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
49
- Find a perfect match between an array of words and an array to check.
50
- Example:
51
- memorio.array.match([arrayOfWords, arrayToCheck])
52
- `,subCommand:[]},{name:"shallow",version:"0.0.1",example:"memorio.array.shallow([array])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
53
- Generate a shallow copy of an array
54
- Example: memorio.array.shallow([array])
55
- `,subCommand:[]},{name:"deepCopy",version:"0.0.1",example:"memorio.array.deepCopy([array])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
56
- Generate a deepCopy of an array
57
- Example: memorio.array.deepCopy([array])
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:`
59
- Generate groups of array by a specific key
60
- Example: memorio.array.groupBy([array, key])
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();})();
1
+ "use strict";(()=>{var u=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var f=(e,r)=>()=>(e&&(r=e(e=0)),r);var n=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var w=(e,r,l,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of P(r))!S.call(e,t)&&t!==l&&u(e,t,{get:()=>r[t],enumerable:!(s=O(r,t))||s.enumerable});return e};var E=e=>w(u({},"__esModule",{value:!0}),e);var g,b=f(()=>{g={name:"memorio",version:"0.2.1",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 I={};var m=f(()=>{"use strict";b();Object.defineProperty(global,"memorio",{value:{},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(global,"events",{value:{},writable:!0,configurable:!1,enumerable:!1});Object.defineProperty(memorio,"version",{writable:!1,configurable:!1,enumerable:!1,value:g.version})});var d=n(()=>{"use strict";Object.defineProperty(memorio,"dispatch",{writable:!1,configurable:!1,enumerable:!1,value:{set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,l=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let s=t=>r?setTimeout(()=>r(t),1):null;window.addEventListener(e,s),global.events[e]=s},remove:e=>{window.removeEventListener(e,global.events[e]),delete global.events[e]}}})});var y=n(()=>{"use strict";Object.defineProperty(memorio,"objPath",{writable:!1,configurable:!1,enumerable:!1,value:(e,r,l=".")=>r.concat(e).join(l)});var p=(e,r,l=[])=>{let s=t=>{let o=t.split(".");o.forEach((a,i)=>{let c=o.slice(0,i+1).join(".");global.memorio.dispatch.set(c,{detail:{name:c}})})};return new Proxy(e,{get(t,o){if(Object.isFrozen(t[o]))return t[o];try{let a=Reflect.get(t,o);return a&&typeof a=="object"&&["Array","Object"].includes(a.constructor.name)?p(a,r,l.concat(o)):a}catch(a){return console.error("Error: ",a),!1}},set(t,o,a){if(t[o]&&typeof t[o]=="object"&&Object.isFrozen(t[o])){console.error(`Error: state '${o}' is locked`);return}try{let i=global.memorio.objPath(o,l);return r({action:"set",path:i,target:t,newValue:a,previousValue:Reflect.get(t,o)}),s("state."+i),Reflect.set(t,o,a),t[o]&&typeof t[o]=="object"&&Reflect.defineProperty(t[o],"lock",{value(){Object.defineProperty(t,o,{writable:!1,enumerable:!1}),Object.freeze(t[o])}}),!0}catch(i){return console.error("Error in set trap:",i),!1}},deleteProperty(t,o){try{let a=global.memorio.objPath(o,l);return r({action:"delete",path:a,target:t}),Reflect.deleteProperty(t,o)}catch(a){return console.error("Error in deleteProperty trap:",a),!1}}})};global?.state?global.state=state:global.state=p({},()=>{});var v=new WeakSet;v.add(state);setInterval(()=>{if(!v.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 h=n(()=>{"use strict";global.observer||(global.observer=null);Object.defineProperty(global,"observer",{enumerable:!1});observer=(e,r=null,l=!0)=>{if((t=>t.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${t}' 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,l);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 j=n(()=>{"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(l){console.error(`Error setting store item '${e}':`,l)}}},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 l=localStorage.getItem(r);l&&(e+=l.length)}return e}}});Object.freeze(store)});m();d();y();h();j();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memorio",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Memorio, State + Observer and Store for a easy life ",
5
5
  "license": "MIT",
6
6
  "deprecated": false,