memorio 0.0.7 → 0.0.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/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @passariello
package/COPYRIGHT.md ADDED
@@ -0,0 +1,9 @@
1
+ # Copyright
2
+
3
+ Copyright (c) 2025, Dario Passariello. All rights reserved.
4
+ Licensed under MIT License, see
5
+ <https://dario.passariello.ca>
6
+
7
+ This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
8
+
9
+ This software is licensed under the MIT License.
package/SECURITY.md ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var f={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:[]}]},m={set:(e,t={})=>{dispatchEvent(new CustomEvent(String(e),t))},listen:(e,t=null,s=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let i=r=>t?setTimeout(()=>t(r),0):null;globalThis.events[e]=i},remove:e=>{globalThis.events.name=""}};memorio.setDescription(f,m);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(s){console.error(`Error setting store item "${e}":`,s)}}},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 s=localStorage.getItem(t);s&&(e+=s.length)}return e}}});Object.freeze(store);var c=(e,t,s=[])=>{let i=r=>{let o=r.split("-");o.forEach((n,a)=>{let l=o.slice(0,a+1).join("-");memorio.dispatch.set(l,{detail:{name:l}})})};return new Proxy(e,{get(r,o){if(Object.isFrozen(r[o]))return r[o];try{let n=Reflect.get(r,o);return n&&typeof n=="object"&&["Array","Object"].includes(n.constructor.name)?c(n,t,s.concat(o)):n}catch(n){return console.error("Error: ",n),!1}},set(r,o,n){if(r[o]&&typeof r[o]=="object"&&Object.isFrozen(r[o])){console.error(`Error: state "${o}" is locked`);return}try{let a=memorio.obj.path(o,s);return t({action:"set",path:a,target:r,newValue:n,previousValue:Reflect.get(r,o)}),i("state-"+a.replaceAll(".","-")),Reflect.set(r,o,n),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(a){return console.error("Error in set trap:",a),!1}},deleteProperty(r,o){try{let n=memorio.obj.path(o,s);return t({action:"delete",path:n,target:r}),Reflect.deleteProperty(r,o)}catch(n){return console.error("Error in deleteProperty trap:",n),!1}}})};globalThis?.state?globalThis.state=state:globalThis.state=c({},()=>{});var u=new WeakSet;u.add(state);setInterval(()=>{if(!u.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);console.info(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,t=null,s=!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){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}let r=e.replaceAll(".","-");memorio.dispatch.listen(r,t,s);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,6 +1,6 @@
1
1
  {
2
2
  "name": "memorio",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "memorio",
5
5
  "copyright": "Dario Passariello",
6
6
  "license": "MIT",
@@ -18,13 +18,7 @@
18
18
  "url": "https://github.com/passariello/",
19
19
  "email": "dariopassariello@gmail.com"
20
20
  },
21
- "main": "dist/index.js",
22
- "bin": {
23
- "dist": "dist"
24
- },
25
- "files": [
26
- "dist/**"
27
- ],
21
+ "main": "index.js",
28
22
  "contributors": [
29
23
  {
30
24
  "name": "Dario Passariello",
@@ -0,0 +1,16 @@
1
+
2
+ interface memorio { }
3
+
4
+ declare var memorio: _memorio
5
+ type memorio = _memorio
6
+
7
+ declare var arguments: any
8
+ type arguments = any
9
+
10
+ /////////////////////////////////////////////
11
+
12
+ interface Descr {
13
+ name: string,
14
+ active: boolean,
15
+ subCommand: Array<SubCommand>,
16
+ }
@@ -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,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
@@ -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: store.set("example",{test:"test"})
10
+ */
11
+ interface _store {
12
+
13
+ /**
14
+ * Create a new store
15
+ *
16
+ * @example
17
+ * store.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 store.
21
+ * @param param The information taht you want to store (Any).
22
+ * @return boolean
23
+ */
24
+ set: (name: string, value: any) => void
25
+
26
+ /**
27
+ * Have back the data from a store.
28
+ *
29
+ * @example
30
+ * store.get("test")
31
+ *
32
+ * @since memorio 0.0.1
33
+ * @param name The String as name to define the store.
34
+ */
35
+ get: (name: string) => any
36
+
37
+ /**
38
+ * Delete an existing store:
39
+ *
40
+ * @example
41
+ * store.delete("test")
42
+ * store.remove("test")
43
+ *
44
+ * @since memorio 0.0.1
45
+ * @param name The String as name to define the store.
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
+ * store.clearAll()
56
+ * store.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
+ * store.quota()
69
+ *
70
+ * @since memorio 0.0.1
71
+ * @return values
72
+ */
73
+ quota: () => void
74
+
75
+ /**
76
+ * Get the size of stores an the total
77
+ *
78
+ * @example
79
+ * store.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 store: _store
91
+ type store = _store