memorio 0.2.19 → 1.0.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.
Files changed (107) hide show
  1. package/.editorconfig +31 -0
  2. package/.gitattributes +1 -0
  3. package/.private/npm +1 -0
  4. package/.vscode/extension.json +15 -0
  5. package/.vscode/settings.json +90 -0
  6. package/config/dispatch.ts +49 -0
  7. package/config/global.ts +36 -0
  8. package/coverage/clover.xml +260 -0
  9. package/coverage/coverage-final.json +10 -0
  10. package/coverage/lcov-report/a51.memorio/config/dispatch.ts.html +232 -0
  11. package/coverage/lcov-report/a51.memorio/config/global.ts.html +193 -0
  12. package/coverage/lcov-report/a51.memorio/config/index.html +131 -0
  13. package/coverage/lcov-report/a51.memorio/dist/config/dispatch.js.html +157 -0
  14. package/coverage/lcov-report/a51.memorio/dist/config/global.js.html +142 -0
  15. package/coverage/lcov-report/a51.memorio/dist/config/index.html +131 -0
  16. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.html +116 -0
  17. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.js.html +103 -0
  18. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.html +116 -0
  19. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.js.html +280 -0
  20. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.html +116 -0
  21. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.js.html +460 -0
  22. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.html +116 -0
  23. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.js.html +367 -0
  24. package/coverage/lcov-report/a51.memorio/dist/index.html +116 -0
  25. package/coverage/lcov-report/a51.memorio/dist/init.js.html +106 -0
  26. package/coverage/lcov-report/a51.memorio/functions/cache/index.html +116 -0
  27. package/coverage/lcov-report/a51.memorio/functions/cache/index.ts.html +142 -0
  28. package/coverage/lcov-report/a51.memorio/functions/observer/index.html +116 -0
  29. package/coverage/lcov-report/a51.memorio/functions/observer/index.ts.html +448 -0
  30. package/coverage/lcov-report/a51.memorio/functions/session/index.html +116 -0
  31. package/coverage/lcov-report/a51.memorio/functions/session/index.ts.html +409 -0
  32. package/coverage/lcov-report/a51.memorio/functions/state/index.html +116 -0
  33. package/coverage/lcov-report/a51.memorio/functions/state/index.ts.html +682 -0
  34. package/coverage/lcov-report/a51.memorio/functions/store/index.html +116 -0
  35. package/coverage/lcov-report/a51.memorio/functions/store/index.ts.html +409 -0
  36. package/coverage/lcov-report/a51.memorio/index.html +131 -0
  37. package/coverage/lcov-report/a51.memorio/index.ts.html +88 -0
  38. package/coverage/lcov-report/a51.memorio/init.ts.html +115 -0
  39. package/coverage/lcov-report/base.css +224 -0
  40. package/coverage/lcov-report/block-navigation.js +87 -0
  41. package/coverage/lcov-report/favicon.png +0 -0
  42. package/coverage/lcov-report/index.html +206 -0
  43. package/coverage/lcov-report/prettify.css +1 -0
  44. package/coverage/lcov-report/prettify.js +2 -0
  45. package/coverage/lcov-report/session/index.html +116 -0
  46. package/coverage/lcov-report/session/index.ts.html +571 -0
  47. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  48. package/coverage/lcov-report/sorter.js +210 -0
  49. package/coverage/lcov-report/state/index.html +116 -0
  50. package/coverage/lcov-report/state/index.ts.html +1090 -0
  51. package/coverage/lcov-report/store/index.html +116 -0
  52. package/coverage/lcov-report/store/index.ts.html +556 -0
  53. package/coverage/lcov.info +518 -0
  54. package/dist/README.md +319 -0
  55. package/dist/index.d.ts +7 -0
  56. package/dist/index.js +1 -0
  57. package/dist/package.json +98 -0
  58. package/dist/types/cache.d.ts +27 -0
  59. package/dist/types/memorio.d.ts +18 -0
  60. package/dist/types/observer.d.ts +47 -0
  61. package/dist/types/session.d.ts +91 -0
  62. package/dist/types/state.d.ts +71 -0
  63. package/dist/types/store.d.ts +91 -0
  64. package/esbuild.config.mjs +54 -0
  65. package/eslint.config.mjs +174 -0
  66. package/examples/bg.jpg +0 -0
  67. package/examples/bootstrap.less +92 -0
  68. package/examples/favicon.ico +0 -0
  69. package/examples/index.htm +65 -0
  70. package/examples/javascript.js +2 -0
  71. package/examples/responsive.less +47 -0
  72. package/examples/styles.less +169 -0
  73. package/functions/cache/index.ts +19 -0
  74. package/functions/observer/index.ts +121 -0
  75. package/functions/session/index.ts +108 -0
  76. package/functions/state/index.ts +199 -0
  77. package/functions/store/index.ts +108 -0
  78. package/index.ts +1 -0
  79. package/init.ts +12 -0
  80. package/jest.config.mjs +33 -0
  81. package/jest.setup.js +2 -0
  82. package/package.json +4 -10
  83. package/tests/basic.test.ts +50 -0
  84. package/tests/cache.test.ts +52 -0
  85. package/tests/observer.test.ts +62 -0
  86. package/tests/setup.ts +48 -0
  87. package/tests/state.test.ts +45 -0
  88. package/tests/store.test.ts +62 -0
  89. package/tsconfig.json +67 -0
  90. package/index.js +0 -1
  91. /package/{CHANGELOG.md → .github/CHANGELOG.md} +0 -0
  92. /package/{CITATION.cff → .github/CITATION.cff} +0 -0
  93. /package/{CODEOWNERS → .github/CODEOWNERS} +0 -0
  94. /package/{CODE_OF_CONDUCT.md → .github/CODE_OF_CONDUCT.md} +0 -0
  95. /package/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
  96. /package/{COPYRIGHT.md → .github/COPYRIGHT.md} +0 -0
  97. /package/{FUNDING.yml → .github/FUNDING.yml} +0 -0
  98. /package/{HISTORY.md → .github/HISTORY.md} +0 -0
  99. /package/{LICENSE.md → .github/LICENSE.md} +0 -0
  100. /package/{README.md → .github/README.md} +0 -0
  101. /package/{SECURITY.md → .github/SECURITY.md} +0 -0
  102. /package/{SUMMARY.md → .github/SUMMARY.md} +0 -0
  103. /package/{dependabot.yml → .github/dependabot.yml} +0 -0
  104. /package/{documents → .github/documents}/OBSERVER.md +0 -0
  105. /package/{documents → .github/documents}/STATE.md +0 -0
  106. /package/{documents → .github/documents}/STORE.md +0 -0
  107. /package/{pull_request_template.md → .github/pull_request_template.md} +0 -0
package/dist/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # Memorio
2
+
3
+ > A lightweight, type-safe state management library for modern JavaScript applications
4
+
5
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.9.2-blue?logo=typescript)
6
+ ![Node.js](https://img.shields.io/badge/Node.js-24.3.0-green?logo=node.js)
7
+ ![Jest](https://img.shields.io/badge/Jest-30.0.5-red?logo=jest)
8
+ ![ESLint](https://img.shields.io/badge/ESLint-9.34.0-purple?logo=eslint)
9
+ ![esbuild](https://img.shields.io/badge/esbuild-0.25.9-yellow?logo=esbuild)
10
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg)
11
+ ![Version](https://img.shields.io/badge/version-0.2.15-orange)
12
+
13
+ ![Tests](https://img.shields.io/badge/tests-passing-brightgreen)
14
+ ![Coverage](https://img.shields.io/badge/coverage-25%20passed-success)
15
+
16
+ ## 📋 Table of Contents
17
+
18
+ - [Features](#features)
19
+ - [Installation](#installation)
20
+ - [Quick Start](#quick-start)
21
+ - [API Reference](#api-reference)
22
+ - [State Management](#state-management)
23
+ - [Observer Pattern](#observer-pattern)
24
+ - [Store](#store)
25
+ - [Session](#session)
26
+ - [Testing](#testing)
27
+ - [Security](#security)
28
+ - [License](#license)
29
+
30
+ ## ✨ Features
31
+
32
+ - 🔄 Reactive state management with observer pattern
33
+ - 💾 Persistent storage with Store API
34
+ - ⚡ Session management for temporary data
35
+ - 🔒 Type-safe with full TypeScript support
36
+ - 🧪 Comprehensive test coverage
37
+ - 🎯 Zero dependencies
38
+ - 🔍 Easy debugging with proxy-based state
39
+
40
+ ## 📦 Installation
41
+
42
+ ```bash
43
+ npm install memorio
44
+ # or
45
+ yarn add memorio
46
+ # or
47
+ pnpm add memorio
48
+ ```
49
+
50
+ ✅ All test suites are passing:
51
+
52
+ - Basic functionality tests
53
+ - State management tests
54
+ - Store operations tests
55
+ - Cache operations tests
56
+ - Observer pattern tests
57
+
58
+ Total: 25 tests passed across 5 test suites
59
+
60
+ ## 🚀 Quick Start
61
+
62
+ ```javascript
63
+ import 'memorio';
64
+
65
+ // State Management
66
+ state.counter = 0;
67
+ state.user = { name: 'John', age: 30 };
68
+
69
+ // Observer Pattern
70
+ observer('state.counter', (newValue, oldValue) => {
71
+ console.log(`Counter changed from ${oldValue} to ${newValue}`);
72
+ });
73
+
74
+ // Store (Persistent Storage)
75
+ store.set('preferences', { theme: 'dark' });
76
+ const preferences = store.get('preferences');
77
+
78
+ // Session Storage
79
+ session.set('token', 'user-jwt-token');
80
+ const token = session.get('token');
81
+ ```
82
+
83
+ ## 📖 API Reference
84
+
85
+ ### State Management
86
+
87
+ State in Memorio is globally accessible and reactive:
88
+
89
+ ```javascript
90
+ // Setting state
91
+ state.user = { name: 'John' };
92
+
93
+ // Getting state
94
+ const userName = state.user.name;
95
+
96
+ // Listing all states
97
+ console.log(state.list);
98
+
99
+ // Locking state (for Objects or Arrays)
100
+ state.user.lock();
101
+
102
+ // Removing state
103
+ state.remove('user');
104
+
105
+ // Clearing all states
106
+ state.removeAll();
107
+
108
+ ```
109
+
110
+ ### Observer Pattern
111
+
112
+ Observe state changes with React-like syntax:
113
+
114
+ ```javascript
115
+ // Basic observer
116
+ observer('state.user', (newValue, oldValue) => {
117
+ console.log('User updated:', newValue);
118
+ });
119
+
120
+ // With React useState
121
+ const [user, setUser] = useState();
122
+ observer('state.user', () => {
123
+ setUser(state.user);
124
+ });
125
+
126
+ // With React useEffect
127
+ useEffect(() => {
128
+ console.log('User changed:', state.user);
129
+ }, [state.user]);
130
+ ```
131
+
132
+ ### Another example of use of Observer
133
+
134
+ ```js
135
+ import 'memorio';
136
+
137
+ // Use the observer to log the changing state value
138
+ observer(
139
+ 'state.count',
140
+ () => console.log("State changed: ", state.count)
141
+ );
142
+
143
+ // Store a value in the state that changes every 5 seconds
144
+ setInterval(() => state.count = Date.now(), 5000);
145
+ ```
146
+
147
+ ---
148
+
149
+ ## STORE
150
+
151
+ ```js
152
+ // Set a store:
153
+ store.set("test", { test: "test" })
154
+
155
+ // Get a store:
156
+ store.get("test") // Output: { test: "test" }
157
+
158
+ // Remove a store:
159
+ store.remove("test") // Output: "ok"
160
+
161
+ // Remove all stores:
162
+ store.removeAll() // Output: "ok"
163
+ ```
164
+
165
+ ### Store
166
+
167
+ Persistent storage for your application:
168
+
169
+ ```javascript
170
+ // Setting values
171
+ store.set('config', { theme: 'dark', language: 'en' });
172
+
173
+ // Getting values
174
+ const config = store.get('config');
175
+
176
+ // Removing specific value
177
+ store.remove('config');
178
+
179
+ // Getting store size
180
+ const size = store.size();
181
+
182
+ // Clearing store
183
+ store.removeAll();
184
+ ```
185
+
186
+ ### Session
187
+
188
+ Temporary storage that persists during page sessions:
189
+
190
+ ```javascript
191
+ // Setting session data
192
+ session.set('userSession', {
193
+ id: 'user123',
194
+ lastActive: Date.now()
195
+ });
196
+
197
+ // Getting session data
198
+ const userData = session.get('userSession');
199
+
200
+ // Checking session size
201
+ const activeItems = session.size();
202
+
203
+ // Removing session data
204
+ session.remove('userSession');
205
+
206
+ // Clearing all session data
207
+ session.removeAll();
208
+
209
+ // Remove all stored data if necessary
210
+ // store.removeAll();
211
+
212
+ return (
213
+ <div>
214
+ <h1 id="name">...</h1>
215
+ </div>
216
+ );
217
+ }
218
+
219
+ export default App;
220
+ ```
221
+
222
+ ---
223
+
224
+ ## SESSION
225
+
226
+ Session storage provides a way to store data for the duration of a page session. The data persists as long as the browser is open and survives over page reloads, but is lost when the browser tab or window is closed.
227
+
228
+ ```js
229
+ // Set a session value:
230
+ session.set("userId", "12345")
231
+
232
+ // Get a session value:
233
+ session.get("userId") // Output: "12345"
234
+
235
+ // Remove a specific session value:
236
+ session.remove("userId")
237
+
238
+ // Get the number of items in session:
239
+ session.size() // Output: number of stored items
240
+
241
+ // Remove all session values:
242
+ session.removeAll()
243
+ ```
244
+
245
+ ### Example use Session in React
246
+
247
+ ```js
248
+ import { useEffect } from 'react';
249
+ import 'memorio';
250
+
251
+ function UserSession() {
252
+ useEffect(() => {
253
+ // Store user session data
254
+ session.set('userSession', {
255
+ id: '12345',
256
+ lastActive: Date.now(),
257
+ preferences: {
258
+ theme: 'dark',
259
+ language: 'en'
260
+ }
261
+ });
262
+
263
+ // Retrieve session data
264
+ const userData = session.get('userSession');
265
+ console.log('User session:', userData);
266
+
267
+ // Clean up on component unmount
268
+ return () => {
269
+ session.remove('userSession');
270
+ };
271
+ }, []);
272
+
273
+ return (
274
+ <div>
275
+ {/* Your component JSX */}
276
+ </div>
277
+ );
278
+ }
279
+
280
+ export default UserSession;
281
+ ```
282
+
283
+ ---
284
+
285
+ ## 🧪 Testing
286
+
287
+ ✅ All test suites are passing:
288
+
289
+ - Basic functionality tests
290
+ - State management tests
291
+ - Store operations tests
292
+ - Cache operations tests
293
+ - Observer pattern tests
294
+
295
+ Total: 25 tests passed across 5 test suites
296
+
297
+ ## 🔒 Security
298
+
299
+ Security scans and reports are available at:
300
+ - [Socket.dev](https://socket.dev/npm/package/memorio)
301
+ - [Snyk.io](https://security.snyk.io/package/npm/memorio)
302
+
303
+ ## 📄 License
304
+
305
+ MIT © [Dario Passariello](https://dario.passariello.ca/)
306
+
307
+ ---
308
+
309
+ ## 🤝 Contributing
310
+
311
+ Contributions are welcome! Please feel free to submit a Pull Request.
312
+
313
+ ## 📧 Support
314
+
315
+ Need help? Feel free to [open an issue](https://github.com/a51-dev/a51.memorio/issues).
316
+
317
+ ---
318
+
319
+ Created with ❤️ by [Dario Passariello](https://dario.passariello.ca/) - Copyright © 2025
@@ -0,0 +1,7 @@
1
+
2
+ /// <reference path="./types/memorio.d.ts" />
3
+ /// <reference path="./types/observer.d.ts" />
4
+ /// <reference path="./types/state.d.ts" />
5
+ /// <reference path="./types/session.d.ts" />
6
+ /// <reference path="./types/store.d.ts" />
7
+ /// <reference path="./types/cache.d.ts" />
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var c={name:"memorio",version:"1.0.0",type:"module",main:"index.js",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",tsc:"tsc -b .",eslint:"eslint .",updates:"npx npm-check-updates -u && npm i","----------":"","publish:npm":"npm run build && npm publish ./dist"},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","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/*"],dependencies:{"dphelper.types":"0.0.19"},devDependencies:{"@eslint/js":"9.34.0","@types/jest":"30.0.0","@types/node":"^24.3.0","@typescript-eslint/eslint-plugin":"8.41.0","@typescript-eslint/parser":"8.41.0","dphelper.types":"0.0.19",esbuild:"^0.25.9","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.34.0",jest:"30.0.5","jest-environment-jsdom":"30.0.5","ts-jest":"29.4.1","ts-loader":"^9.5.4","ts-node":"10.9.2",tslib:"^2.8.1",typescript:"5.9.2"}};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,"version",{writable:!1,configurable:!1,enumerable:!1,value:c.version});Object.defineProperty(memorio,"dispatch",{writable:!1,configurable:!1,enumerable:!1,value:{set:(e,t={})=>{dispatchEvent(new CustomEvent(String(e),t))},listen:(e,t=null,i=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let l=r=>t?setTimeout(()=>t(r),1):null;globalThis.addEventListener(e,l),globalThis.events[e]=l},remove:e=>{globalThis.removeEventListener(e,globalThis.events[e]),delete globalThis.events[e]}}});Object.defineProperty(memorio,"objPath",{writable:!1,configurable:!1,enumerable:!1,value:(e,t,i=".")=>t.concat(e).join(i)});var u=(e,t,i=[])=>{let l=r=>{let o=r.split(".");o.forEach((s,n)=>{let a=o.slice(0,n+1).join(".");globalThis.memorio.dispatch.set(a,{detail:{name:a}})})};return new Proxy(e,{get(r,o){if(o==="list"){let s={};for(let n in r)typeof r[n]!="function"&&!["list","remove","removeAll"].includes(n)&&(s[n]=r[n]);return s}if(o==="remove")return function(s){return s in r&&!["list","remove","removeAll"].includes(s)?(delete r[s],!0):!1};if(o==="removeAll")return function(){for(let s in r)typeof r[s]!="function"&&!["list","remove","removeAll"].includes(s)&&delete r[s];return!0};if(Object.isFrozen(r[o]))return r[o];try{let s=Reflect.get(r,o);return s&&typeof s=="object"&&["Array","Object"].includes(s.constructor.name)?u(s,t,i.concat(o)):s}catch(s){console.error("Error: ",s);return}},set(r,o,s){if(r[o]&&typeof r[o]=="object"&&Object.isFrozen(r[o])){console.error(`Error: state '${o}' is locked`);return}try{let n=globalThis.memorio.objPath(o,i);return t({action:"set",path:n,target:r,newValue:s,previousValue:Reflect.get(r,o)}),l("state."+n),Reflect.set(r,o,s),r[o]&&typeof r[o]=="object"&&Reflect.defineProperty(r[o],"lock",{value(){Object.defineProperty(r,o,{writable:!1,enumerable:!1}),Object.freeze(r[o])}}),!0}catch(n){return console.error("Error in set trap:",n),!1}},deleteProperty(r,o){try{let s=globalThis.memorio.objPath(o,i);return t({action:"delete",path:s,target:r}),Reflect.deleteProperty(r,o)}catch(s){return console.error("Error in deleteProperty trap:",s),!1}}})},g={};globalThis?.state?globalThis.state=state:globalThis.state=u(g,()=>{});var f=new WeakSet;f.add(state);setInterval(()=>{if(!f.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});globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1});observer=(e,t=null,i=!0)=>{if((r=>r.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${r}' string is incorrect!`),!1):!0)(e)){if(!e&&!t){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&t){console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'.");return}if(e&&!t){globalThis.memorio.dispatch.listen(String(e),{detail:{name:String(e)}}),console.debug("called: ",e);return}if(e&&t){if(typeof e!="string"||typeof t!="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,t,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);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(store,{get:{value(e){if(e)try{let t=localStorage.getItem(e);return t&&JSON.parse(t)}catch(t){console.error(`Error parsing store item '${e}':`,t)}}},set:{value(e,t){if(e)try{t==null?localStorage.setItem(e,JSON.stringify(null)):typeof t=="object"||typeof t=="number"||typeof t=="boolean"||typeof t=="string"?localStorage.setItem(e,JSON.stringify(t)):typeof t=="function"&&console.error("It's not secure to store functions.")}catch(i){console.error(`Error setting store item '${e}':`,i)}}},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:t})=>{e&&t&&console.debug(`Using ${e/1024} out of ${t/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let t in localStorage)if(localStorage.hasOwnProperty(t)){let i=localStorage.getItem(t);i&&(e+=i.length)}return e}}});Object.freeze(store);Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(session,{get:{value(e){if(e)try{let t=sessionStorage.getItem(e);return t&&JSON.parse(t)}catch(t){console.error(`Error parsing session item '${e}':`,t)}}},set:{value(e,t){if(e)try{t==null?sessionStorage.setItem(e,JSON.stringify(null)):typeof t=="object"||typeof t=="number"||typeof t=="boolean"||typeof t=="string"?sessionStorage.setItem(e,JSON.stringify(t)):typeof t=="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){session.remove(e)}},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:t})=>{e&&t&&console.debug(`Using ${e/1024} out of ${t/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let t in sessionStorage)if(sessionStorage.hasOwnProperty(t)){let i=sessionStorage.getItem(t);i&&(e+=i.length)}return e}}});Object.freeze(session);Object.defineProperty(window,"cache",{value:new Proxy({},{}),enumerable:!1,configurable:!1});})();
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "memorio",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "node ./esbuild.config.mjs",
8
+ "watch": "esbuild init.ts --bundle --outdir=dist --serve",
9
+ "-----------": "",
10
+ "test": "set NODE_OPTIONS=--experimental-vm-modules && jest",
11
+ "test:watch": "set NODE_OPTIONS=--experimental-vm-modules && jest --watch",
12
+ "test:coverage": "set NODE_OPTIONS=--experimental-vm-modules && jest --coverage",
13
+ "test:watchAll": "set NODE_OPTIONS=--experimental-vm-modules && jest --watchAll",
14
+ "tsc": "tsc -b .",
15
+ "eslint": "eslint .",
16
+ "updates": "npx npm-check-updates -u && npm i",
17
+ "----------": "",
18
+ "publish:npm": "npm run build && npm publish ./dist"
19
+ },
20
+ "types": "index.d.ts",
21
+ "typings": "./types/*",
22
+ "description": "Memorio, State + Observer and Store/Session for a easy life ",
23
+ "license": "MIT",
24
+ "copyright": "Dario Passariello, BigLogic ca - a51.dev is a BigLogic project",
25
+ "homepage": "https://a51.gitbook.io/memorio",
26
+ "author": {
27
+ "name": "Dario Passariello",
28
+ "url": "https://dario.passariello.ca/",
29
+ "email": "dariopassariello@gmail.com"
30
+ },
31
+ "support": {
32
+ "name": "Dario Passariello",
33
+ "url": "https://github.com/passariello/",
34
+ "email": "dariopassariello@gmail.com"
35
+ },
36
+ "contributors": [
37
+ {
38
+ "name": "Dario Passariello",
39
+ "email": "dariopassarielloa@gmail.com"
40
+ },
41
+ {
42
+ "name": "Valeria Cala Scaglitta",
43
+ "email": "valeriacalascaglitta@gmail.com"
44
+ }
45
+ ],
46
+ "keywords": [
47
+ "memorio",
48
+ "state",
49
+ "store",
50
+ "session",
51
+ "observer",
52
+ "dario",
53
+ "passariello",
54
+ "context",
55
+ "react",
56
+ "biglogic",
57
+ "a51"
58
+ ],
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/a51-dev/a51.memorio.git",
62
+ "help": "https://github.com/a51-dev/a51.memorio#readme"
63
+ },
64
+ "bugs": {
65
+ "url": "https://github.com/a51-dev/a51.memorio/issues"
66
+ },
67
+ "funding": [
68
+ {
69
+ "type": "patreon",
70
+ "url": "https://www.patreon.com/passariello"
71
+ }
72
+ ],
73
+ "typing": [
74
+ "types/*"
75
+ ],
76
+ "dependencies": {
77
+ "dphelper.types": "0.0.19"
78
+ },
79
+ "devDependencies": {
80
+ "@eslint/js": "9.34.0",
81
+ "@types/jest": "30.0.0",
82
+ "@types/node": "^24.3.0",
83
+ "@typescript-eslint/eslint-plugin": "8.41.0",
84
+ "@typescript-eslint/parser": "8.41.0",
85
+ "dphelper.types": "0.0.19",
86
+ "esbuild": "^0.25.9",
87
+ "esbuild-plugin-clean": "^1.0.1",
88
+ "esbuild-plugin-copy": "^2.1.1",
89
+ "eslint": "9.34.0",
90
+ "jest": "30.0.5",
91
+ "jest-environment-jsdom": "30.0.5",
92
+ "ts-jest": "29.4.1",
93
+ "ts-loader": "^9.5.4",
94
+ "ts-node": "10.9.2",
95
+ "tslib": "^2.8.1",
96
+ "typescript": "5.9.2"
97
+ }
98
+ }
@@ -0,0 +1,27 @@
1
+ /*!
2
+ dphelper
3
+ Copyright (c) 2019 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under MIT License, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /**
9
+ * Cache is used for internal use only... but you can use if you need.
10
+ * @return Some stuff you cache... usually used for dynamic imports from dphelper.
11
+ */
12
+
13
+ interface _cache {
14
+
15
+ /**
16
+ * Create a cache, please use state instead!
17
+ *
18
+ * @example
19
+ * cache.myCache = any
20
+ *
21
+ * @since dphelper 1.0.6
22
+ */
23
+ [key: string]: any
24
+ }
25
+
26
+ declare var cache: _cache
27
+ type cache = _cache
@@ -0,0 +1,18 @@
1
+
2
+ interface _memorio {
3
+ setProps: any,
4
+ obj: any,
5
+ array: any,
6
+ dispatch: any,
7
+ setDescription: any
8
+ }
9
+
10
+ type memorio = _memorio
11
+ declare var memorio: any
12
+
13
+ type arguments = any
14
+ declare var arguments: any
15
+
16
+ global.memorio = global.memorio
17
+ ? global.memorio
18
+ : globalThis.memorio
@@ -0,0 +1,47 @@
1
+ /*!
2
+ memorio
3
+ Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under MIT License, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /**
9
+ * Observer run a callback anytime the associated state going to change
10
+ * @return Execution of function after state change.
11
+ */
12
+ interface _observer {
13
+
14
+ /**
15
+ * Generate your observer
16
+ *
17
+ * @example
18
+ * observer("myState", Function)
19
+ *
20
+ * @since memorio 1.0.6
21
+ */
22
+ (stateName: string, callBack: any): any
23
+
24
+ /**
25
+ * List of active observers
26
+ *
27
+ * @example
28
+ * observer.list()
29
+ *
30
+ * @since memorio 1.0.6
31
+ */
32
+ readonly list?: () => void
33
+
34
+ /**
35
+ * Remove the active observer (not the state)
36
+ *
37
+ * @example
38
+ * observer.remove("myState")
39
+ *
40
+ * @since memorio 1.0.6
41
+ */
42
+ readonly remove?: (name: string, callBack?: any, flag?: boolean) => void
43
+
44
+ }
45
+
46
+ declare var observer: _observer
47
+ type observer = _observer
@@ -0,0 +1,91 @@
1
+ /*!
2
+ memorio
3
+ Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under MIT License, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /**
9
+ * Create states using: session.set("example",{test:"test"})
10
+ */
11
+ interface _session {
12
+
13
+ /**
14
+ * Create a new session
15
+ *
16
+ * @example
17
+ * session.set("test","example") // or Array, Object, Number, Functions...
18
+ *
19
+ * @since memorio 0.0.1
20
+ * @param name The String as name to define the session.
21
+ * @param param The information taht you want to session (Any).
22
+ * @return boolean
23
+ */
24
+ set: (name: string, value: any) => void
25
+
26
+ /**
27
+ * Have back the data from a session.
28
+ *
29
+ * @example
30
+ * session.get("test")
31
+ *
32
+ * @since memorio 0.0.1
33
+ * @param name The String as name to define the session.
34
+ */
35
+ get: (name: string) => any
36
+
37
+ /**
38
+ * Delete an existing session:
39
+ *
40
+ * @example
41
+ * session.delete("test")
42
+ * session.remove("test")
43
+ *
44
+ * @since memorio 0.0.1
45
+ * @param name The String as name to define the session.
46
+ * @return boolean
47
+ */
48
+ delete: (name: string) => boolean | undefined
49
+ remove: (name: string) => boolean | undefined
50
+
51
+ /**
52
+ * Delete all storages
53
+ *
54
+ * @example
55
+ * session.clearAll()
56
+ * session.removeAll()
57
+ *
58
+ * @since memorio 0.0.1
59
+ * @return boolean
60
+ */
61
+ clearAll: () => boolean
62
+ removeAll: () => boolean
63
+
64
+ /**
65
+ * Know how much space you have for total storages
66
+ *
67
+ * @example
68
+ * session.quota()
69
+ *
70
+ * @since memorio 0.0.1
71
+ * @return values
72
+ */
73
+ quota: () => void
74
+
75
+ /**
76
+ * Get the size of sessions an the total
77
+ *
78
+ * @example
79
+ * session.size()
80
+ *
81
+ * @since memorio 0.0.1
82
+ * @return dimension in kb
83
+ */
84
+ size: () => number
85
+
86
+ // TODO
87
+ // readonly increaseQuota: (value: number) => void
88
+ }
89
+
90
+ declare var session: _session
91
+ type session = _session
@@ -0,0 +1,71 @@
1
+ /*!
2
+ memorio
3
+ Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under MIT License, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /**
9
+ * If you use only "state" you get the entire Proxy object
10
+ * @return Proxy Object of all states.
11
+ */
12
+ interface _state {
13
+
14
+ /**
15
+ * Create states using: state.test = "example"
16
+ *
17
+ * @example
18
+ * state.myStuff = any
19
+ *
20
+ * @since memorio 0.0.1
21
+ * @param key The name of the state for which you want to modify the action.
22
+ * @return The previous values (Any).
23
+ * Important: Object is a Proxy.
24
+ */
25
+ [key: string]: any
26
+
27
+ /**
28
+ * Delete entire state using: state.remove("test")
29
+ *
30
+ * @example
31
+ * state.remove(stateName)
32
+ *
33
+ * @since memorio 0.0.1
34
+ * @param stateName The name of the state for which you want to delete.
35
+ * @return boolean.
36
+ */
37
+ readonly remove?: (stateName: string) => any
38
+
39
+ /**
40
+ * List all states using: state.list
41
+ *
42
+ * @example
43
+ * state.removeAll()
44
+ *
45
+ * @since memorio 1.8.92
46
+ * @return Remove all states.
47
+ */
48
+ readonly removeAll?: () => any
49
+
50
+ /**
51
+ * List all states using: state.list
52
+ *
53
+ * @example
54
+ * state.list
55
+ *
56
+ * @since memorio 0.0.1
57
+ * @return Object of all states (Not the Proxy).
58
+ */
59
+ readonly list?: (stateName: string) => any
60
+
61
+ /**
62
+ * Generate a message for "memorio"
63
+ * Note: FOR INTERNAL USE ONLY.
64
+ * @since memorio 0.0.1
65
+ */
66
+ readonly mex?: any
67
+
68
+ }
69
+
70
+ declare var state: _state
71
+ type state = _state