Socket
Socket
Sign inDemoInstall

@ryangjchandler/spruce

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.4.0

2

dist/spruce.js

@@ -1,2 +0,2 @@

"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e=function(e,t){return function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),o=t(i),a=0;a<Math.max(s.length-1,o.length-1);a++){var u=parseInt(s[a]||0,10),c=parseInt(o[a]||0,10);if(u>c)return 1;if(c>u)return-1}var f=s[s.length-1],h=o[o.length-1];if(f&&h){var d=f.split(".").map(r),p=h.split(".").map(r);for(a=0;a<Math.max(d.length,p.length);a++){if(void 0===d[a]||"string"==typeof p[a]&&"number"==typeof d[a])return-1;if(void 0===p[a]||"string"==typeof d[a]&&"number"==typeof p[a])return 1;if(d[a]>p[a])return 1;if(p[a]>d[a])return-1}}else if(f||h)return f?-1:1;return 0}var s=[">",">=","=","<","<="],o={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return o[r].indexOf(n)>-1},i}()}(t={exports:{}}),t.exports}(),t=function(e){return null==e},r=function(e){return Object.getPrototypeOf(e)===Object.prototype},n=function(e){return Array.isArray(e)},i=function(e,s){return Object.entries(e).forEach(function(o){var a=o[0],u=o[1];t(u)||!r(u)&&!n(u)||(n(u)&&(u.__key_name=a),e[a]=i(u,s))}),new Proxy(e,{set:function(e,n,o){return!t(o)&&r(o)&&(o=i(o,s)),s.set(e,n,e[n]=o),!0}})},s={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=i(this.stores,{set:function(t,r,n){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(e.stores,t,r,n),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&e.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(n=Object.assign(t,n)),n},updateLocalStorage:function(e){this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},watch:function(e,t){this.watchers[e]||(this.watchers[e]=[]),this.watchers[e].push(t)},runWatchers:function(e,t,r,n){var i=this;if(i.watchers[r=t.__key_name||r])return i.watchers[r].forEach(function(e){return e(n)});Object.keys(i.watchers).filter(function(e){return e.includes(".")}).forEach(function(s){var o=s.split(".");r===o[o.length-1]&&o.reduce(function(e,o){return(e[r]===t[r]||Object.is(t,e))&&i.watchers[s].forEach(function(e){return e(n)}),e[o]},e)})},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=s;var o=window.deferLoadingAlpine||function(e){e()};window.deferLoadingAlpine=function(e){window.Spruce.start(),o(e)},module.exports=s;
"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e=function(e,t){return function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),o=t(i),a=0;a<Math.max(s.length-1,o.length-1);a++){var c=parseInt(s[a]||0,10),u=parseInt(o[a]||0,10);if(c>u)return 1;if(u>c)return-1}var f=s[s.length-1],h=o[o.length-1];if(f&&h){var d=f.split(".").map(r),p=h.split(".").map(r);for(a=0;a<Math.max(d.length,p.length);a++){if(void 0===d[a]||"string"==typeof p[a]&&"number"==typeof d[a])return-1;if(void 0===p[a]||"string"==typeof d[a]&&"number"==typeof p[a])return 1;if(d[a]>p[a])return 1;if(p[a]>d[a])return-1}}else if(f||h)return f?-1:1;return 0}var s=[">",">=","=","<","<="],o={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return o[r].indexOf(n)>-1},i}()}(t={exports:{}}),t.exports}(),t=function(e){return null==e},r=function(e){return Object.getPrototypeOf(e)===Object.prototype},n=function(e){return Array.isArray(e)},i=function(e,s){return Object.entries(e).forEach(function(o){var a=o[0],c=o[1];t(c)||!r(c)&&!n(c)||(e[a]=i(c,s))}),new Proxy(e,{set:function(e,n,o,a){return!t(o)&&r(o)&&(o=i(o,s)),s.set(e,n,e[n]=o,a),!0}})},s={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],hasStarted:!1,start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=i(this.stores,{set:function(t,r,n,i){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(t,r,n,i),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.hasStarted=!0,this.disableReactivity=!0,Object.entries(this.watchers).forEach(function(t){var r=t[0];t[1].forEach(function(t){return e.watch(r,t)})}),this.disableReactivity=!1,this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&e.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var t=this;window.Alpine.addMagicProperty("store",function(e){return t.subscribe(e),t.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(delete(n=Object.assign(t,n)).__watchers,delete n.__key_name),n},updateLocalStorage:function(e){var t=this.store(e);delete t.__watchers,delete t.__key_name,this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},get:function(e){return e.split(".").reduce(function(e,t){return e[t]},this.stores)},watch:function(e,i){if(!this.hasStarted)return this.watchers[e]||(this.watchers[e]=[]),void this.watchers[e].push(i);var s=e.split("."),o=s.reduce(function(e,i){var s=e[i];return t(s)||!r(s)&&!n(s)?e:s},this.stores),a=Object.is(o,this.get(e))?"__self":s[s.length-1];o.__watchers||(o.__watchers=new Map),o.__watchers.has(a)||o.__watchers.set(a,new Set),o.__watchers.get(a).add(i)},runWatchers:function(e,t,r){e.__watchers&&(e.__watchers.has(t)&&e.__watchers.get(t).forEach(function(e){return e(r)}),e.__watchers.has("__self")&&e.__watchers.get("__self").forEach(function(e){return e(r,t)}))},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=s;var o=window.deferLoadingAlpine||function(e){e()};window.deferLoadingAlpine=function(e){window.Spruce.start(),o(e)},module.exports=s;
//# sourceMappingURL=spruce.js.map

@@ -1,2 +0,2 @@

"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e,t=(function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),o=t(i),a=0;a<Math.max(s.length-1,o.length-1);a++){var u=parseInt(s[a]||0,10),c=parseInt(o[a]||0,10);if(u>c)return 1;if(c>u)return-1}var f=s[s.length-1],h=o[o.length-1];if(f&&h){var d=f.split(".").map(r),p=h.split(".").map(r);for(a=0;a<Math.max(d.length,p.length);a++){if(void 0===d[a]||"string"==typeof p[a]&&"number"==typeof d[a])return-1;if(void 0===p[a]||"string"==typeof d[a]&&"number"==typeof p[a])return 1;if(d[a]>p[a])return 1;if(p[a]>d[a])return-1}}else if(f||h)return f?-1:1;return 0}var s=[">",">=","=","<","<="],o={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return o[r].indexOf(n)>-1},i}()}(e={exports:{}}),e.exports),r=function(e){return null==e},n=function(e){return Object.getPrototypeOf(e)===Object.prototype},i=function(e){return Array.isArray(e)},s=function(e,t){return Object.entries(e).forEach(function(o){var a=o[0],u=o[1];r(u)||!n(u)&&!i(u)||(i(u)&&(u.__key_name=a),e[a]=s(u,t))}),new Proxy(e,{set:function(e,i,o){return!r(o)&&n(o)&&(o=s(o,t)),t.set(e,i,e[i]=o),!0}})},o={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=s(this.stores,{set:function(t,r,n){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(e.stores,t,r,n),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&t.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(n=Object.assign(t,n)),n},updateLocalStorage:function(e){this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},watch:function(e,t){this.watchers[e]||(this.watchers[e]=[]),this.watchers[e].push(t)},runWatchers:function(e,t,r,n){var i=this;if(i.watchers[r=t.__key_name||r])return i.watchers[r].forEach(function(e){return e(n)});Object.keys(i.watchers).filter(function(e){return e.includes(".")}).forEach(function(s){var o=s.split(".");r===o[o.length-1]&&o.reduce(function(e,o){return(e[r]===t[r]||Object.is(t,e))&&i.watchers[s].forEach(function(e){return e(n)}),e[o]},e)})},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=o;var a=window.deferLoadingAlpine||function(e){e()};window.deferLoadingAlpine=function(e){window.Spruce.start(),a(e)};export default o;
"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e,t=(function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),a=t(i),o=0;o<Math.max(s.length-1,a.length-1);o++){var c=parseInt(s[o]||0,10),u=parseInt(a[o]||0,10);if(c>u)return 1;if(u>c)return-1}var f=s[s.length-1],h=a[a.length-1];if(f&&h){var d=f.split(".").map(r),p=h.split(".").map(r);for(o=0;o<Math.max(d.length,p.length);o++){if(void 0===d[o]||"string"==typeof p[o]&&"number"==typeof d[o])return-1;if(void 0===p[o]||"string"==typeof d[o]&&"number"==typeof p[o])return 1;if(d[o]>p[o])return 1;if(p[o]>d[o])return-1}}else if(f||h)return f?-1:1;return 0}var s=[">",">=","=","<","<="],a={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return a[r].indexOf(n)>-1},i}()}(e={exports:{}}),e.exports),r=function(e){return null==e},n=function(e){return Object.getPrototypeOf(e)===Object.prototype},i=function(e){return Array.isArray(e)},s=function(e,t){return Object.entries(e).forEach(function(a){var o=a[0],c=a[1];r(c)||!n(c)&&!i(c)||(e[o]=s(c,t))}),new Proxy(e,{set:function(e,i,a,o){return!r(a)&&n(a)&&(a=s(a,t)),t.set(e,i,e[i]=a,o),!0}})},a={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],hasStarted:!1,start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=s(this.stores,{set:function(t,r,n,i){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(t,r,n,i),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.hasStarted=!0,this.disableReactivity=!0,Object.entries(this.watchers).forEach(function(t){var r=t[0];t[1].forEach(function(t){return e.watch(r,t)})}),this.disableReactivity=!1,this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&t.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(delete(n=Object.assign(t,n)).__watchers,delete n.__key_name),n},updateLocalStorage:function(e){var t=this.store(e);delete t.__watchers,delete t.__key_name,this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},get:function(e){return e.split(".").reduce(function(e,t){return e[t]},this.stores)},watch:function(e,t){if(!this.hasStarted)return this.watchers[e]||(this.watchers[e]=[]),void this.watchers[e].push(t);var s=e.split("."),a=s.reduce(function(e,t){var s=e[t];return r(s)||!n(s)&&!i(s)?e:s},this.stores),o=Object.is(a,this.get(e))?"__self":s[s.length-1];a.__watchers||(a.__watchers=new Map),a.__watchers.has(o)||a.__watchers.set(o,new Set),a.__watchers.get(o).add(t)},runWatchers:function(e,t,r){e.__watchers&&(e.__watchers.has(t)&&e.__watchers.get(t).forEach(function(e){return e(r)}),e.__watchers.has("__self")&&e.__watchers.get("__self").forEach(function(e){return e(r,t)}))},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=a;var o=window.deferLoadingAlpine||function(e){e()};window.deferLoadingAlpine=function(e){window.Spruce.start(),o(e)};export default a;
//# sourceMappingURL=spruce.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.spruce=t()}(this,function(){"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e,t=(function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),o=t(i),a=0;a<Math.max(s.length-1,o.length-1);a++){var u=parseInt(s[a]||0,10),c=parseInt(o[a]||0,10);if(u>c)return 1;if(c>u)return-1}var f=s[s.length-1],d=o[o.length-1];if(f&&d){var h=f.split(".").map(r),p=d.split(".").map(r);for(a=0;a<Math.max(h.length,p.length);a++){if(void 0===h[a]||"string"==typeof p[a]&&"number"==typeof h[a])return-1;if(void 0===p[a]||"string"==typeof h[a]&&"number"==typeof p[a])return 1;if(h[a]>p[a])return 1;if(p[a]>h[a])return-1}}else if(f||d)return f?-1:1;return 0}var s=[">",">=","=","<","<="],o={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return o[r].indexOf(n)>-1},i}()}(e={exports:{}}),e.exports),r=function(e){return null==e},n=function(e){return Object.getPrototypeOf(e)===Object.prototype},i=function(e){return Array.isArray(e)},s=function(e,t){return Object.entries(e).forEach(function(o){var a=o[0],u=o[1];r(u)||!n(u)&&!i(u)||(i(u)&&(u.__key_name=a),e[a]=s(u,t))}),new Proxy(e,{set:function(e,i,o){return!r(o)&&n(o)&&(o=s(o,t)),t.set(e,i,e[i]=o),!0}})},o={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=s(this.stores,{set:function(t,r,n){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(e.stores,t,r,n),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&t.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(n=Object.assign(t,n)),n},updateLocalStorage:function(e){this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},watch:function(e,t){this.watchers[e]||(this.watchers[e]=[]),this.watchers[e].push(t)},runWatchers:function(e,t,r,n){var i=this;if(i.watchers[r=t.__key_name||r])return i.watchers[r].forEach(function(e){return e(n)});Object.keys(i.watchers).filter(function(e){return e.includes(".")}).forEach(function(s){var o=s.split(".");r===o[o.length-1]&&o.reduce(function(e,o){return(e[r]===t[r]||Object.is(t,e))&&i.watchers[s].forEach(function(e){return e(n)}),e[o]},e)})},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=o;var a=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce.start(),a(e)},o});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.spruce=t()}(this,function(){"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var e,t=(function(e,t){e.exports=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r=e.replace(/^v/,"").replace(/\+.*$/,""),n=-1===(t=r).indexOf("-")?t.length:t.indexOf("-"),i=r.substring(0,n).split(".");return i.push(r.substring(n+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function n(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function i(e,i){[e,i].forEach(n);for(var s=t(e),o=t(i),a=0;a<Math.max(s.length-1,o.length-1);a++){var c=parseInt(s[a]||0,10),u=parseInt(o[a]||0,10);if(c>u)return 1;if(u>c)return-1}var f=s[s.length-1],h=o[o.length-1];if(f&&h){var d=f.split(".").map(r),p=h.split(".").map(r);for(a=0;a<Math.max(d.length,p.length);a++){if(void 0===d[a]||"string"==typeof p[a]&&"number"==typeof d[a])return-1;if(void 0===p[a]||"string"==typeof d[a]&&"number"==typeof p[a])return 1;if(d[a]>p[a])return 1;if(p[a]>d[a])return-1}}else if(f||h)return f?-1:1;return 0}var s=[">",">=","=","<","<="],o={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]};return i.validate=function(t){return"string"==typeof t&&e.test(t)},i.compare=function(e,t,r){!function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===s.indexOf(e))throw new TypeError("Invalid operator, expected one of "+s.join("|"))}(r);var n=i(e,t);return o[r].indexOf(n)>-1},i}()}(e={exports:{}}),e.exports),r=function(e){return null==e},n=function(e){return Object.getPrototypeOf(e)===Object.prototype},i=function(e){return Array.isArray(e)},s=function(e,t){return Object.entries(e).forEach(function(o){var a=o[0],c=o[1];r(c)||!n(c)&&!i(c)||(e[a]=s(c,t))}),new Proxy(e,{set:function(e,i,o,a){return!r(o)&&n(o)&&(o=s(o,t)),t.set(e,i,e[i]=o,a),!0}})},o={stores:{},persistenceDriver:window.localStorage,persisted:[],subscribers:[],watchers:{},disableReactivity:!1,startingCallbacks:[],startedCallbacks:[],hasStarted:!1,start:function(){var e=this;this.startingCallbacks.forEach(function(e){return e()}),this.attach(),this.stores=s(this.stores,{set:function(t,r,n,i){if(!e.disableReactivity){e.updateSubscribers(),e.runWatchers(t,r,n,i),e.disableReactivity=!0;try{e.persisted.forEach(e.updateLocalStorage.bind(e))}catch(e){}e.disableReactivity=!1}}}),this.hasStarted=!0,this.disableReactivity=!0,Object.entries(this.watchers).forEach(function(t){var r=t[0];t[1].forEach(function(t){return e.watch(r,t)})}),this.disableReactivity=!1,this.startedCallbacks.forEach(function(e){return e()})},starting:function(e){this.startingCallbacks.push(e)},started:function(e){this.startedCallbacks.push(e)},attach:function(){if(!(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")||window.Alpine&&t.compare(window.Alpine.version,"2.7.0",">=")))throw new Error("[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.");var e=this;window.Alpine.addMagicProperty("store",function(t){return e.subscribe(t),e.stores})},store:function(e,t,r){if(void 0===r&&(r=!1),"function"==typeof t&&(t=t()),r)try{this.stores[e]=this.retrieveFromLocalStorage(e,(n={},Object.entries(t).filter(function(e){return"function"==typeof e[1]}).forEach(function(e){return n[e[0]]=e[1]}),n)),this.persisted.includes(e)||this.persisted.push(e)}catch(e){}var n;return this.stores[e]||(this.stores[e]=t),this.stores[e]},reset:function(e,t){this.stores[e]=t},subscribe:function(e){return this.subscribers.includes(e)||this.subscribers.push(e),this.stores},updateSubscribers:function(){this.subscribers.filter(function(e){return!!e.__x}).forEach(function(e){e.__x.updateElements(e)})},retrieveFromLocalStorage:function(e,t){void 0===t&&(t={});var r=this.persistenceDriver.getItem("__spruce:"+e);if(!r)return null;var n=JSON.parse(r);return"object"==typeof n&&(delete(n=Object.assign(t,n)).__watchers,delete n.__key_name),n},updateLocalStorage:function(e){var t=this.store(e);delete t.__watchers,delete t.__key_name,this.persistenceDriver.setItem("__spruce:"+e,JSON.stringify(this.store(e)))},get:function(e){return e.split(".").reduce(function(e,t){return e[t]},this.stores)},watch:function(e,t){if(!this.hasStarted)return this.watchers[e]||(this.watchers[e]=[]),void this.watchers[e].push(t);var s=e.split("."),o=s.reduce(function(e,t){var s=e[t];return r(s)||!n(s)&&!i(s)?e:s},this.stores),a=Object.is(o,this.get(e))?"__self":s[s.length-1];o.__watchers||(o.__watchers=new Map),o.__watchers.has(a)||o.__watchers.set(a,new Set),o.__watchers.get(a).add(t)},runWatchers:function(e,t,r){e.__watchers&&(e.__watchers.has(t)&&e.__watchers.get(t).forEach(function(e){return e(r)}),e.__watchers.has("__self")&&e.__watchers.get("__self").forEach(function(e){return e(r,t)}))},persistUsing:function(e){if(this.persisted.length>0&&console.warn("[Spruce] You have already initialised a persisted store. Changing the driver may cause issues."),"function"!=typeof e.getItem)throw new Error("[Spruce] The persistence driver must have a `getItem(key)` method.");if("function"!=typeof e.setItem)throw new Error("[Spruce] The persistence driver must have a `setItem(key, value)` method.");this.persistenceDriver=e}};window.Spruce=o;var a=window.deferLoadingAlpine||function(e){e()};return window.deferLoadingAlpine=function(e){window.Spruce.start(),a(e)},o});
//# sourceMappingURL=spruce.umd.js.map
{
"name": "@ryangjchandler/spruce",
"description": "A lightweight state management layer for Alpine.js",
"version": "2.3.0",
"version": "2.4.0",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -1,2 +0,2 @@

import { getMethods, checkForAlpine } from './utils'
import { getMethods, checkForAlpine, isObject, isArray, isNullOrUndefined } from './utils'
import { createObservable } from './observable'

@@ -21,2 +21,4 @@

hasStarted: false,
start() {

@@ -28,3 +30,3 @@ this.startingCallbacks.forEach(fn => fn())

this.stores = createObservable(this.stores, {
set: (target, key, value) => {
set: (target, key, value, receiver) => {
if (this.disableReactivity) {

@@ -36,3 +38,3 @@ return

this.runWatchers(this.stores, target, key, value)
this.runWatchers(target, key, value, receiver)

@@ -51,2 +53,12 @@ this.disableReactivity = true

this.hasStarted = true
this.disableReactivity = true
Object.entries(this.watchers).forEach(([name, callbacks]) => {
callbacks.forEach(callback => this.watch(name, callback))
})
this.disableReactivity = false
this.startedCallbacks.forEach(fn => fn())

@@ -130,2 +142,5 @@ },

storage = Object.assign(methods, storage)
delete storage.__watchers
delete storage.__key_name
}

@@ -137,37 +152,69 @@

updateLocalStorage(name) {
const store = this.store(name)
delete store.__watchers
delete store.__key_name
this.persistenceDriver.setItem(`__spruce:${name}`, JSON.stringify(this.store(name)))
},
get(name) {
return name.split('.').reduce((target, part) => target[part], this.stores)
},
watch(name, callback) {
if (!this.watchers[name]) {
this.watchers[name] = []
if (! this.hasStarted) {
this.watchers[name] || (this.watchers[name] = [])
this.watchers[name].push(callback)
return
}
this.watchers[name].push(callback)
},
const nameParts = name.split('.')
runWatchers(stores, target, key, value) {
key = target['__key_name'] || key
const target = nameParts.reduce((target, part) => {
const sub = target[part]
const self = this
if (! isNullOrUndefined(sub) && (isObject(sub) || isArray(sub))) {
return sub
}
if (self.watchers[key]) {
return self.watchers[key].forEach(callback => callback(value))
return target
}, this.stores)
/**
* If the target object / array is the property
* that needs to be watched, a magic `__self` key is
* used so that runner can pick up on it later.
*/
const part = Object.is(target, this.get(name)) ? '__self' : nameParts[nameParts.length - 1]
if (! target.__watchers) {
target.__watchers = new Map
}
if (! target.__watchers.has(part)) {
target.__watchers.set(part, new Set)
}
Object.keys(self.watchers)
.filter(watcher => watcher.includes('.'))
.forEach(fullDotNotationKey => {
let dotNotationParts = fullDotNotationKey.split('.')
target.__watchers.get(part).add(callback)
},
if (key !== dotNotationParts[dotNotationParts.length - 1]) return
runWatchers(target, key, value) {
if (! target.__watchers) {
return
}
dotNotationParts.reduce((comparison, part) => {
if (comparison[key] === target[key] || Object.is(target, comparison)) {
self.watchers[fullDotNotationKey].forEach(callback => callback(value))
}
if (target.__watchers.has(key)) {
target.__watchers.get(key).forEach(f => f(value))
}
return comparison[part]
}, stores)
})
/**
* The `__self` key is used for watchers that are registered
* to the object or array being updated.
*/
if (target.__watchers.has('__self')) {
target.__watchers.get('__self').forEach(f => f(value, key))
}
},

@@ -174,0 +221,0 @@

@@ -5,7 +5,3 @@ import { isNullOrUndefined, isObject, isArray } from './utils'

Object.entries(target).forEach(([key, value]) => {
if (! isNullOrUndefined(value) && (isObject(value) || isArray(value))) {
if (isArray(value)) {
value['__key_name'] = key
}
if (! isNullOrUndefined(value) && (isObject(value) || isArray(value))) {
target[key] = createObservable(value, callbacks)

@@ -16,3 +12,3 @@ }

return new Proxy(target, {
set(target, key, value) {
set(target, key, value, receiver) {
if (! isNullOrUndefined(value) && isObject(value)) {

@@ -22,3 +18,3 @@ value = createObservable(value, callbacks)

callbacks.set(target, key, target[key] = value)
callbacks.set(target, key, target[key] = value, receiver)

@@ -25,0 +21,0 @@ return true

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc