memorio 1.2.5 → 1.2.6
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/LICENSE.md +21 -0
- package/index.js +1 -1
- package/package.json +1 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 1995-2025 by Dario Passariello
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var c={name:"memorio",version:"1.2.
|
|
1
|
+
"use strict";(()=>{var c={name:"memorio",version:"1.2.6",type:"module",main:"index.js",types:"index.d.ts",typings:"./types/*",description:"Memorio, State + Observer and Store for a easy life ",license:"MIT",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"},contributors:[{name:"Dario Passariello",email:"dariopassarielloa@gmail.com"},{name:"Valeria Cala Scaglitta",email:"valeriacalascaglitta@gmail.com"}],keywords:["biglogic","a51","memorio","state","store","observer","useObserver","dario","passariello"],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","-----------":"",test:"set NODE_OPTIONS=--experimental-vm-modules && jest","test:watch":"set NODE_OPTIONS=--experimental-vm-modules && jest --watch","test:coverage":"set NODE_OPTIONS=--experimental-vm-modules && jest --coverage","test:watchAll":"set NODE_OPTIONS=--experimental-vm-modules && jest --watchAll","------------":"","npm:publish":"npm run build && npm publish ./dist"},dependencies:{"dphelper.types":"0.0.20"},devDependencies:{"@eslint/js":"9.39.1","@types/jest":"30.0.0","@types/node":"^24.10.1","@typescript-eslint/eslint-plugin":"8.47.0","@typescript-eslint/parser":"8.47.0",esbuild:"^0.27.0","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.39.1",jest:"30.2.0","jest-environment-jsdom":"30.2.0","ts-jest":"29.4.5","ts-loader":"^9.5.4","ts-node":"10.9.2",tslib:"^2.8.1",typescript:"5.9.3"}};Object.defineProperty(globalThis,"memorio",{value:{},writable:!1,configurable:!0,enumerable:!1});Object.defineProperty(globalThis,"events",{value:{},writable:!0,enumerable:!1});Object.defineProperty(memorio,"version",{writable:!1,enumerable:!1,value:c.version});var u=["list","state","store","observer","useObserver","remove","removeAll"];Object.defineProperty(memorio,"dispatch",{writable:!1,enumerable:!1,value:{set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,i=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let n=t=>r?setTimeout(()=>r(t),1):null;globalThis.addEventListener(e,n),globalThis.events[e]=n},remove:e=>{globalThis.removeEventListener(e,globalThis.events[e]),delete globalThis.events[e]}}});Object.defineProperty(memorio,"objPath",{writable:!1,enumerable:!1,value:(e,r,i=".")=>r.concat(e).join(i)});var f=(e,r,i=[])=>{let n=t=>{let o=t.split(".");o.forEach((s,l)=>{let a=o.slice(0,l+1).join(".");globalThis.memorio.dispatch.set(a,{detail:{name:a}})})};return new Proxy(e,{get(t,o){if(o==="list")return console.log('Some state could be hidden when you use "state.list". Use "state" to see the complete list '),JSON.parse(JSON.stringify(state));if(o==="remove")return function(s){return delete t[s],!0};if(o==="removeAll")return function(){try{for(let s in t)typeof t[s]!="function"&&!["list","remove","removeAll"].includes(s)&&(Object.isFrozen(t[s])||delete t[s],delete t[s])}catch(s){console.error(s)}};if(Object.isFrozen(t[o]))return t[o];try{let s=Reflect.get(t,o);return s&&typeof s=="object"&&["Array","Object"].includes(s.constructor.name)?f(s,r,i.concat(o)):s}catch(s){console.error("Error: ",s);return}},set(t,o,s){if(u.includes(o))return console.error("key "+o+" is protected"),!1;if(t[o]&&typeof t[o]=="object"&&Object.isFrozen(t[o]))return console.error(`Error: state '${o}' is locked`),!1;try{let l=globalThis.memorio.objPath(o,i);return r({action:"set",path:l,target:t,newValue:s,previousValue:Reflect.get(t,o)}),n("state."+l),Reflect.set(t,o,s),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(l){console.error("Error in set trap:",l);return}},deleteProperty(t,o){try{let s=globalThis.memorio.objPath(o,i);return r({action:"delete",path:s,target:t}),Reflect.deleteProperty(t,o)}catch(s){console.error("Error in deleteProperty trap:",s);return}}})};globalThis?.state?globalThis.state=state:globalThis.state=f({},()=>{});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:!0});globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1,configurable:!0});observer=(e,r=null,i=!0)=>{try{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))return}catch(n){console.error(n);return}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){globalThis.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}globalThis.memorio.dispatch.listen(e,r,i);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);globalThis.useObserver||(globalThis.useObserver=null);Object.defineProperty(globalThis,"useObserver",{enumerable:!1,configurable:!0});useObserver=(e,r)=>{try{return observer(r,()=>e()),!0}catch(i){console.error(i);return}};Object.freeze(useObserver);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!0});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)}return null}}},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(i){console.error(`Error setting store item '${e}':`,i)}return null}}},remove:{value(e){if(e)return localStorage.getItem(e)?(localStorage.removeItem(e),!0):!1}},delete:{value(e){return store.remove(e),!0}},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.`),[e/1024,r/1024])).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let r in localStorage)if(localStorage.hasOwnProperty(r)){let i=localStorage.getItem(r);i&&(e+=i.length)}return e}}});Object.freeze(store);Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:!1,configurable:!0});Object.defineProperties(session,{get:{value(e){if(e)try{let r=sessionStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.error(`Error parsing session item '${e}':`,r)}}},set:{value(e,r){if(e)try{r==null?sessionStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?sessionStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.error("It's not secure to session functions.")}catch(i){console.error(`Error setting session item '${e}':`,i)}}},remove:{value(e){if(e&&sessionStorage.getItem(e))return sessionStorage.removeItem(e),!0}},delete:{value(e){return session.remove(e),!0}},removeAll:{value(){return sessionStorage.clear(),!0}},clearAll:{value(){return session.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 sessionStorage)if(sessionStorage.hasOwnProperty(r)){let i=sessionStorage.getItem(r);i&&(e+=i.length)}return e}}});Object.freeze(session);Object.defineProperty(window,"cache",{value:new Proxy({},{}),enumerable:!1,configurable:!0});})();
|