memorio 0.1.7 → 0.1.8

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/CONTRIBUTING.md CHANGED
@@ -26,17 +26,17 @@ All types of contributions are encouraged and valued. See the [Table of Contents
26
26
 
27
27
  ## Code of Conduct
28
28
 
29
- This project and everyone participating in it is governed by the [memorio Code of Conduct](https://github.com/a51-dev/a51.memorio.public/blob/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [dariopassariello@gmail.com](mailto:dariopassariello@gmail.com).
29
+ This project and everyone participating in it is governed by the [memorio Code of Conduct](https://github.com/a51-dev/a51.memorio/blob/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [dariopassariello@gmail.com](mailto:dariopassariello@gmail.com).
30
30
 
31
31
  ## I Have a Question
32
32
 
33
33
  > If you want to ask a question, we assume that you have read the available [Documentation](https://a51.gitbook.io/memorio/).
34
34
 
35
- Before you ask a question, it is best to search for existing [Issues](https://github.com/a51-dev/a51.memorio.public/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
35
+ Before you ask a question, it is best to search for existing [Issues](https://github.com/a51-dev/a51.memorio/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
36
36
 
37
37
  If you then still feel the need to ask a question and need clarification, we recommend the following:
38
38
 
39
- * Open an [Issue](https://github.com/a51-dev/a51.memorio.public/issues/new).
39
+ * Open an [Issue](https://github.com/a51-dev/a51.memorio/issues/new).
40
40
  * Provide as much context as you can about what you're running into.
41
41
  * Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
42
42
 
@@ -56,7 +56,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform
56
56
 
57
57
  * Make sure that you are using the latest version.
58
58
  * Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://a51.gitbook.io/memorio/). If you are looking for support, you might want to check [this section](contributing.md#i-have-a-question)).
59
- * To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/a51-dev/a51.memorio.public/issues?q=label%3Abug).
59
+ * To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/a51-dev/a51.memorio/issues?q=label%3Abug).
60
60
  * Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
61
61
  * Collect information about the bug:
62
62
  * Stack trace (Traceback)
@@ -71,7 +71,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform
71
71
 
72
72
  We use GitHub issues to track bugs and errors. If you run into an issue with the project:
73
73
 
74
- * Open an [Issue](https://github.com/a51-dev/a51.memorio.public/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
74
+ * Open an [Issue](https://github.com/a51-dev/a51.memorio/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
75
75
  * Explain the behavior you would expect and the actual behavior.
76
76
  * Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
77
77
  * Provide the information you collected in the previous section.
@@ -90,12 +90,12 @@ This section guides you through submitting an enhancement suggestion for memorio
90
90
 
91
91
  * Make sure that you are using the latest version.
92
92
  * Read the [documentation](https://a51.gitbook.io/memorio/) carefully and find out if the functionality is already covered, maybe by an individual configuration.
93
- * Perform a [search](https://github.com/a51-dev/a51.memorio.public/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
93
+ * Perform a [search](https://github.com/a51-dev/a51.memorio/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
94
94
  * Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
95
95
 
96
96
  #### How Do I Submit a Good Enhancement Suggestion?
97
97
 
98
- Enhancement suggestions are tracked as [GitHub issues](https://github.com/a51-dev/a51.memorio.public/issues).
98
+ Enhancement suggestions are tracked as [GitHub issues](https://github.com/a51-dev/a51.memorio/issues).
99
99
 
100
100
  * Use a **clear and descriptive title** for the issue to identify the suggestion.
101
101
  * Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Memorio
2
2
 
3
- Memory management for State and Store in easy way
3
+ ## Create State + Observer and Store in easy way
4
+
5
+ ---
6
+ *Created by Dario Passariello - Copyright (c) 2025*
4
7
 
5
8
  ## STATE
6
9
 
@@ -25,8 +28,48 @@ state.removeAll()
25
28
 
26
29
  *["test" is only an example]
27
30
 
31
+ ```
32
+ Observer work for State like useState:
33
+
34
+ ```js
35
+ const [change,setChange] = useState()
36
+
37
+ // Observe state changes and set the react useState
38
+ observer(
39
+ 'myData',
40
+ () => {
41
+ console.log('myData has changed to:', state.myData);
42
+ setChange[state.myData];
43
+ }
44
+ );
45
+
46
+ or
47
+
48
+ // you can use the useEffect
49
+ useEffect(
50
+ ()=>{
51
+ console.log('myData has changed to:', state.myData);
52
+ }, [state.myData]
53
+ )
54
+ ```
55
+
56
+ ### Another example of use of Observer
57
+
58
+ ```js
59
+ import 'memorio';
60
+
61
+ // Use the observer to log the changing state value
62
+ observer(
63
+ 'state.count',
64
+ () => console.log("State changed: ", state.count)
65
+ );
66
+
67
+ // Store a value in the state that changes every 5 seconds
68
+ setInterval(() => state.count = Date.now(), 5000);
28
69
  ```
29
70
 
71
+ ---
72
+
30
73
  ## STORE
31
74
 
32
75
  ```js
@@ -43,9 +86,49 @@ store.remove("test") // Output: "ok"
43
86
  store.removeAll() // Output: "ok"
44
87
  ```
45
88
 
89
+ ### Example use Store in React
90
+
46
91
  ```js
47
- // Observe state changes
48
- observer('myData', () => {
49
- console.log('myData has changed to:', state.myData);
50
- });
92
+ import { useEffect } from 'react';
93
+ import 'memorio';
94
+
95
+ function App() {
96
+
97
+ // Store a value in the store (persistent storage)
98
+ store.set(
99
+ 'user',
100
+ {
101
+ name: 'John Doe',
102
+ age: 30
103
+ }
104
+ );
105
+
106
+ // Use the stored value in a React component
107
+ useEffect(
108
+ () => {
109
+ console.log(store.get("user"));
110
+ // Output: { name: "John Doe", age: 30 }
111
+ document.querySelector("#name").innerText = store.get("user").name
112
+ }, []
113
+ );
114
+
115
+ // Remove all stored data if necessary
116
+ // store.removeAll();
117
+
118
+ return (
119
+ <div>
120
+ <h1 id="name">...</h1>
121
+ </div>
122
+ );
123
+ }
124
+
125
+ export default App;
51
126
  ```
127
+
128
+ ---
129
+
130
+ ## Security Check
131
+
132
+ - [Socket.dev](https://socket.dev/npm/package/memorio)
133
+
134
+ - [Snyk.io](https://security.snyk.io/package/npm/memorio)
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";(()=>{Object.defineProperty(window,"memorio",{value:{},writable:!1,configurable:!1});Object.defineProperty(memorio,"setProps",{value:(e,r,t)=>{Object.defineProperty(e,r.name,t||{writable:!1,configurable:!1,enumerable:!1}),t?.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(t){Object.defineProperties(memorio[e.name],{[t]:{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:`
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
2
  Generate a shallow copy of an object
3
3
  Example: memorio.obj.shallow([object])
4
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
5
  Generate a deepCopy of an object
6
6
  Example: memorio.obj.deepCopy([object])
7
- `,subCommand:[]}]},d={toArray:e=>Object.entries(e),replaceNullObjects:e=>{let r={...e};return Object.keys(e).forEach(t=>{e[t]===null&&(r[t]="")}),r},serialize:e=>{if(typeof e=="function")return e.toString();if(typeof e=="object"){let r={};for(let[t,a]of Object.entries(e))r[t]=memorio.obj.serialize(a);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[t,a]of Object.entries(e))r[t]=memorio.obj.deSerialize(a);return r}return e},sort:e=>Object.keys(e).sort().reduce((r,t)=>(r[t]=e[t],r),{}),toXML:e=>{let r=(t,a="")=>{let o="";for(let n in t)if(t.hasOwnProperty(n)){let i=t[n];typeof i=="object"&&i!==null?o+=`${a}<${n}>
8
- ${r(i,a+" ")}${a}</${n}>
9
- `:o+=`${a}<${n}>${i}</${n}>
10
- `}return o};return r(e)},find:(e,r,t)=>e.find(a=>a[r]===t),instance:e=>Object.create(e),updateByKey:(e,r,t)=>(e.hasOwnProperty(r)&&(e[r]=t),e),findindex:(e,r)=>e.findIndex(t=>t[r]!==void 0),parse:e=>{try{return JSON.parse(e)}catch{return e}},isObject:e=>typeof e=="object"&&e!==null,diff:(e,r)=>{let t={};for(let a in e)e.hasOwnProperty(a)&&e[a]!==r[a]&&(t[a]={obj1:e[a],obj2:r[a]});for(let a in r)r.hasOwnProperty(a)&&e[a]!==r[a]&&(t[a]={obj1:e[a],obj2:r[a]});return t},path:(e,r,t=".")=>r.concat(e).join(t),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:`
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:`
11
11
  Example:
12
12
  const array = [
13
13
  {"date":1230,"value":1},
@@ -67,4 +67,4 @@ ${r(i,a+" ")}${a}</${n}>
67
67
  `,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
68
  Generate groups of array by a specific key
69
69
  Example: memorio.array.groupBy([array, key])
70
- `,subCommand:[]}]},f={find:(e,r)=>{if(Array.isArray(e)){for(let t of e){if(t[r]===r)return t;if(t.children){let a=memorio.array.find(r,t.children);if(a)return a}}return!1}},unique:e=>{if(Array.isArray(e))return[...new Set(e)]},delete:(e,r)=>{Array.isArray(e)&&e.some(function t(a,o,n){if(a[r]===r)return n.splice(o,1),!0;for(let i of Object.keys(a)){let s=a[i];if(Array.isArray(s))return s.some(t)}})},merge:(e,r)=>{if(!e||!r)return r||e;for(let t of Object.keys(e))e[t]instanceof Object&&r[t]&&Object.assign(e[t],memorio.array.merge(r[t],e[t]));return Object.assign(r||{},e)},mergeByKey:(e,r,t)=>e.map(a=>{let o=r.find(n=>a[t]===n[t]);return o?Object.assign({},a,o):a}),asc:e=>{if(Array.isArray(e))return e.sort((r,t)=>r-t)},desc:e=>{if(Array.isArray(e))return e.sort((r,t)=>t-r)},duplicates:e=>{if(!Array.isArray(e))return;let r=new Set,t=new Set;for(let a of e)r.has(a)?t.add(a):r.add(a);return Array.from(t)},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((t,a)=>t+(a[r]||0),0):"provide a multidimensional array",shuffle:e=>{if(Array.isArray(e)){for(let r=e.length-1;r>0;r--){let t=Math.floor(Math.random()*(r+1));[e[r],e[t]]=[e[t],e[r]]}return e}},generate:e=>{if(Number.isNaN(e))return;let r=Array.from({length:e},(t,a)=>a+1);return memorio.array.shuffle(r)},testArrayInt:e=>{if(!Array.isArray(e))return;let r=[];for(let t=1;t<=e.length;t++)e.includes(t)||r.push(t);return r},rand32:e=>{let r=performance.now(),t=[];t.nums=[],t.time=[];for(var a=0;a<e;++a)t.nums.push(crypto.getRandomValues(new Uint32Array(1))[0]);let o=performance.now();return t.time.push(o-r),t},findindex:(e,r)=>e.findIndex(t=>t.name===r),pathToJson:(e,r="/")=>{let t={},a;for(let o of e){a=t;let n=o.split(r);for(let i of n.slice(1,-1)){if(i==="")return;i in a||(a[i]={}),a=a[i]}a[n[n.length-1]]=null}return t},deepClone:e=>JSON.parse(JSON.stringify(e)),match:(e,r)=>e.filter(t=>r.includes(t)),shallow:e=>Object.assign([],e),deepCopy:e=>structuredClone(e),groupBy:(e,r)=>e.reduce((t,a)=>({...t,[a[r]]:[...t[r]||[],a]}),{})};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,t=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let a=o=>r?setTimeout(()=>r(o),0):null;globalThis.events[e]=a},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(t){console.error(`Error setting store item "${e}":`,t)}}},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 t=localStorage.getItem(r);t&&(e+=t.length)}return e}}});Object.freeze(store);var c=(e,r,t=[])=>{let a=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,t.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,t);return r({action:"set",path:s,target:o,newValue:i,previousValue:Reflect.get(o,n)}),a("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,t);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,t=!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,t);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);})();
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);})();
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "memorio",
3
- "version": "0.1.7",
4
- "description": "memorio",
5
- "copyright": "Dario Passariello",
3
+ "version": "0.1.8",
4
+ "description": "Memorio, State + Observer and Store for a easy life ",
6
5
  "license": "MIT",
7
6
  "deprecated": false,
8
7
  "preferGlobal": true,
9
8
  "target": "web",
9
+ "copyright": "Dario Passariello, BigLogic ca - a51.dev is a BigLogic project",
10
10
  "homepage": "https://a51.gitbook.io/memorio",
11
11
  "author": {
12
12
  "name": "Dario Passariello",
@@ -33,6 +33,8 @@
33
33
  "memorio": {}
34
34
  },
35
35
  "keywords": [
36
+ "biglogic",
37
+ "a51",
36
38
  "memorio",
37
39
  "state",
38
40
  "store",