Comparing version 1.2.0 to 1.3.0
@@ -1,1 +0,1 @@ | ||
import{stringify as t,parse as r}from"qs";function i(){return(i=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])}return t}).apply(this,arguments)}class e{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=i}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error(`Ziggy error: '${i}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){var o;if(super(),this.t=null!=(o=null!=n?n:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=i({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>i({},t,{[r]:this.s[r]}),{});return this.i.compile(this.s)+t(i({},r,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const i=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new e(t,s,this.t).matchesUrl(i))||[void 0,void 0];if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(r)||!o)return o;const h=new e(s,n,this.t);r=this.o(r,h);const u=this.h(n);return!(!Object.values(r).every(t=>!t)||Object.values(u).length)||Object.entries(r).every(([t,r])=>u[t]==r)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,s)=>i({},t,e[s]?{[e[s].name]:r}:{[r]:""}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),i({},this.u(r),this.l(t,r.bindings))}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},e)=>i({},t,{[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[e,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===e)return i({},t,{[e]:s});if(!s.hasOwnProperty(r[e])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${r[e]}'.`);r[e]="id"}return i({},t,{[e]:s[r[e]]})},{})}h(t){var e;let s=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,r="",e)=>{const[s,n]=[t,r].map(t=>t.split(e));return n.reduce((t,r,e)=>/^{[^}?]+\??}$/.test(r)&&s[e]?i({},t,{[r.replace(/^{|\??}$/g,"")]:s[e]}):t,{})};return i({},n(window.location.host,t.domain,"."),n(s,t.uri,"/"),r(null===(e=window.location.search)||void 0===e?void 0:e.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,i,e){const n=new s(t,r,i,e);return t?n.toString():n} | ||
import{stringify as t,parse as i}from"qs";function r(){return(r=Object.assign||function(t){for(var i=1;i<arguments.length;i++){var r=arguments[i];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t}).apply(this,arguments)}class e{constructor(t,i,r){var e;this.name=t,this.definition=i,this.bindings=null!=(e=i.bindings)?e:{},this.config=r}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,i;return null!=(t=null===(i=this.template.match(/{[^}?]+\??}/g))||void 0===i?void 0:i.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const i=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${i}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(i,r)=>{var e;if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(e=t[r])?e:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,i,s=!0,n){var h;if(super(),this.t=null!=(h=null!=n?n:Ziggy)?h:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=r({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.h(i)}}toString(){const i=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:i})=>i===t)).filter(t=>"_query"!==t).reduce((t,i)=>r({},t,{[i]:this.s[i]}),{});return this.i.compile(this.s)+t(r({},i,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,i)=>"boolean"==typeof t?Number(t):i(t)})}current(t,i){const r=this.t.absolute?this.o.host+this.o.pathname:this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const h=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(i)||!h)return h;const o=new e(s,n,this.t);i=this.h(i,o);const u=this.u(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,i])=>u[t]==i)}get o(){var t,i,r,e,s,n;const{host:h="",pathname:o="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(i=this.t.location)||void 0===i?void 0:i.host)?t:h,pathname:null!=(r=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?r:o,search:null!=(s=null===(n=this.t.location)||void 0===n?void 0:n.search)?s:u}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},i=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=i.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,i,s)=>r({},t,e[s]?{[e[s].name]:i}:{[i]:""}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(i.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),r({},this.l(i),this.g(t,i.bindings))}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:i},e)=>r({},t,{[i]:this.t.defaults[i]}),{})}g(t,i={}){return Object.entries(t).reduce((t,[e,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===e)return r({},t,{[e]:s});if(!s.hasOwnProperty(i[e])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${i[e]}'.`);i[e]="id"}return r({},t,{[e]:s[i[e]]})},{})}u(t){var e;let s=this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,i="",e)=>{const[s,n]=[t,i].map(t=>t.split(e));return n.reduce((t,i,e)=>/^{[^}?]+\??}$/.test(i)&&s[e]?r({},t,{[i.replace(/^{|\??}$/g,"")]:s[e]}):t,{})};return r({},n(this.o.host,t.domain,"."),n(s,t.uri,"/"),i(null===(e=this.o.search)||void 0===e?void 0:e.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,i,r,e){const n=new s(t,i,r,e);return t?n.toString():n} |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("qs")):"function"==typeof define&&define.amd?define(["qs"],e):(t=t||self).route=e(t.qs)}(this,function(t){class e{constructor(t,e,i){var r;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},this.config=i}get template(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}get parameterSegments(){var t,e;return null!=(t=null===(e=this.template.match(/{[^}?]+\??}/g))||void 0===e?void 0:e.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+e+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{var r;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+this.name+"'.");return encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class i extends String{constructor(t,i,r=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(i)}}toString(){const e=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+t.stringify({...e,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,i){const r=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);if([null,void 0].includes(i)||!o)return o;const h=new e(s,n,this.t);i=this.o(i,h);const u=this.h(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,e])=>u[t]==e)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,r)=>i[r]?{...t,[i[r].name]:e}:{...t,[e]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(e),...this.l(t,e.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}l(t,e={}){return Object.entries(t).reduce((t,[i,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===i)return{...t,[i]:r};if(!r.hasOwnProperty(e[i])){if(!r.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+e[i]+"'.");e[i]="id"}return{...t,[i]:r[e[i]]}},{})}h(e){var i;let r=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,e="",i)=>{const[r,s]=[t,e].map(t=>t.split(i));return s.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&r[i]?{...t,[e.replace(/^{|\??}$/g,"")]:r[i]}:t,{})};return{...s(window.location.host,e.domain,"."),...s(r,e.uri,"/"),...t.parse(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}return function(t,e,r,s){const n=new i(t,e,r,s);return t?n.toString():n}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("qs")):"function"==typeof define&&define.amd?define(["qs"],e):(t=t||self).route=e(t.qs)}(this,function(t){class e{constructor(t,e,i){this.name=t,this.definition=e,this.bindings=e.bindings??{},this.config=i}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t;return(null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error(`Ziggy error: '${i}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[i]??"")}).replace(/\/+$/,""):this.template}}class i extends String{constructor(t,i,r=!0,s){if(super(),this.t=s??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(i)}}toString(){const e=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+t.stringify({...e,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,i){const r=this.t.absolute?this.h.host+this.h.pathname:this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(i)||!o)return o;const h=new e(s,n,this.t);i=this.o(i,h);const u=this.u(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,e])=>u[t]==e)}get h(){var t,e,i;const{host:r="",pathname:s="",search:n=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??r,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??s,search:(null===(i=this.t.location)||void 0===i?void 0:i.search)??n}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,r)=>i[r]?{...t,[i[r].name]:e}:{...t,[e]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.l(e),...this.g(t,e.bindings)}}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}g(t,e={}){return Object.entries(t).reduce((t,[i,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===i)return{...t,[i]:r};if(!r.hasOwnProperty(e[i])){if(!r.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${e[i]}'.`);e[i]="id"}return{...t,[i]:r[e[i]]}},{})}u(e){var i;let r=this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,e="",i)=>{const[r,s]=[t,e].map(t=>t.split(i));return s.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&r[i]?{...t,[e.replace(/^{|\??}$/g,"")]:r[i]}:t,{})};return{...s(this.h.host,e.domain,"."),...s(r,e.uri,"/"),...t.parse(null===(i=this.h.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}return function(t,e,r,s){const n=new i(t,e,r,s);return t?n.toString():n}}); |
@@ -1,1 +0,1 @@ | ||
import{stringify as t,parse as r}from"qs";class i{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=i}get template(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+this.name+"'.");return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class e extends String{constructor(t,r,e=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:e},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new i(t,this.t.routes[t],this.t),this.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>({...t,[r]:this.s[r]}),{});return this.i.compile(this.s)+t({...r,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new i(t,s,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);if([null,void 0].includes(r)||!o)return o;const h=new i(s,n,this.t);r=this.o(r,h);const u=this.h(n);return!(!Object.values(r).every(t=>!t)||Object.values(u).length)||Object.entries(r).every(([t,r])=>u[t]==r)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,e)=>i[e]?{...t,[i[e].name]:r}:{...t,[r]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(r),...this.l(t,r.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>({...t,[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[i,e])=>{if(!e||"object"!=typeof e||Array.isArray(e)||"_query"===i)return{...t,[i]:e};if(!e.hasOwnProperty(r[i])){if(!e.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+r[i]+"'.");r[i]="id"}return{...t,[i]:e[r[i]]}},{})}h(t){var i;let e=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,r="",i)=>{const[e,s]=[t,r].map(t=>t.split(i));return s.reduce((t,r,i)=>/^{[^}?]+\??}$/.test(r)&&e[i]?{...t,[r.replace(/^{|\??}$/g,"")]:e[i]}:t,{})};return{...s(window.location.host,t.domain,"."),...s(e,t.uri,"/"),...r(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,i,s){const n=new e(t,r,i,s);return t?n.toString():n} | ||
import{stringify as t,parse as i}from"qs";class e{constructor(t,i,e){this.name=t,this.definition=i,this.bindings=i.bindings??{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t;return(null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const i=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${i}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(i,e)=>{if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[e]??"")}).replace(/\/+$/,""):this.template}}class r extends String{constructor(t,i,r=!0,s){if(super(),this.t=s??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.h(i)}}toString(){const i=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:i})=>i===t)).filter(t=>"_query"!==t).reduce((t,i)=>({...t,[i]:this.s[i]}),{});return this.i.compile(this.s)+t({...i,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,i)=>"boolean"==typeof t?Number(t):i(t)})}current(t,i){const r=this.t.absolute?this.o.host+this.o.pathname:this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const h=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(i)||!h)return h;const o=new e(s,n,this.t);i=this.h(i,o);const u=this.u(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,i])=>u[t]==i)}get o(){var t,i,e;const{host:r="",pathname:s="",search:n=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??r,pathname:(null===(i=this.t.location)||void 0===i?void 0:i.pathname)??s,search:(null===(e=this.t.location)||void 0===e?void 0:e.search)??n}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},i=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=i.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,i,r)=>e[r]?{...t,[e[r].name]:i}:{...t,[i]:""},{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(i.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),{...this.l(i),...this.g(t,i.bindings)}}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:i},e)=>({...t,[i]:this.t.defaults[i]}),{})}g(t,i={}){return Object.entries(t).reduce((t,[e,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===e)return{...t,[e]:r};if(!r.hasOwnProperty(i[e])){if(!r.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${i[e]}'.`);i[e]="id"}return{...t,[e]:r[i[e]]}},{})}u(t){var e;let r=this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,i="",e)=>{const[r,s]=[t,i].map(t=>t.split(e));return s.reduce((t,i,e)=>/^{[^}?]+\??}$/.test(i)&&r[e]?{...t,[i.replace(/^{|\??}$/g,"")]:r[e]}:t,{})};return{...s(this.o.host,t.domain,"."),...s(r,t.uri,"/"),...i(null===(e=this.o.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,i,e,s){const n=new r(t,i,e,s);return t?n.toString():n} |
@@ -1,1 +0,1 @@ | ||
import{stringify as t,parse as r}from"qs";function i(){return(i=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])}return t}).apply(this,arguments)}class e{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=i}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error(`Ziggy error: '${i}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){var o;if(super(),this.t=null!=(o=null!=n?n:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=i({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>i({},t,{[r]:this.s[r]}),{});return this.i.compile(this.s)+t(i({},r,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const i=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new e(t,s,this.t).matchesUrl(i))||[void 0,void 0];if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(r)||!o)return o;const h=new e(s,n,this.t);r=this.o(r,h);const u=this.h(n);return!(!Object.values(r).every(t=>!t)||Object.values(u).length)||Object.entries(r).every(([t,r])=>u[t]==r)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,s)=>i({},t,e[s]?{[e[s].name]:r}:{[r]:""}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),i({},this.u(r),this.l(t,r.bindings))}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},e)=>i({},t,{[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[e,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===e)return i({},t,{[e]:s});if(!s.hasOwnProperty(r[e])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${r[e]}'.`);r[e]="id"}return i({},t,{[e]:s[r[e]]})},{})}h(t){var e;let s=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,r="",e)=>{const[s,n]=[t,r].map(t=>t.split(e));return n.reduce((t,r,e)=>/^{[^}?]+\??}$/.test(r)&&s[e]?i({},t,{[r.replace(/^{|\??}$/g,"")]:s[e]}):t,{})};return i({},n(window.location.host,t.domain,"."),n(s,t.uri,"/"),r(null===(e=window.location.search)||void 0===e?void 0:e.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}const n={install:(t,r)=>t.mixin({methods:{route:(t,i,e,n=r)=>function(t,r,i,e){const n=new s(t,r,i,e);return t?n.toString():n}(t,i,e,n)}})};export{n as ZiggyVue}; | ||
import{stringify as t,parse as i}from"qs";function r(){return(r=Object.assign||function(t){for(var i=1;i<arguments.length;i++){var r=arguments[i];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t}).apply(this,arguments)}class e{constructor(t,i,r){var e;this.name=t,this.definition=i,this.bindings=null!=(e=i.bindings)?e:{},this.config=r}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t,i;return null!=(t=null===(i=this.template.match(/{[^}?]+\??}/g))||void 0===i?void 0:i.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const i=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${i}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(i,r)=>{var e;if([null,void 0].includes(t[r])&&this.parameterSegments.find(({name:t})=>t===r).required)throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(e=t[r])?e:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,i,s=!0,n){var o;if(super(),this.t=null!=(o=null!=n?n:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=r({},this.t,{absolute:s}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(i)}}toString(){const i=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:i})=>i===t)).filter(t=>"_query"!==t).reduce((t,i)=>r({},t,{[i]:this.s[i]}),{});return this.i.compile(this.s)+t(r({},i,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,i)=>"boolean"==typeof t?Number(t):i(t)})}current(t,i){const r=this.t.absolute?this.h.host+this.h.pathname:this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(i)||!o)return o;const h=new e(s,n,this.t);i=this.o(i,h);const u=this.u(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,i])=>u[t]==i)}get h(){var t,i,r,e,s,n;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null===(i=this.t.location)||void 0===i?void 0:i.host)?t:o,pathname:null!=(r=null===(e=this.t.location)||void 0===e?void 0:e.pathname)?r:h,search:null!=(s=null===(n=this.t.location)||void 0===n?void 0:n.search)?s:u}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},i=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=i.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,i,s)=>r({},t,e[s]?{[e[s].name]:i}:{[i]:""}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(i.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),r({},this.l(i),this.g(t,i.bindings))}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:i},e)=>r({},t,{[i]:this.t.defaults[i]}),{})}g(t,i={}){return Object.entries(t).reduce((t,[e,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===e)return r({},t,{[e]:s});if(!s.hasOwnProperty(i[e])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${i[e]}'.`);i[e]="id"}return r({},t,{[e]:s[i[e]]})},{})}u(t){var e;let s=this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,i="",e)=>{const[s,n]=[t,i].map(t=>t.split(e));return n.reduce((t,i,e)=>/^{[^}?]+\??}$/.test(i)&&s[e]?r({},t,{[i.replace(/^{|\??}$/g,"")]:s[e]}):t,{})};return r({},n(this.h.host,t.domain,"."),n(s,t.uri,"/"),i(null===(e=this.h.search)||void 0===e?void 0:e.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}const n={install:(t,i)=>t.mixin({methods:{route:(t,r,e,n=i)=>function(t,i,r,e){const n=new s(t,i,r,e);return t?n.toString():n}(t,r,e,n)}})};export{n as ZiggyVue}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],e):e((t=t||self).ZiggyVue={},t.qs)}(this,function(t,e){class i{constructor(t,e,i){var r;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},this.config=i}get template(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}get parameterSegments(){var t,e;return null!=(t=null===(e=this.template.match(/{[^}?]+\??}/g))||void 0===e?void 0:e.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+e+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{var r;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+this.name+"'.");return encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class r extends String{constructor(t,e,r=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new i(t,this.t.routes[t],this.t),this.s=this.o(e)}}toString(){const t=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+e.stringify({...t,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const r=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([e,s])=>new i(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);if([null,void 0].includes(e)||!o)return o;const h=new i(s,n,this.t);e=this.o(e,h);const u=this.h(n);return!(!Object.values(e).every(t=>!t)||Object.values(u).length)||Object.entries(e).every(([t,e])=>u[t]==e)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,r)=>i[r]?{...t,[i[r].name]:e}:{...t,[e]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(e),...this.l(t,e.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}l(t,e={}){return Object.entries(t).reduce((t,[i,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===i)return{...t,[i]:r};if(!r.hasOwnProperty(e[i])){if(!r.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+e[i]+"'.");e[i]="id"}return{...t,[i]:r[e[i]]}},{})}h(t){var i;let r=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,e="",i)=>{const[r,s]=[t,e].map(t=>t.split(i));return s.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&r[i]?{...t,[e.replace(/^{|\??}$/g,"")]:r[i]}:t,{})};return{...s(window.location.host,t.domain,"."),...s(r,t.uri,"/"),...e.parse(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}t.ZiggyVue={install:(t,e)=>t.mixin({methods:{route:(t,i,s,n=e)=>function(t,e,i,s){const n=new r(t,e,i,s);return t?n.toString():n}(t,i,s,n)}})}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],e):e((t=t||self).ZiggyVue={},t.qs)}(this,function(t,e){class i{constructor(t,e,i){this.name=t,this.definition=e,this.bindings=e.bindings??{},this.config=i}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t;return(null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${e}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error(`Ziggy error: '${i}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[i]??"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,e,s=!0,r){if(super(),this.t=r??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:s},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new i(t,this.t.routes[t],this.t),this.s=this.o(e)}}toString(){const t=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+e.stringify({...t,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const s=this.t.absolute?this.h.host+this.h.pathname:this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[r,n]=Object.entries(this.t.routes).find(([e,r])=>new i(t,r,this.t).matchesUrl(s))||[void 0,void 0];if(!t)return r;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(r);if([null,void 0].includes(e)||!o)return o;const h=new i(r,n,this.t);e=this.o(e,h);const u=this.u(n);return!(!Object.values(e).every(t=>!t)||Object.values(u).length)||Object.entries(e).every(([t,e])=>u[t]==e)}get h(){var t,e,i;const{host:s="",pathname:r="",search:n=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??s,pathname:(null===(e=this.t.location)||void 0===e?void 0:e.pathname)??r,search:(null===(i=this.t.location)||void 0===i?void 0:i.search)??n}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},e=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,s)=>i[s]?{...t,[i[s].name]:e}:{...t,[e]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.l(e),...this.g(t,e.bindings)}}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}g(t,e={}){return Object.entries(t).reduce((t,[i,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===i)return{...t,[i]:s};if(!s.hasOwnProperty(e[i])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${e[i]}'.`);e[i]="id"}return{...t,[i]:s[e[i]]}},{})}u(t){var i;let s=this.h.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const r=(t,e="",i)=>{const[s,r]=[t,e].map(t=>t.split(i));return r.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&s[i]?{...t,[e.replace(/^{|\??}$/g,"")]:s[i]}:t,{})};return{...r(this.h.host,t.domain,"."),...r(s,t.uri,"/"),...e.parse(null===(i=this.h.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}t.ZiggyVue={install:(t,e)=>t.mixin({methods:{route:(t,i,r,n=e)=>function(t,e,i,r){const n=new s(t,e,i,r);return t?n.toString():n}(t,i,r,n)}})}}); |
@@ -1,1 +0,1 @@ | ||
import{stringify as t,parse as r}from"qs";class i{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.config=i}get template(){return((this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:"")+"/"+this.definition.uri).replace(/\/+$/,"")}get parameterSegments(){var t,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;if([null,void 0].includes(t[i])&&this.parameterSegments.find(({name:t})=>t===i).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+this.name+"'.");return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class e extends String{constructor(t,r,e=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:e},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new i(t,this.t.routes[t],this.t),this.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>({...t,[r]:this.s[r]}),{});return this.i.compile(this.s)+t({...r,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new i(t,s,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);if([null,void 0].includes(r)||!o)return o;const h=new i(s,n,this.t);r=this.o(r,h);const u=this.h(n);return!(!Object.values(r).every(t=>!t)||Object.values(u).length)||Object.entries(r).every(([t,r])=>u[t]==r)}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,e)=>i[e]?{...t,[i[e].name]:r}:{...t,[r]:""},{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(r),...this.l(t,r.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>({...t,[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[i,e])=>{if(!e||"object"!=typeof e||Array.isArray(e)||"_query"===i)return{...t,[i]:e};if(!e.hasOwnProperty(r[i])){if(!e.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+r[i]+"'.");r[i]="id"}return{...t,[i]:e[r[i]]}},{})}h(t){var i;let e=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,r="",i)=>{const[e,s]=[t,r].map(t=>t.split(i));return s.reduce((t,r,i)=>/^{[^}?]+\??}$/.test(r)&&e[i]?{...t,[r.replace(/^{|\??}$/g,"")]:e[i]}:t,{})};return{...s(window.location.host,t.domain,"."),...s(e,t.uri,"/"),...r(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}const s={install:(t,r)=>t.mixin({methods:{route:(t,i,s,n=r)=>function(t,r,i,s){const n=new e(t,r,i,s);return t?n.toString():n}(t,i,s,n)}})};export{s as ZiggyVue}; | ||
import{stringify as t,parse as i}from"qs";class e{constructor(t,i,e){this.name=t,this.definition=i,this.bindings=i.bindings??{},this.config=e}get template(){return`${this.config.absolute?this.definition.domain?`${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port?":"+this.config.port:""}`:this.config.url:""}/${this.definition.uri}`.replace(/\/+$/,"")}get parameterSegments(){var t;return(null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))??[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const i=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${i}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(i,e)=>{if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(t[e]??"")}).replace(/\/+$/,""):this.template}}class r extends String{constructor(t,i,r=!0,s){if(super(),this.t=s??Ziggy??(null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy),this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new e(t,this.t.routes[t],this.t),this.s=this.h(i)}}toString(){const i=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:i})=>i===t)).filter(t=>"_query"!==t).reduce((t,i)=>({...t,[i]:this.s[i]}),{});return this.i.compile(this.s)+t({...i,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,i)=>"boolean"==typeof t?Number(t):i(t)})}current(t,i){const r=this.t.absolute?this.o.host+this.o.pathname:this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const h=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);if([null,void 0].includes(i)||!h)return h;const o=new e(s,n,this.t);i=this.h(i,o);const u=this.u(n);return!(!Object.values(i).every(t=>!t)||Object.values(u).length)||Object.entries(i).every(([t,i])=>u[t]==i)}get o(){var t,i,e;const{host:r="",pathname:s="",search:n=""}="undefined"!=typeof window?window.location:{};return{host:(null===(t=this.t.location)||void 0===t?void 0:t.host)??r,pathname:(null===(i=this.t.location)||void 0===i?void 0:i.pathname)??s,search:(null===(e=this.t.location)||void 0===e?void 0:e.search)??n}}get params(){return this.u(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},i=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=i.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,i,r)=>e[r]?{...t,[e[r].name]:i}:{...t,[i]:""},{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(i.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),{...this.l(i),...this.g(t,i.bindings)}}l(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:i},e)=>({...t,[i]:this.t.defaults[i]}),{})}g(t,i={}){return Object.entries(t).reduce((t,[e,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===e)return{...t,[e]:r};if(!r.hasOwnProperty(i[e])){if(!r.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${i[e]}'.`);i[e]="id"}return{...t,[e]:r[i[e]]}},{})}u(t){var e;let r=this.o.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,i="",e)=>{const[r,s]=[t,i].map(t=>t.split(e));return s.reduce((t,i,e)=>/^{[^}?]+\??}$/.test(i)&&r[e]?{...t,[i.replace(/^{|\??}$/g,"")]:r[e]}:t,{})};return{...s(this.o.host,t.domain,"."),...s(r,t.uri,"/"),...i(null===(e=this.o.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}const s={install:(t,i)=>t.mixin({methods:{route:(t,e,s,n=i)=>function(t,i,e,s){const n=new r(t,i,e,s);return t?n.toString():n}(t,e,s,n)}})};export{s as ZiggyVue}; |
{ | ||
"name": "ziggy-js", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Use your Laravel named routes in JavaScript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -73,4 +73,4 @@ import { parse, stringify } from 'qs'; | ||
const url = this._config.absolute | ||
? window.location.host + window.location.pathname | ||
: window.location.pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/'); | ||
? this._location.host + this._location.pathname | ||
: this._location.pathname.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '').replace(/^\/+/, '/'); | ||
@@ -105,2 +105,18 @@ // Find the first route that matches the current URL | ||
/** | ||
* Get an object representing the current location (by default this will be | ||
* the JavaScript `window` global if it's available). | ||
* | ||
* @return {Object} | ||
*/ | ||
get _location() { | ||
const { host = '', pathname = '', search = '' } = typeof window !== 'undefined' ? window.location : {}; | ||
return { | ||
host: this._config.location?.host ?? host, | ||
pathname: this._config.location?.pathname ?? pathname, | ||
search: this._config.location?.search ?? search, | ||
}; | ||
} | ||
/** | ||
* Get all parameter values from the current window URL. | ||
@@ -228,3 +244,3 @@ * | ||
_dehydrate(route) { | ||
let pathname = window.location.pathname | ||
let pathname = this._location.pathname | ||
// If this Laravel app is in a subdirectory, trim the subdirectory from the path | ||
@@ -250,5 +266,5 @@ .replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '') | ||
return { | ||
...dehydrate(window.location.host, route.domain, '.'), // Domain parameters | ||
...dehydrate(this._location.host, route.domain, '.'), // Domain parameters | ||
...dehydrate(pathname, route.uri, '/'), // Path parameters | ||
...parse(window.location.search?.replace(/^\?/, '')), // Query parameters | ||
...parse(this._location.search?.replace(/^\?/, '')), // Query parameters | ||
}; | ||
@@ -255,0 +271,0 @@ } |
63890
440