stunk
Version:
Stunk is a lightweight, framework-agnostic state management library for JavaScript and TypeScript. It uses chunk-based state units for efficient updates, reactivity, and performance optimization in React, Vue(WIP), Svelte(Coming soon), and Vanilla JS/TS a
1 lines • 2.25 kB
JavaScript
function d(e,r){if(e===void 0)throw new Error("Value cannot be undefined.");if(r.length===0)return e;let t=e;for(let o=0;o<r.length;o++){let s=r[o],l=typeof s=="function"?s:s.fn,u=typeof s=="function"?`index ${o}`:s.name||`index ${o}`;try{let f=l(t);if(f===void 0)break;if(f===null)throw new Error(`Middleware "${u}" returned null value.`);t=f;}catch(f){let y=f instanceof Error?f.message:String(f);throw new Error(`Middleware "${u}" threw an error: ${y}`)}}return t}function p(e,r){if(e===r)return true;if(!e||!r||typeof e!=typeof r)return false;if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return false;for(let t=0;t<e.length;t++)if(e[t]!==r[t])return false;return true}if(typeof e=="object"&&typeof r=="object"){let t=Object.keys(e),o=Object.keys(r);if(t.length!==o.length)return false;for(let s of t)if(!Object.prototype.hasOwnProperty.call(r,s)||e[s]!==r[s])return false;return true}return false}function h(e,r,t="",o={}){let{checkMissing:s=true,checkTypes:l=true}=o;if(e===null||r===null||e===void 0||r===void 0)return;if(typeof e!=typeof r){console.error(`\u{1F6A8} Stunk: Type mismatch at '${t||"root"}'. Expected ${typeof e}, got ${typeof r}.`);return}if(typeof e!="object"||typeof r!="object")return;if(Array.isArray(e)!==Array.isArray(r)){console.error(`\u{1F6A8} Stunk: Type mismatch at '${t||"root"}'. Expected ${Array.isArray(e)?"array":"object"}, got ${Array.isArray(r)?"array":"object"}.`);return}if(Array.isArray(e)&&Array.isArray(r)){if(e.length>0&&typeof e[0]=="object")for(let n=0;n<r.length;n++)h(e[0],r[n],`${t}[${n}]`,o);return}let u=Object.keys(e),f=Object.keys(r),y=new Set(u),k=new Set(f),a=f.filter(n=>!y.has(n));if(a.length>0&&(console.error(`\u{1F6A8} Stunk: Unknown properties at '${t||"root"}': ${a.join(", ")}`),console.error("Expected keys:",u),console.error("Received keys:",f)),s){let n=u.filter(c=>!k.has(c));n.length>0&&console.error(`\u{1F6A8} Stunk: Missing properties at '${t||"root"}': ${n.join(", ")}`);}for(let n of u){let c=e[n],i=r[n];c===void 0||i===void 0||i===null||(l&&typeof c!="object"&&typeof c!=typeof i&&console.error(`\u{1F6A8} Stunk: Type mismatch at '${t?t+".":""}${n}'. Expected ${typeof c}, got ${typeof i}.`),h(c,i,t?`${t}.${n}`:n,o));}}export{d as a,p as b,h as c};