ziggy-js 1.3.6 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,8 @@ Install Ziggy into your Laravel app with `composer require tightenco/ziggy`.
35
35
 
36
36
  Add the `@routes` Blade directive to your main layout (_before_ your application's JavaScript), and the `route()` helper function will now be available globally!
37
37
 
38
+ > By default, the output of the `@routes` Blade directive includes a list of all your application's routes and their parameters. This route list is included in the HTML of the page and can be viewed by end users. To configure which routes are included in this list, or to show and hide different routes on different pages, see [Filtering Routes](#filtering-routes).
39
+
38
40
  ## Usage
39
41
 
40
42
  #### The `route()` helper
@@ -593,7 +595,7 @@ Thanks to [Caleb Porzio](http://twitter.com/calebporzio), [Adam Wathan](http://t
593
595
 
594
596
  ## Security
595
597
 
596
- If you discover any security related issues, please email <hello@tighten.co> instead of using the issue tracker.
598
+ Please review our [security policy](../../security/policy) on how to report security vulnerabilities.
597
599
 
598
600
  ## License
599
601
 
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- 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)}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))}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,{bindings:i,parameterSegments:e}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!e.some(({name:t})=>t===s))return r({},t,{[s]:n});if(!n.hasOwnProperty(i[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${i[s]}'.`);i[s]="id"}return r({},t,{[s]:n[i[s]]})},{})}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
+ import{stringify as t,parse as e}from"qs";function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},i.apply(this,arguments)}class r{constructor(t,e,i){var r,s;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},this.wheres=null!=(s=e.wheres)?s:{},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.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(/{[^}]+}/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,s;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 this.parameterSegments[this.parameterSegments.length-1].name===i&&".*"===this.wheres[i]?null!=(s=t[i])?s:"":encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,e,s=!0,n){if(super(),this.t=null!=n?n:"undefined"!=typeof Ziggy?Ziggy:null==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 r(t,this.t.routes[t],this.t),this.h=this.o(e)}}toString(){const e=Object.keys(this.h).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>i({},t,{[e]:this.h[e]}),{});return this.i.compile(this.h)+t(i({},e,this.h._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const i=this.t.absolute?this.u().host+this.u().pathname:this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([e,s])=>new r(t,s,this.t).matchesUrl(i))||[void 0,void 0];if(!t)return s;const h=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(s);if([null,void 0].includes(e)||!h)return h;const o=new r(s,n,this.t);e=this.o(e,o);const u=this.l(n);return!(!Object.values(e).every(t=>!t)||Object.values(u).length)||Object.entries(e).every(([t,e])=>u[t]==e)}u(){var t,e,i,r,s,n;const{host:h="",pathname:o="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:h,pathname:null!=(i=null==(r=this.t.location)?void 0:r.pathname)?i:o,search:null!=(s=null==(n=this.t.location)?void 0:n.search)?s:u}}get params(){return this.l(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 r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,s)=>i({},t,r[s]?{[r[s].name]:e}:{[e]:""}),{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),i({},this.g(e),this.m(t,e))}g(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>i({},t,{[e]:this.t.defaults[e]}),{})}m(t,{bindings:e,parameterSegments:r}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!r.some(({name:t})=>t===s))return i({},t,{[s]:n});if(!n.hasOwnProperty(e[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${e[s]}'.`);e[s]="id"}return i({},t,{[s]:n[e[s]]})},{})}l(t){var r;let s=this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[s,n]=[t,e].map(t=>t.split(r));return n.reduce((t,e,r)=>/{[^}?]+\??}/.test(e)&&s[r]?i({},t,{[e.replace(/.*{|\??}.*/g,"")]:s[r].replace(e.match(/^[^{]*/g),"").replace(e.match(/[^}]*$/g),"")}):t,{})};return i({},n(this.u().host,t.domain,"."),n(s,t.uri,"/"),e(null==(r=this.u().search)?void 0:r.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}function n(t,e,i,r){const n=new s(t,e,i,r);return t?n.toString():n}export{n as default};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("qs")):"function"==typeof define&&define.amd?define(["qs"],t):(n=n||self).route=t(n.qs)}(this,function(n){function t(n,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}function r(n,r,i){return r&&t(n.prototype,r),i&&t(n,i),n}function i(){return(i=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])}return n}).apply(this,arguments)}function e(n){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)})(n)}function u(n,t){return(u=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n})(n,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(n){return!1}}function f(n,t,r){return(f=o()?Reflect.construct:function(n,t,r){var i=[null];i.push.apply(i,t);var e=new(Function.bind.apply(n,i));return r&&u(e,r.prototype),e}).apply(null,arguments)}function c(n){var t="function"==typeof Map?new Map:void 0;return(c=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return f(n,arguments,e(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,n)})(n)}var s=function(){function n(n,t,r){var i;this.name=n,this.definition=t,this.bindings=null!=(i=t.bindings)?i:{},this.config=r}var t=n.prototype;return t.matchesUrl=function(n){if(!this.definition.methods.includes("GET"))return!1;var t=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+t+"$").test(n.replace(/\/+$/,"").split("?").shift())},t.compile=function(n){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e;if([null,void 0].includes(n[i])&&t.parameterSegments.find(function(n){return n.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+t.name+"'.");return encodeURIComponent(null!=(e=n[i])?e:"")}).replace(/\/+$/,""):this.template},r(n,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var n,t;return null!=(n=null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),a=function(t){var e,u;function o(n,r,e,u){var o,f;if(void 0===e&&(e=!0),(f=t.call(this)||this).t=null!=(o=null!=u?u:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=i({},f.t,{absolute:e}),n){if(!f.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");f.i=new s(n,f.t.routes[n],f.t),f.u=f.o(r)}return f}u=t,(e=o).prototype=Object.create(u.prototype),e.prototype.constructor=e,e.__proto__=u;var f=o.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(n){return"_query"!==n}).reduce(function(n,r){var e;return i({},n,((e={})[r]=t.u[r],e))},{});return this.i.compile(this.u)+n.stringify(i({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(n,t){return"boolean"==typeof n?Number(n):t(n)}})},f.current=function(n,t){var r=this,i=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(t){return new s(n,t[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!n)return u;var f=new RegExp("^"+n.replace(".","\\.").replace("*",".*")+"$").test(u);if([null,void 0].includes(t)||!f)return f;var c=new s(u,o,this.t);t=this.o(t,c);var a=this.h(o);return!(!Object.values(t).every(function(n){return!n})||Object.values(a).length)||Object.entries(t).every(function(n){return a[n[0]]==n[1]})},f.s=function(){var n,t,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(n=null===(t=this.t.location)||void 0===t?void 0:t.host)?n:void 0===f?"":f,pathname:null!=(r=null===(i=this.t.location)||void 0===i?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null===(u=this.t.location)||void 0===u?void 0:u.search)?e:void 0===s?"":s}},f.has=function(n){return Object.keys(this.t.routes).includes(n)},f.o=function(n,t){var r=this;void 0===n&&(n={}),void 0===t&&(t=this.i),n=["string","number"].includes(typeof n)?[n]:n;var e=t.parameterSegments.filter(function(n){return!r.t.defaults[n.name]});if(Array.isArray(n))n=n.reduce(function(n,t,r){var u,o;return i({},n,e[r]?((u={})[e[r].name]=t,u):((o={})[t]="",o))},{});else if(1===e.length&&!n[e[0].name]&&(n.hasOwnProperty(Object.values(t.bindings)[0])||n.hasOwnProperty("id"))){var u;(u={})[e[0].name]=n,n=u}return i({},this.l(t),this.v(n,t))},f.l=function(n){var t=this;return n.parameterSegments.filter(function(n){return t.t.defaults[n.name]}).reduce(function(n,r,e){var u,o=r.name;return i({},n,((u={})[o]=t.t.defaults[o],u))},{})},f.v=function(n,t){var r=t.bindings,e=t.parameterSegments;return Object.entries(n).reduce(function(n,t){var u,o,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(n){return n.name===f}))return i({},n,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return i({},n,((u={})[f]=c[r[f]],u))},{})},f.h=function(t){var r,e=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(n,t,r){void 0===t&&(t="");var e=[n,t].map(function(n){return n.split(r)}),u=e[0];return e[1].reduce(function(n,t,r){var e;return/^{[^}?]+\??}$/.test(t)&&u[r]?i({},n,((e={})[t.replace(/^{|\??}$/g,"")]=u[r],e)):n},{})};return i({},u(this.s().host,t.domain,"."),u(e,t.uri,"/"),n.parse(null===(r=this.s().search)||void 0===r?void 0:r.replace(/^\?/,"")))},f.valueOf=function(){return this.toString()},f.check=function(n){return this.has(n)},r(o,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),o}(c(String));return function(n,t,r,i){var e=new a(n,t,r,i);return n?e.toString():e}});
1
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("qs")):"function"==typeof define&&define.amd?define(["qs"],t):(n||self).route=t(n.qs)}(this,function(n){function t(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}function r(n,r,e){return r&&t(n.prototype,r),e&&t(n,e),Object.defineProperty(n,"prototype",{writable:!1}),n}function e(){return e=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},e.apply(this,arguments)}function i(n){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},i(n)}function u(n,t){return u=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n},u(n,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(n){return!1}}function f(n,t,r){return f=o()?Reflect.construct:function(n,t,r){var e=[null];e.push.apply(e,t);var i=new(Function.bind.apply(n,e));return r&&u(i,r.prototype),i},f.apply(null,arguments)}function c(n){var t="function"==typeof Map?new Map:void 0;return c=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return f(n,arguments,i(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,n)},c(n)}var s=/*#__PURE__*/function(){function n(n,t,r){var e,i;this.name=n,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},this.wheres=null!=(i=t.wheres)?i:{},this.config=r}var t=n.prototype;return t.matchesUrl=function(n){if(!this.definition.methods.includes("GET"))return!1;var t=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}?]*\?}/g,"([^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+t+"$").test(n.replace(/\/+$/,"").split("?").shift())},t.compile=function(n){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,e){var i,u;if([null,void 0].includes(n[e])&&t.parameterSegments.find(function(n){return n.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");return t.parameterSegments[t.parameterSegments.length-1].name===e&&".*"===t.wheres[e]?null!=(u=n[e])?u:"":encodeURIComponent(null!=(i=n[e])?i:"")}).replace(/\/+$/,""):this.template},r(n,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var n,t;return null!=(n=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),a=/*#__PURE__*/function(t){var i,o;function f(n,r,i,u){var o;if(void 0===i&&(i=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=e({},o.t,{absolute:i}),n){if(!o.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");o.i=new s(n,o.t.routes[n],o.t),o.u=o.o(r)}return o}o=t,(i=f).prototype=Object.create(o.prototype),i.prototype.constructor=i,u(i,o);var c=f.prototype;return c.toString=function(){var t=this,r=Object.keys(this.u).filter(function(n){return!t.i.parameterSegments.some(function(t){return t.name===n})}).filter(function(n){return"_query"!==n}).reduce(function(n,r){var i;return e({},n,((i={})[r]=t.u[r],i))},{});return this.i.compile(this.u)+n.stringify(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(n,t){return"boolean"==typeof n?Number(n):t(n)}})},c.current=function(n,t){var r=this,e=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(t){return new s(n,t[1],r.t).matchesUrl(e)})||[void 0,void 0],u=i[0],o=i[1];if(!n)return u;var f=new RegExp("^"+n.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(u);if([null,void 0].includes(t)||!f)return f;var c=new s(u,o,this.t);t=this.o(t,c);var a=this.h(o);return!(!Object.values(t).every(function(n){return!n})||Object.values(a).length)||Object.entries(t).every(function(n){return a[n[0]]==n[1]})},c.l=function(){var n,t,r,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(n=null==(t=this.t.location)?void 0:t.host)?n:void 0===f?"":f,pathname:null!=(r=null==(e=this.t.location)?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===s?"":s}},c.has=function(n){return Object.keys(this.t.routes).includes(n)},c.o=function(n,t){var r=this;void 0===n&&(n={}),void 0===t&&(t=this.i),n=["string","number"].includes(typeof n)?[n]:n;var i=t.parameterSegments.filter(function(n){return!r.t.defaults[n.name]});if(Array.isArray(n))n=n.reduce(function(n,t,r){var u,o;return e({},n,i[r]?((u={})[i[r].name]=t,u):((o={})[t]="",o))},{});else if(1===i.length&&!n[i[0].name]&&(n.hasOwnProperty(Object.values(t.bindings)[0])||n.hasOwnProperty("id"))){var u;(u={})[i[0].name]=n,n=u}return e({},this.v(t),this.g(n,t))},c.v=function(n){var t=this;return n.parameterSegments.filter(function(n){return t.t.defaults[n.name]}).reduce(function(n,r,i){var u,o=r.name;return e({},n,((u={})[o]=t.t.defaults[o],u))},{})},c.g=function(n,t){var r=t.bindings,i=t.parameterSegments;return Object.entries(n).reduce(function(n,t){var u,o,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(n){return n.name===f}))return e({},n,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},n,((u={})[f]=c[r[f]],u))},{})},c.h=function(t){var r,i=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(n,t,r){void 0===t&&(t="");var i=[n,t].map(function(n){return n.split(r)}),u=i[0];return i[1].reduce(function(n,t,r){var i;return/{[^}?]+\??}/.test(t)&&u[r]?e({},n,((i={})[t.replace(/.*{|\??}.*/g,"")]=u[r].replace(t.match(/^[^{]*/g),"").replace(t.match(/[^}]*$/g),""),i)):n},{})};return e({},u(this.l().host,t.domain,"."),u(i,t.uri,"/"),n.parse(null==(r=this.l().search)?void 0:r.replace(/^\?/,"")))},c.valueOf=function(){return this.toString()},c.check=function(n){return this.has(n)},r(f,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),f}(/*#__PURE__*/c(String));return function(n,t,r,e){var i=new a(n,t,r,e);return n?i.toString():i}});
package/dist/index.m.js CHANGED
@@ -1 +1 @@
1
- import{stringify as t,parse as n}from"qs";function r(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t,n,i){return n&&r(t.prototype,n),i&&r(t,i),t}function e(){return(e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,n){return(o=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function c(t,n,r){return(c=f()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var e=new(Function.bind.apply(t,i));return r&&o(e,r.prototype),e}).apply(null,arguments)}function s(t){var n="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return c(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)})(t)}var a=function(){function t(t,n,r){var i;this.name=t,this.definition=n,this.bindings=null!=(i=n.bindings)?i:{},this.config=r}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e;if([null,void 0].includes(t[i])&&n.parameterSegments.find(function(t){return t.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+n.name+"'.");return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template},i(t,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null===(n=this.template.match(/{[^}?]+\??}/g))||void 0===n?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),h=function(r){var u,o;function f(t,n,i,u){var o,f;if(void 0===i&&(i=!0),(f=r.call(this)||this).t=null!=(o=null!=u?u:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=e({},f.t,{absolute:i}),t){if(!f.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");f.i=new a(t,f.t.routes[t],f.t),f.u=f.o(n)}return f}o=r,(u=f).prototype=Object.create(o.prototype),u.prototype.constructor=u,u.__proto__=o;var c=f.prototype;return c.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(t){return"_query"!==t}).reduce(function(t,r){var i;return e({},t,((i={})[r]=n.u[r],i))},{});return this.i.compile(this.u)+t(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},c.current=function(t,n){var r=this,i=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(n){return new a(t,n[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!t)return u;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(u);if([null,void 0].includes(n)||!f)return f;var c=new a(u,o,this.t);n=this.o(n,c);var s=this.h(o);return!(!Object.values(n).every(function(t){return!t})||Object.values(s).length)||Object.entries(n).every(function(t){return s[t[0]]==t[1]})},c.s=function(){var t,n,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null===(n=this.t.location)||void 0===n?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null===(i=this.t.location)||void 0===i?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null===(u=this.t.location)||void 0===u?void 0:u.search)?e:void 0===s?"":s}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return e({},t,i[r]?((u={})[i[r].name]=n,u):((o={})[n]="",o))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[i[0].name]=t,t=u}return e({},this.l(n),this.v(t,n))},c.l=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,i){var u,o=r.name;return e({},t,((u={})[o]=n.t.defaults[o],u))},{})},c.v=function(t,n){var r=n.bindings,i=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(t){return t.name===f}))return e({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},t,((u={})[f]=c[r[f]],u))},{})},c.h=function(t){var r,i=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(t,n,r){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(r)}),u=i[0];return i[1].reduce(function(t,n,r){var i;return/^{[^}?]+\??}$/.test(n)&&u[r]?e({},t,((i={})[n.replace(/^{|\??}$/g,"")]=u[r],i)):t},{})};return e({},u(this.s().host,t.domain,"."),u(i,t.uri,"/"),n(null===(r=this.s().search)||void 0===r?void 0:r.replace(/^\?/,"")))},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},i(f,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),f}(s(String));export default function(t,n,r,i){var e=new h(t,n,r,i);return t?e.toString():e}
1
+ import{stringify as t,parse as n}from"qs";function r(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t,n,i){return n&&r(t.prototype,n),i&&r(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(){return e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},e.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,n){return o=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t},o(t,n)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function c(t,n,r){return c=f()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var e=new(Function.bind.apply(t,i));return r&&o(e,r.prototype),e},c.apply(null,arguments)}function s(t){var n="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return c(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},s(t)}var a=/*#__PURE__*/function(){function t(t,n,r){var i,e;this.name=t,this.definition=n,this.bindings=null!=(i=n.bindings)?i:{},this.wheres=null!=(e=n.wheres)?e:{},this.config=r}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}?]*\?}/g,"([^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e,u;if([null,void 0].includes(t[i])&&n.parameterSegments.find(function(t){return t.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+n.name+"'.");return n.parameterSegments[n.parameterSegments.length-1].name===i&&".*"===n.wheres[i]?null!=(u=t[i])?u:"":encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template},i(t,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null==(n=this.template.match(/{[^}?]+\??}/g))?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),l=/*#__PURE__*/function(r){var u,f;function c(t,n,i,u){var o;if(void 0===i&&(i=!0),(o=r.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=e({},o.t,{absolute:i}),t){if(!o.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");o.i=new a(t,o.t.routes[t],o.t),o.u=o.o(n)}return o}f=r,(u=c).prototype=Object.create(f.prototype),u.prototype.constructor=u,o(u,f);var s=c.prototype;return s.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(t){return"_query"!==t}).reduce(function(t,r){var i;return e({},t,((i={})[r]=n.u[r],i))},{});return this.i.compile(this.u)+t(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},s.current=function(t,n){var r=this,i=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(n){return new a(t,n[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!t)return u;var f=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(u);if([null,void 0].includes(n)||!f)return f;var c=new a(u,o,this.t);n=this.o(n,c);var s=this.h(o);return!(!Object.values(n).every(function(t){return!t})||Object.values(s).length)||Object.entries(n).every(function(t){return s[t[0]]==t[1]})},s.l=function(){var t,n,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null==(n=this.t.location)?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null==(i=this.t.location)?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null==(u=this.t.location)?void 0:u.search)?e:void 0===s?"":s}},s.has=function(t){return Object.keys(this.t.routes).includes(t)},s.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return e({},t,i[r]?((u={})[i[r].name]=n,u):((o={})[n]="",o))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[i[0].name]=t,t=u}return e({},this.v(n),this.g(t,n))},s.v=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,i){var u,o=r.name;return e({},t,((u={})[o]=n.t.defaults[o],u))},{})},s.g=function(t,n){var r=n.bindings,i=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(t){return t.name===f}))return e({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},t,((u={})[f]=c[r[f]],u))},{})},s.h=function(t){var r,i=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(t,n,r){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(r)}),u=i[0];return i[1].reduce(function(t,n,r){var i;return/{[^}?]+\??}/.test(n)&&u[r]?e({},t,((i={})[n.replace(/.*{|\??}.*/g,"")]=u[r].replace(n.match(/^[^{]*/g),"").replace(n.match(/[^}]*$/g),""),i)):t},{})};return e({},u(this.l().host,t.domain,"."),u(i,t.uri,"/"),n(null==(r=this.l().search)?void 0:r.replace(/^\?/,"")))},s.valueOf=function(){return this.toString()},s.check=function(t){return this.has(t)},i(c,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),c}(/*#__PURE__*/s(String));function h(t,n,r,i){var e=new l(t,n,r,i);return t?e.toString():e}export{h as default};
package/dist/vue.es.js CHANGED
@@ -1 +1 @@
1
- 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)}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))}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,{bindings:i,parameterSegments:e}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!e.some(({name:t})=>t===s))return r({},t,{[s]:n});if(!n.hasOwnProperty(i[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${i[s]}'.`);i[s]="id"}return r({},t,{[s]:n[i[s]]})},{})}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
+ import{stringify as t,parse as e}from"qs";function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},i.apply(this,arguments)}class r{constructor(t,e,i){var r,s;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},this.wheres=null!=(s=e.wheres)?s:{},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.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(/{[^}]+}/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,s;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 this.parameterSegments[this.parameterSegments.length-1].name===i&&".*"===this.wheres[i]?null!=(s=t[i])?s:"":encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,e,s=!0,n){if(super(),this.t=null!=n?n:"undefined"!=typeof Ziggy?Ziggy:null==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 r(t,this.t.routes[t],this.t),this.h=this.o(e)}}toString(){const e=Object.keys(this.h).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>i({},t,{[e]:this.h[e]}),{});return this.i.compile(this.h)+t(i({},e,this.h._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,e){const i=this.t.absolute?this.u().host+this.u().pathname:this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([e,s])=>new r(t,s,this.t).matchesUrl(i))||[void 0,void 0];if(!t)return s;const h=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(s);if([null,void 0].includes(e)||!h)return h;const o=new r(s,n,this.t);e=this.o(e,o);const u=this.l(n);return!(!Object.values(e).every(t=>!t)||Object.values(u).length)||Object.entries(e).every(([t,e])=>u[t]==e)}u(){var t,e,i,r,s,n;const{host:h="",pathname:o="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:h,pathname:null!=(i=null==(r=this.t.location)?void 0:r.pathname)?i:o,search:null!=(s=null==(n=this.t.location)?void 0:n.search)?s:u}}get params(){return this.l(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 r=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,s)=>i({},t,r[s]?{[r[s].name]:e}:{[e]:""}),{}):1!==r.length||t[r[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[r[0].name]:t}),i({},this.g(e),this.m(t,e))}g(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},r)=>i({},t,{[e]:this.t.defaults[e]}),{})}m(t,{bindings:e,parameterSegments:r}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!r.some(({name:t})=>t===s))return i({},t,{[s]:n});if(!n.hasOwnProperty(e[s])){if(!n.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${s}' parameter is missing route model binding key '${e[s]}'.`);e[s]="id"}return i({},t,{[s]:n[e[s]]})},{})}l(t){var r;let s=this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",r)=>{const[s,n]=[t,e].map(t=>t.split(r));return n.reduce((t,e,r)=>/{[^}?]+\??}/.test(e)&&s[r]?i({},t,{[e.replace(/.*{|\??}.*/g,"")]:s[r].replace(e.match(/^[^{]*/g),"").replace(e.match(/[^}]*$/g),"")}):t,{})};return i({},n(this.u().host,t.domain,"."),n(s,t.uri,"/"),e(null==(r=this.u().search)?void 0:r.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}const n={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)}})};export{n as ZiggyVue};
package/dist/vue.js CHANGED
@@ -1 +1 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],t):t((n=n||self).ZiggyVue={},n.qs)}(this,function(n,t){function r(n,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}function i(n,t,i){return t&&r(n.prototype,t),i&&r(n,i),n}function e(){return(e=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])}return n}).apply(this,arguments)}function u(n){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)})(n)}function o(n,t){return(o=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n})(n,t)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(n){return!1}}function c(n,t,r){return(c=f()?Reflect.construct:function(n,t,r){var i=[null];i.push.apply(i,t);var e=new(Function.bind.apply(n,i));return r&&o(e,r.prototype),e}).apply(null,arguments)}function s(n){var t="function"==typeof Map?new Map:void 0;return(s=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return c(n,arguments,u(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,n)})(n)}var a=function(){function n(n,t,r){var i;this.name=n,this.definition=t,this.bindings=null!=(i=t.bindings)?i:{},this.config=r}var t=n.prototype;return t.matchesUrl=function(n){if(!this.definition.methods.includes("GET"))return!1;var t=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+t+"$").test(n.replace(/\/+$/,"").split("?").shift())},t.compile=function(n){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e;if([null,void 0].includes(n[i])&&t.parameterSegments.find(function(n){return n.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+t.name+"'.");return encodeURIComponent(null!=(e=n[i])?e:"")}).replace(/\/+$/,""):this.template},i(n,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var n,t;return null!=(n=null===(t=this.template.match(/{[^}?]+\??}/g))||void 0===t?void 0:t.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),h=function(n){var r,u;function o(t,r,i,u){var o,f;if(void 0===i&&(i=!0),(f=n.call(this)||this).t=null!=(o=null!=u?u:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=e({},f.t,{absolute:i}),t){if(!f.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");f.i=new a(t,f.t.routes[t],f.t),f.u=f.o(r)}return f}u=n,(r=o).prototype=Object.create(u.prototype),r.prototype.constructor=r,r.__proto__=u;var f=o.prototype;return f.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(n){return"_query"!==n}).reduce(function(t,r){var i;return e({},t,((i={})[r]=n.u[r],i))},{});return this.i.compile(this.u)+t.stringify(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(n,t){return"boolean"==typeof n?Number(n):t(n)}})},f.current=function(n,t){var r=this,i=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(t){return new a(n,t[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!n)return u;var f=new RegExp("^"+n.replace(".","\\.").replace("*",".*")+"$").test(u);if([null,void 0].includes(t)||!f)return f;var c=new a(u,o,this.t);t=this.o(t,c);var s=this.h(o);return!(!Object.values(t).every(function(n){return!n})||Object.values(s).length)||Object.entries(t).every(function(n){return s[n[0]]==n[1]})},f.s=function(){var n,t,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(n=null===(t=this.t.location)||void 0===t?void 0:t.host)?n:void 0===f?"":f,pathname:null!=(r=null===(i=this.t.location)||void 0===i?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null===(u=this.t.location)||void 0===u?void 0:u.search)?e:void 0===s?"":s}},f.has=function(n){return Object.keys(this.t.routes).includes(n)},f.o=function(n,t){var r=this;void 0===n&&(n={}),void 0===t&&(t=this.i),n=["string","number"].includes(typeof n)?[n]:n;var i=t.parameterSegments.filter(function(n){return!r.t.defaults[n.name]});if(Array.isArray(n))n=n.reduce(function(n,t,r){var u,o;return e({},n,i[r]?((u={})[i[r].name]=t,u):((o={})[t]="",o))},{});else if(1===i.length&&!n[i[0].name]&&(n.hasOwnProperty(Object.values(t.bindings)[0])||n.hasOwnProperty("id"))){var u;(u={})[i[0].name]=n,n=u}return e({},this.l(t),this.v(n,t))},f.l=function(n){var t=this;return n.parameterSegments.filter(function(n){return t.t.defaults[n.name]}).reduce(function(n,r,i){var u,o=r.name;return e({},n,((u={})[o]=t.t.defaults[o],u))},{})},f.v=function(n,t){var r=t.bindings,i=t.parameterSegments;return Object.entries(n).reduce(function(n,t){var u,o,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(n){return n.name===f}))return e({},n,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},n,((u={})[f]=c[r[f]],u))},{})},f.h=function(n){var r,i=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(n,t,r){void 0===t&&(t="");var i=[n,t].map(function(n){return n.split(r)}),u=i[0];return i[1].reduce(function(n,t,r){var i;return/^{[^}?]+\??}$/.test(t)&&u[r]?e({},n,((i={})[t.replace(/^{|\??}$/g,"")]=u[r],i)):n},{})};return e({},u(this.s().host,n.domain,"."),u(i,n.uri,"/"),t.parse(null===(r=this.s().search)||void 0===r?void 0:r.replace(/^\?/,"")))},f.valueOf=function(){return this.toString()},f.check=function(n){return this.has(n)},i(o,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),o}(s(String));n.ZiggyVue={install:function(n,t){return n.mixin({methods:{route:function(n,r,i,e){return void 0===e&&(e=t),function(n,t,r,i){var e=new h(n,t,r,i);return n?e.toString():e}(n,r,i,e)}}})}}});
1
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("qs")):"function"==typeof define&&define.amd?define(["exports","qs"],t):t((n||self).ZiggyVue={},n.qs)}(this,function(n,t){function r(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}function e(n,t,e){return t&&r(n.prototype,t),e&&r(n,e),Object.defineProperty(n,"prototype",{writable:!1}),n}function i(){return i=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},i.apply(this,arguments)}function u(n){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},u(n)}function o(n,t){return o=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n},o(n,t)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(n){return!1}}function c(n,t,r){return c=f()?Reflect.construct:function(n,t,r){var e=[null];e.push.apply(e,t);var i=new(Function.bind.apply(n,e));return r&&o(i,r.prototype),i},c.apply(null,arguments)}function s(n){var t="function"==typeof Map?new Map:void 0;return s=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return c(n,arguments,u(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,n)},s(n)}var a=/*#__PURE__*/function(){function n(n,t,r){var e,i;this.name=n,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},this.wheres=null!=(i=t.wheres)?i:{},this.config=r}var t=n.prototype;return t.matchesUrl=function(n){if(!this.definition.methods.includes("GET"))return!1;var t=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}?]*\?}/g,"([^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+t+"$").test(n.replace(/\/+$/,"").split("?").shift())},t.compile=function(n){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,e){var i,u;if([null,void 0].includes(n[e])&&t.parameterSegments.find(function(n){return n.name===e}).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");return t.parameterSegments[t.parameterSegments.length-1].name===e&&".*"===t.wheres[e]?null!=(u=n[e])?u:"":encodeURIComponent(null!=(i=n[e])?i:"")}).replace(/\/+$/,""):this.template},e(n,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var n,t;return null!=(n=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),l=/*#__PURE__*/function(n){var r,u;function f(t,r,e,u){var o;if(void 0===e&&(e=!0),(o=n.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),t){if(!o.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");o.i=new a(t,o.t.routes[t],o.t),o.u=o.o(r)}return o}u=n,(r=f).prototype=Object.create(u.prototype),r.prototype.constructor=r,o(r,u);var c=f.prototype;return c.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(n){return"_query"!==n}).reduce(function(t,r){var e;return i({},t,((e={})[r]=n.u[r],e))},{});return this.i.compile(this.u)+t.stringify(i({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(n,t){return"boolean"==typeof n?Number(n):t(n)}})},c.current=function(n,t){var r=this,e=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),i=Object.entries(this.t.routes).find(function(t){return new a(n,t[1],r.t).matchesUrl(e)})||[void 0,void 0],u=i[0],o=i[1];if(!n)return u;var f=new RegExp("^"+n.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(u);if([null,void 0].includes(t)||!f)return f;var c=new a(u,o,this.t);t=this.o(t,c);var s=this.h(o);return!(!Object.values(t).every(function(n){return!n})||Object.values(s).length)||Object.entries(t).every(function(n){return s[n[0]]==n[1]})},c.l=function(){var n,t,r,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(n=null==(t=this.t.location)?void 0:t.host)?n:void 0===f?"":f,pathname:null!=(r=null==(e=this.t.location)?void 0:e.pathname)?r:void 0===c?"":c,search:null!=(i=null==(u=this.t.location)?void 0:u.search)?i:void 0===s?"":s}},c.has=function(n){return Object.keys(this.t.routes).includes(n)},c.o=function(n,t){var r=this;void 0===n&&(n={}),void 0===t&&(t=this.i),n=["string","number"].includes(typeof n)?[n]:n;var e=t.parameterSegments.filter(function(n){return!r.t.defaults[n.name]});if(Array.isArray(n))n=n.reduce(function(n,t,r){var u,o;return i({},n,e[r]?((u={})[e[r].name]=t,u):((o={})[t]="",o))},{});else if(1===e.length&&!n[e[0].name]&&(n.hasOwnProperty(Object.values(t.bindings)[0])||n.hasOwnProperty("id"))){var u;(u={})[e[0].name]=n,n=u}return i({},this.v(t),this.g(n,t))},c.v=function(n){var t=this;return n.parameterSegments.filter(function(n){return t.t.defaults[n.name]}).reduce(function(n,r,e){var u,o=r.name;return i({},n,((u={})[o]=t.t.defaults[o],u))},{})},c.g=function(n,t){var r=t.bindings,e=t.parameterSegments;return Object.entries(n).reduce(function(n,t){var u,o,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(n){return n.name===f}))return i({},n,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return i({},n,((u={})[f]=c[r[f]],u))},{})},c.h=function(n){var r,e=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(n,t,r){void 0===t&&(t="");var e=[n,t].map(function(n){return n.split(r)}),u=e[0];return e[1].reduce(function(n,t,r){var e;return/{[^}?]+\??}/.test(t)&&u[r]?i({},n,((e={})[t.replace(/.*{|\??}.*/g,"")]=u[r].replace(t.match(/^[^{]*/g),"").replace(t.match(/[^}]*$/g),""),e)):n},{})};return i({},u(this.l().host,n.domain,"."),u(e,n.uri,"/"),t.parse(null==(r=this.l().search)?void 0:r.replace(/^\?/,"")))},c.valueOf=function(){return this.toString()},c.check=function(n){return this.has(n)},e(f,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),f}(/*#__PURE__*/s(String));n.ZiggyVue={install:function(n,t){return n.mixin({methods:{route:function(n,r,e,i){return void 0===i&&(i=t),function(n,t,r,e){var i=new l(n,t,r,e);return n?i.toString():i}(n,r,e,i)}}})}}});
package/dist/vue.m.js CHANGED
@@ -1 +1 @@
1
- import{stringify as t,parse as n}from"qs";function r(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t,n,i){return n&&r(t.prototype,n),i&&r(t,i),t}function e(){return(e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,n){return(o=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function c(t,n,r){return(c=f()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var e=new(Function.bind.apply(t,i));return r&&o(e,r.prototype),e}).apply(null,arguments)}function s(t){var n="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return c(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)})(t)}var a=function(){function t(t,n,r){var i;this.name=t,this.definition=n,this.bindings=null!=(i=n.bindings)?i:{},this.config=r}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e;if([null,void 0].includes(t[i])&&n.parameterSegments.find(function(t){return t.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+n.name+"'.");return encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template},i(t,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null===(n=this.template.match(/{[^}?]+\??}/g))||void 0===n?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),h=function(r){var u,o;function f(t,n,i,u){var o,f;if(void 0===i&&(i=!0),(f=r.call(this)||this).t=null!=(o=null!=u?u:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,f.t=e({},f.t,{absolute:i}),t){if(!f.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");f.i=new a(t,f.t.routes[t],f.t),f.u=f.o(n)}return f}o=r,(u=f).prototype=Object.create(o.prototype),u.prototype.constructor=u,u.__proto__=o;var c=f.prototype;return c.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(t){return"_query"!==t}).reduce(function(t,r){var i;return e({},t,((i={})[r]=n.u[r],i))},{});return this.i.compile(this.u)+t(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},c.current=function(t,n){var r=this,i=this.t.absolute?this.s().host+this.s().pathname:this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(n){return new a(t,n[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!t)return u;var f=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(u);if([null,void 0].includes(n)||!f)return f;var c=new a(u,o,this.t);n=this.o(n,c);var s=this.h(o);return!(!Object.values(n).every(function(t){return!t})||Object.values(s).length)||Object.entries(n).every(function(t){return s[t[0]]==t[1]})},c.s=function(){var t,n,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null===(n=this.t.location)||void 0===n?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null===(i=this.t.location)||void 0===i?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null===(u=this.t.location)||void 0===u?void 0:u.search)?e:void 0===s?"":s}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return e({},t,i[r]?((u={})[i[r].name]=n,u):((o={})[n]="",o))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[i[0].name]=t,t=u}return e({},this.l(n),this.v(t,n))},c.l=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,i){var u,o=r.name;return e({},t,((u={})[o]=n.t.defaults[o],u))},{})},c.v=function(t,n){var r=n.bindings,i=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(t){return t.name===f}))return e({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},t,((u={})[f]=c[r[f]],u))},{})},c.h=function(t){var r,i=this.s().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(t,n,r){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(r)}),u=i[0];return i[1].reduce(function(t,n,r){var i;return/^{[^}?]+\??}$/.test(n)&&u[r]?e({},t,((i={})[n.replace(/^{|\??}$/g,"")]=u[r],i)):t},{})};return e({},u(this.s().host,t.domain,"."),u(i,t.uri,"/"),n(null===(r=this.s().search)||void 0===r?void 0:r.replace(/^\?/,"")))},c.valueOf=function(){return this.toString()},c.check=function(t){return this.has(t)},i(f,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),f}(s(String)),l={install:function(t,n){return t.mixin({methods:{route:function(t,r,i,e){return void 0===e&&(e=n),function(t,n,r,i){var e=new h(t,n,r,i);return t?e.toString():e}(t,r,i,e)}}})}};export{l as ZiggyVue};
1
+ import{stringify as t,parse as n}from"qs";function r(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t,n,i){return n&&r(t.prototype,n),i&&r(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(){return e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},e.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,n){return o=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t},o(t,n)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function c(t,n,r){return c=f()?Reflect.construct:function(t,n,r){var i=[null];i.push.apply(i,n);var e=new(Function.bind.apply(t,i));return r&&o(e,r.prototype),e},c.apply(null,arguments)}function s(t){var n="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return c(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},s(t)}var a=/*#__PURE__*/function(){function t(t,n,r){var i,e;this.name=t,this.definition=n,this.bindings=null!=(i=n.bindings)?i:{},this.wheres=null!=(e=n.wheres)?e:{},this.config=r}var n=t.prototype;return n.matchesUrl=function(t){if(!this.definition.methods.includes("GET"))return!1;var n=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}?]*\?}/g,"([^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+n+"$").test(t.replace(/\/+$/,"").split("?").shift())},n.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,function(r,i){var e,u;if([null,void 0].includes(t[i])&&n.parameterSegments.find(function(t){return t.name===i}).required)throw new Error("Ziggy error: '"+i+"' parameter is required for route '"+n.name+"'.");return n.parameterSegments[n.parameterSegments.length-1].name===i&&".*"===n.wheres[i]?null!=(u=t[i])?u:"":encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template},i(t,[{key:"template",get:function(){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(/\/+$/,"")}},{key:"parameterSegments",get:function(){var t,n;return null!=(t=null==(n=this.template.match(/{[^}?]+\??}/g))?void 0:n.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),l=/*#__PURE__*/function(r){var u,f;function c(t,n,i,u){var o;if(void 0===i&&(i=!0),(o=r.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=e({},o.t,{absolute:i}),t){if(!o.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");o.i=new a(t,o.t.routes[t],o.t),o.u=o.o(n)}return o}f=r,(u=c).prototype=Object.create(f.prototype),u.prototype.constructor=u,o(u,f);var s=c.prototype;return s.toString=function(){var n=this,r=Object.keys(this.u).filter(function(t){return!n.i.parameterSegments.some(function(n){return n.name===t})}).filter(function(t){return"_query"!==t}).reduce(function(t,r){var i;return e({},t,((i={})[r]=n.u[r],i))},{});return this.i.compile(this.u)+t(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,n){return"boolean"==typeof t?Number(t):n(t)}})},s.current=function(t,n){var r=this,i=this.t.absolute?this.l().host+this.l().pathname:this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),e=Object.entries(this.t.routes).find(function(n){return new a(t,n[1],r.t).matchesUrl(i)})||[void 0,void 0],u=e[0],o=e[1];if(!t)return u;var f=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(u);if([null,void 0].includes(n)||!f)return f;var c=new a(u,o,this.t);n=this.o(n,c);var s=this.h(o);return!(!Object.values(n).every(function(t){return!t})||Object.values(s).length)||Object.entries(n).every(function(t){return s[t[0]]==t[1]})},s.l=function(){var t,n,r,i,e,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,s=o.search;return{host:null!=(t=null==(n=this.t.location)?void 0:n.host)?t:void 0===f?"":f,pathname:null!=(r=null==(i=this.t.location)?void 0:i.pathname)?r:void 0===c?"":c,search:null!=(e=null==(u=this.t.location)?void 0:u.search)?e:void 0===s?"":s}},s.has=function(t){return Object.keys(this.t.routes).includes(t)},s.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),t=["string","number"].includes(typeof t)?[t]:t;var i=n.parameterSegments.filter(function(t){return!r.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,n,r){var u,o;return e({},t,i[r]?((u={})[i[r].name]=n,u):((o={})[n]="",o))},{});else if(1===i.length&&!t[i[0].name]&&(t.hasOwnProperty(Object.values(n.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[i[0].name]=t,t=u}return e({},this.v(n),this.g(t,n))},s.v=function(t){var n=this;return t.parameterSegments.filter(function(t){return n.t.defaults[t.name]}).reduce(function(t,r,i){var u,o=r.name;return e({},t,((u={})[o]=n.t.defaults[o],u))},{})},s.g=function(t,n){var r=n.bindings,i=n.parameterSegments;return Object.entries(t).reduce(function(t,n){var u,o,f=n[0],c=n[1];if(!c||"object"!=typeof c||Array.isArray(c)||!i.some(function(t){return t.name===f}))return e({},t,((o={})[f]=c,o));if(!c.hasOwnProperty(r[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+r[f]+"'.");r[f]="id"}return e({},t,((u={})[f]=c[r[f]],u))},{})},s.h=function(t){var r,i=this.l().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,""),u=function(t,n,r){void 0===n&&(n="");var i=[t,n].map(function(t){return t.split(r)}),u=i[0];return i[1].reduce(function(t,n,r){var i;return/{[^}?]+\??}/.test(n)&&u[r]?e({},t,((i={})[n.replace(/.*{|\??}.*/g,"")]=u[r].replace(n.match(/^[^{]*/g),"").replace(n.match(/[^}]*$/g),""),i)):t},{})};return e({},u(this.l().host,t.domain,"."),u(i,t.uri,"/"),n(null==(r=this.l().search)?void 0:r.replace(/^\?/,"")))},s.valueOf=function(){return this.toString()},s.check=function(t){return this.has(t)},i(c,[{key:"params",get:function(){return this.h(this.t.routes[this.current()])}}]),c}(/*#__PURE__*/s(String)),h={install:function(t,n){return t.mixin({methods:{route:function(t,r,i,e){return void 0===e&&(e=n),function(t,n,r,i){var e=new l(t,n,r,i);return t?e.toString():e}(t,r,i,e)}}})}};export{h as ZiggyVue};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziggy-js",
3
- "version": "1.3.6",
3
+ "version": "1.4.3",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",
@@ -52,13 +52,12 @@
52
52
  "regex": "^_(?!query)"
53
53
  },
54
54
  "dependencies": {
55
- "qs": "^6.8.0"
55
+ "qs": "~6.9.7"
56
56
  },
57
57
  "devDependencies": {
58
- "@babel/preset-env": "^7.11.0",
59
58
  "babel-preset-power-assert": "^3.0.0",
60
59
  "jest": "^27.0.6",
61
- "microbundle": "^0.12.3",
60
+ "microbundle": "^0.14.2",
62
61
  "power-assert": "^1.6.1"
63
62
  }
64
63
  }
package/src/js/Route.js CHANGED
@@ -11,6 +11,7 @@ export default class Route {
11
11
  this.name = name;
12
12
  this.definition = definition;
13
13
  this.bindings = definition.bindings ?? {};
14
+ this.wheres = definition.wheres ?? {};
14
15
  this.config = config;
15
16
  }
16
17
 
@@ -60,6 +61,10 @@ export default class Route {
60
61
  // by replacing its parameter segments with matchers for parameter values
61
62
  const pattern = this.template
62
63
  .replace(/\/{[^}?]*\?}/g, '(\/[^/?]+)?')
64
+ // TODO: the above line with the leading slash is necessary to pick up completely optional *segments*,
65
+ // like in `/pages/{subPage?}`, so that those are handled first before the more permissive patterns
66
+ // below, but there's probably a way to do this in one shot
67
+ .replace(/{[^}?]*\?}/g, '([^/?]+)?')
63
68
  .replace(/{[^}]+}/g, '[^/?]+')
64
69
  .replace(/^\w+:\/\//, '');
65
70
 
@@ -81,6 +86,10 @@ export default class Route {
81
86
  throw new Error(`Ziggy error: '${segment}' parameter is required for route '${this.name}'.`)
82
87
  }
83
88
 
89
+ if (this.parameterSegments[this.parameterSegments.length - 1].name === segment && this.wheres[segment] === '.*') {
90
+ return params[segment] ?? '';
91
+ }
92
+
84
93
  return encodeURIComponent(params[segment] ?? '');
85
94
  }).replace(/\/+$/, '');
86
95
  }
package/src/js/Router.js CHANGED
@@ -14,7 +14,7 @@ export default class Router extends String {
14
14
  constructor(name, params, absolute = true, config) {
15
15
  super();
16
16
 
17
- this._config = config ?? Ziggy ?? globalThis?.Ziggy;
17
+ this._config = config ?? (typeof Ziggy !== 'undefined' ? Ziggy : globalThis?.Ziggy);
18
18
  this._config = { ...this._config, absolute };
19
19
 
20
20
  if (name) {
@@ -83,7 +83,7 @@ export default class Router extends String {
83
83
 
84
84
  // Test the passed name against the current route, matching some
85
85
  // basic wildcards, e.g. passing `events.*` matches `events.show`
86
- const match = new RegExp(`^${name.replace('.', '\\.').replace('*', '.*')}$`).test(current);
86
+ const match = new RegExp(`^${name.replace(/\./g, '\\.').replace(/\*/g, '.*')}$`).test(current);
87
87
 
88
88
  if ([null, undefined].includes(params) || !match) return match;
89
89
 
@@ -246,15 +246,20 @@ export default class Router extends String {
246
246
 
247
247
  // Given part of a valid 'hydrated' URL containing all its parameter values,
248
248
  // a route template, and a delimiter, extract the parameters as an object
249
- // E.g. dehydrate('events/{event}/{venue}', 'events/2/chicago', '/'); // { event: 2, venue: 'chicago' }
249
+ // E.g. dehydrate('events/2/chicago', 'events/{event}/{venue}', '/'); // { event: 2, venue: 'chicago' }
250
250
  const dehydrate = (hydrated, template = '', delimiter) => {
251
251
  const [values, segments] = [hydrated, template].map(s => s.split(delimiter));
252
252
 
253
253
  return segments.reduce((result, current, i) => {
254
254
  // Only include template segments that are route parameters
255
255
  // AND have a value present in the passed hydrated string
256
- return /^{[^}?]+\??}$/.test(current) && values[i]
257
- ? { ...result, [current.replace(/^{|\??}$/g, '')]: values[i] }
256
+ return /{[^}?]+\??}/.test(current) && values[i]
257
+ ? {
258
+ ...result,
259
+ [current.replace(/.*{|\??}.*/g, '')]: values[i]
260
+ .replace(current.match(/^[^{]*/g), '')
261
+ .replace(current.match(/[^}]*$/g), ''),
262
+ }
258
263
  : result;
259
264
  }, {});
260
265
  }