memorio 0.1.8 → 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/index.d.ts +4 -0
- package/index.js +4 -70
- package/package.json +12 -2
- package/types/memorio.d.ts +9 -3
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(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
|
-
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 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);})();
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Memorio, State + Observer and Store for a easy life ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"deprecated": false,
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"types/*"
|
|
61
61
|
],
|
|
62
62
|
"scripts": {
|
|
63
|
-
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
64
63
|
"build": "node ./esbuild.config.mjs",
|
|
64
|
+
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
65
65
|
"-----------": "",
|
|
66
66
|
"tsc": "tsc -b .",
|
|
67
67
|
"eslint": "eslint .",
|
|
@@ -69,8 +69,18 @@
|
|
|
69
69
|
"publish:npm": "npm run build && npm publish ./dist"
|
|
70
70
|
},
|
|
71
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",
|
|
72
81
|
"@typescript-eslint/eslint-plugin": "8.39.1",
|
|
73
82
|
"@typescript-eslint/parser": "8.39.1",
|
|
83
|
+
"babel-loader": "10.0.0",
|
|
74
84
|
"esbuild": "^0.25.9",
|
|
75
85
|
"esbuild-plugin-clean": "^1.0.1",
|
|
76
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
|
}
|