memorio 0.1.7 → 0.1.9
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 +7 -7
- package/README.md +88 -5
- package/index.d.ts +4 -0
- package/index.js +4 -70
- package/package.json +16 -4
- package/types/memorio.d.ts +9 -3
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1,70 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{Object.defineProperty
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Generate a deepCopy of an object
|
|
6
|
-
Example: memorio.obj.deepCopy([object])
|
|
7
|
-
`,subCommand:[]}]},d={toArray:e=>Object.entries(e),replaceNullObjects:e=>{let r={...e};return Object.keys(e).forEach(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:`
|
|
11
|
-
Example:
|
|
12
|
-
const array = [
|
|
13
|
-
{"date":1230,"value":1},
|
|
14
|
-
{"date":1231,"value":2},
|
|
15
|
-
{"date":1232,"value":3, "value1":3, name:"John"},
|
|
16
|
-
{"date":1233,"value":4},
|
|
17
|
-
{"date":1234,"value":5},
|
|
18
|
-
{"date":1235,"value":6}
|
|
19
|
-
]
|
|
20
|
-
const newData = [
|
|
21
|
-
{"date":1230,"value":1000,'name':'Diana'},
|
|
22
|
-
{"date":1232,"value":1000, "value1":20000},
|
|
23
|
-
{"date":1234,"value":1000},
|
|
24
|
-
{"date":1235,"value":888810000}
|
|
25
|
-
]
|
|
26
|
-
Command: memorio.array.mergeByKey( array, newData, 'date' )
|
|
27
|
-
Result:
|
|
28
|
-
[
|
|
29
|
-
{"date": 1230,"value": 1000, name: "Diana" },
|
|
30
|
-
{"date": 1231,"value": 2},
|
|
31
|
-
{"date": 1232 "value": 1000, "value1": 20000, name: "John" },
|
|
32
|
-
{"date": 1233,"value": 4},
|
|
33
|
-
{"date": 1234, "value": 1000},
|
|
34
|
-
{"date": 1235,"value": 888810000}
|
|
35
|
-
]
|
|
36
|
-
`,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:`
|
|
37
|
-
Sum the values of a specified column in a multidimensional array.
|
|
38
|
-
Example:
|
|
39
|
-
const array = [
|
|
40
|
-
[12, 23, 34],
|
|
41
|
-
[45, 56, 67],
|
|
42
|
-
[78, 89, 90]
|
|
43
|
-
]
|
|
44
|
-
console.debug(memorio.array.sumColumn(array, 0)) // Result: 135
|
|
45
|
-
`,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:`
|
|
46
|
-
Test if an array contains consecutive integers.
|
|
47
|
-
Examples:
|
|
48
|
-
console.debug(memorio.array.testArrayInt([1,2,3,4,6,7])) // Result: [5]
|
|
49
|
-
`,subCommand:[]},{name:"rand32",version:"0.0.1",example:"memorio.array.rand32(num)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20230527",type:"function",active:!0,description:`
|
|
50
|
-
Generate an array of random 32-bit unsigned integers.
|
|
51
|
-
Example:
|
|
52
|
-
console.debug(memorio.array.rand32(500000))
|
|
53
|
-
`,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:`
|
|
54
|
-
Generate a deep clone of an array or object.
|
|
55
|
-
Example:
|
|
56
|
-
memorio.array.deepClone([array|object])
|
|
57
|
-
`,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:`
|
|
58
|
-
Find a perfect match between an array of words and an array to check.
|
|
59
|
-
Example:
|
|
60
|
-
memorio.array.match([arrayOfWords, arrayToCheck])
|
|
61
|
-
`,subCommand:[]},{name:"shallow",version:"0.0.1",example:"memorio.array.shallow([array])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
|
|
62
|
-
Generate a shallow copy of an array
|
|
63
|
-
Example: memorio.array.shallow([array])
|
|
64
|
-
`,subCommand:[]},{name:"deepCopy",version:"0.0.1",example:"memorio.array.deepCopy([array])",author:"Dario Passariello",creationDate:"20250101",lastMod:"20250101",type:"function",active:!0,description:`
|
|
65
|
-
Generate a deepCopy of an array
|
|
66
|
-
Example: memorio.array.deepCopy([array])
|
|
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
|
-
Generate groups of array by a specific key
|
|
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);})();
|
|
1
|
+
"use strict";(()=>{var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var f=(e,r)=>()=>(e&&(r=e(e=0)),r);var l=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var R=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of A(r))!E.call(e,o)&&o!==t&&u(e,o,{get:()=>r[o],enumerable:!(n=P(r,o))||n.enumerable});return e};var $=e=>R(u({},"__esModule",{value:!0}),e);var g,b=f(()=>{g={name:"memorio",version:"0.1.9",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:{"@babel/core":"^7.28.3","@babel/eslint-parser":"^7.28.0","@babel/plugin-transform-runtime":"7.28.3","@babel/preset-env":"7.28.3","@babel/preset-react":"7.27.1","@babel/preset-typescript":"7.27.1","@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","babel-loader":"10.0.0",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 k={};var y=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});global.memorio.version=g.version});var m=l(()=>{"use strict";Object.defineProperty(global.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(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(t){Object.defineProperties(global.memorio[e.name],{[t]:{writable:!1,configurable:!1,enumerable:!1}})}),global.memorio.setProps(global.memorio,e,{writable:!1,configurable:!1,enumerable:!1})}})});var d=l(()=>{"use strict";var x={find:(e,r)=>{if(Array.isArray(e)){for(let t of e){if(t[r]===r)return t;if(t.children){let n=global.memorio.array.find(r,t.children);if(n)return n}}return!1}},unique:e=>{if(Array.isArray(e))return[...new Set(e)]},delete:(e,r)=>{Array.isArray(e)&&e.some(function t(n,o,s){if(n[r]===r)return s.splice(o,1),!0;for(let i of Object.keys(n)){let a=n[i];if(Array.isArray(a))return a.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],global.memorio.array.merge(r[t],e[t]));return Object.assign(r||{},e)},mergeByKey:(e,r,t)=>e.map(n=>{let o=r.find(s=>n[t]===s[t]);return o?Object.assign({},n,o):n}),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 n of e)r.has(n)?t.add(n):r.add(n);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,n)=>t+(n[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,n)=>n+1);return global.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 n=0;n<e;++n)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={},n;for(let o of e){n=t;let s=o.split(r);for(let i of s.slice(1,-1)){if(i==="")return;i in n||(n[i]={}),n=n[i]}n[s[s.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,n)=>({...t,[n[r]]:[...t[r]||[],n]}),{})};global.memorio.setDescription({},x)});var p=l(()=>{"use strict";var I={set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,t=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let n=o=>r?setTimeout(()=>r(o),1):null;window.addEventListener(e,n),global.events[e]=n},remove:e=>{window.removeEventListener(e,global.events[e]),delete global.events[e]}};global.memorio.setDescription({},I)});var h=l(()=>{"use strict";var q={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,n]of Object.entries(e))r[t]=global.memorio.obj.serialize(n);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,n]of Object.entries(e))r[t]=global.memorio.obj.deSerialize(n);return r}return e},sort:e=>Object.keys(e).sort().reduce((r,t)=>(r[t]=e[t],r),{}),toXML:e=>{let r=(t,n="")=>{let o="";for(let s in t)if(t.hasOwnProperty(s)){let i=t[s];typeof i=="object"&&i!==null?o+=`${n}<${s}>
|
|
2
|
+
${r(i,n+" ")}${n}</${s}>
|
|
3
|
+
`:o+=`${n}<${s}>${i}</${s}>
|
|
4
|
+
`}return o};return r(e)},find:(e,r,t)=>e.find(n=>n[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 n in e)e.hasOwnProperty(n)&&e[n]!==r[n]&&(t[n]={obj1:e[n],obj2:r[n]});for(let n in r)r.hasOwnProperty(n)&&e[n]!==r[n]&&(t[n]={obj1:e[n],obj2:r[n]});return t},path:(e,r,t=".")=>r.concat(e).join(t),shallow:e=>Object.assign({},e),deepCopy:e=>structuredClone(e)};global.memorio.setDescription({},q)});var O=l(()=>{"use strict";var v=(e,r,t=[])=>{let n=o=>{let s=o.split(".");s.forEach((i,a)=>{let c=s.slice(0,a+1).join(".");global.memorio.dispatch.set(c,{detail:{name:c}})})};return new Proxy(e,{get(o,s){if(Object.isFrozen(o[s]))return o[s];try{let i=Reflect.get(o,s);return i&&typeof i=="object"&&["Array","Object"].includes(i.constructor.name)?v(i,r,t.concat(s)):i}catch(i){return console.error("Error: ",i),!1}},set(o,s,i){if(o[s]&&typeof o[s]=="object"&&Object.isFrozen(o[s])){console.error(`Error: state '${s}' is locked`);return}try{let a=global.memorio.obj.path(s,t);return r({action:"set",path:a,target:o,newValue:i,previousValue:Reflect.get(o,s)}),n("state."+a),Reflect.set(o,s,i),o[s]&&typeof o[s]=="object"&&Reflect.defineProperty(o[s],"lock",{value(){Object.defineProperty(o,s,{writable:!1,enumerable:!1}),Object.freeze(o[s])}}),!0}catch(a){return console.error("Error in set trap:",a),!1}},deleteProperty(o,s){try{let i=global.memorio.obj.path(s,t);return r({action:"delete",path:i,target:o}),Reflect.deleteProperty(o,s)}catch(i){return console.error("Error in deleteProperty trap:",i),!1}}})};global?.state?global.state=state:global.state=v({},()=>{});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 w=l(()=>{"use strict";global.observer||(global.observer=null);Object.defineProperty(global,"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){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,t);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 S=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(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)});y();m();d();p();h();O();w();S();})();
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
5
|
-
"copyright": "Dario Passariello",
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|
|
@@ -58,8 +60,8 @@
|
|
|
58
60
|
"types/*"
|
|
59
61
|
],
|
|
60
62
|
"scripts": {
|
|
61
|
-
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
62
63
|
"build": "node ./esbuild.config.mjs",
|
|
64
|
+
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
63
65
|
"-----------": "",
|
|
64
66
|
"tsc": "tsc -b .",
|
|
65
67
|
"eslint": "eslint .",
|
|
@@ -67,8 +69,18 @@
|
|
|
67
69
|
"publish:npm": "npm run build && npm publish ./dist"
|
|
68
70
|
},
|
|
69
71
|
"devDependencies": {
|
|
72
|
+
"@babel/core": "^7.28.3",
|
|
73
|
+
"@babel/eslint-parser": "^7.28.0",
|
|
74
|
+
"@babel/plugin-transform-runtime": "7.28.3",
|
|
75
|
+
"@babel/preset-env": "7.28.3",
|
|
76
|
+
"@babel/preset-react": "7.27.1",
|
|
77
|
+
"@babel/preset-typescript": "7.27.1",
|
|
78
|
+
"@eslint/js": "9.33.0",
|
|
79
|
+
"@types/jest": "^30.0.0",
|
|
80
|
+
"@types/node": "^24.3.0",
|
|
70
81
|
"@typescript-eslint/eslint-plugin": "8.39.1",
|
|
71
82
|
"@typescript-eslint/parser": "8.39.1",
|
|
83
|
+
"babel-loader": "10.0.0",
|
|
72
84
|
"esbuild": "^0.25.9",
|
|
73
85
|
"esbuild-plugin-clean": "^1.0.1",
|
|
74
86
|
"esbuild-plugin-copy": "^2.1.1",
|
package/types/memorio.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
declare module 'memorio' {
|
|
4
|
+
const resource: { [key: string]: any }
|
|
5
|
+
export = resource
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
interface _memorio {
|
|
3
9
|
setProps: any,
|
|
4
10
|
obj: any,
|
|
@@ -7,16 +13,16 @@ interface _memorio {
|
|
|
7
13
|
setDescription: any
|
|
8
14
|
}
|
|
9
15
|
|
|
10
|
-
declare var memorio: _memorio
|
|
11
16
|
type memorio = _memorio
|
|
17
|
+
declare var memorio: any
|
|
12
18
|
|
|
13
|
-
declare var arguments: any
|
|
14
19
|
type arguments = any
|
|
20
|
+
declare var arguments: any
|
|
15
21
|
|
|
16
22
|
/////////////////////////////////////////////
|
|
17
23
|
|
|
18
24
|
interface Descr {
|
|
19
25
|
name: string,
|
|
20
26
|
active: boolean,
|
|
21
|
-
subCommand:
|
|
27
|
+
subCommand: object,
|
|
22
28
|
}
|