ziggy-js 1.4.2 → 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
package/dist/index.es.js CHANGED
@@ -1 +1 @@
1
- import{stringify as t,parse as e}from"qs";function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}class i{constructor(t,e,r){var i;this.name=t,this.definition=e,this.bindings=null!=(i=e.bindings)?i:{},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,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,r)=>{var i;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!=(i=t[r])?i:"")}).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=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 i(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)=>r({},t,{[e]:this.h[e]}),{});return this.i.compile(this.h)+t(r({},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 r=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 i(t,s,this.t).matchesUrl(r))||[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 i(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,r,i,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!=(r=null==(i=this.t.location)?void 0:i.pathname)?r: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 i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,s)=>r({},t,i[s]?{[i[s].name]:e}:{[e]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),r({},this.g(e),this.m(t,e))}g(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>r({},t,{[e]:this.t.defaults[e]}),{})}m(t,{bindings:e,parameterSegments:i}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!i.some(({name:t})=>t===s))return r({},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 r({},t,{[s]:n[e[s]]})},{})}l(t){var i;let s=this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",i)=>{const[s,n]=[t,e].map(t=>t.split(i));return n.reduce((t,e,i)=>/{[^}?]+\??}/.test(e)&&s[i]?r({},t,{[e.replace(/.*{|\??}.*/g,"")]:s[i].replace(e.match(/^[^{]*/g),"").replace(e.match(/[^}]*$/g),"")}):t,{})};return r({},n(this.u().host,t.domain,"."),n(s,t.uri,"/"),e(null==(i=this.u().search)?void 0:i.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}function n(t,e,r,i){const n=new s(t,e,r,i);return t?n.toString():n}export{n as default};
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||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),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}).apply(this,arguments)}function i(n){return(i=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 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}).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)})(n)}var s=function(){function n(n,t,r){var e;this.name=n,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},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;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 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=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.h().host+this.h().pathname:this.h().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.l(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.h=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.l=function(t){var r,i=this.h().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.h().host,t.domain,"."),u(i,t.uri,"/"),n.parse(null==(r=this.h().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.l(this.t.routes[this.current()])}}]),f}(c(String));return function(n,t,r,e){var i=new a(n,t,r,e);return n?i.toString():i}});
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 n,parse as t}from"qs";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 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 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(/{[^}]+}/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.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),h=function(r){var u,f;function c(n,t,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}),n){if(!o.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");o.i=new a(n,o.t.routes[n],o.t),o.u=o.o(t)}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 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(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)}})},s.current=function(n,t){var r=this,i=this.t.absolute?this.h().host+this.h().pathname:this.h().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(/\./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.l(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]})},s.h=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.host)?n: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(n){return Object.keys(this.t.routes).includes(n)},s.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))},s.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))},{})},s.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))},{})},s.l=function(n){var r,i=this.h().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.h().host,n.domain,"."),u(i,n.uri,"/"),t(null==(r=this.h().search)?void 0:r.replace(/^\?/,"")))},s.valueOf=function(){return this.toString()},s.check=function(n){return this.has(n)},i(c,[{key:"params",get:function(){return this.l(this.t.routes[this.current()])}}]),c}(s(String));function l(n,t,r,i){var e=new h(n,t,r,i);return n?e.toString():e}export{l as default};
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 e}from"qs";function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}class i{constructor(t,e,r){var i;this.name=t,this.definition=e,this.bindings=null!=(i=e.bindings)?i:{},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,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,r)=>{var i;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!=(i=t[r])?i:"")}).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=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 i(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)=>r({},t,{[e]:this.h[e]}),{});return this.i.compile(this.h)+t(r({},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 r=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 i(t,s,this.t).matchesUrl(r))||[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 i(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,r,i,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!=(r=null==(i=this.t.location)?void 0:i.pathname)?r: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 i=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,s)=>r({},t,i[s]?{[i[s].name]:e}:{[e]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),r({},this.g(e),this.m(t,e))}g(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>r({},t,{[e]:this.t.defaults[e]}),{})}m(t,{bindings:e,parameterSegments:i}){return Object.entries(t).reduce((t,[s,n])=>{if(!n||"object"!=typeof n||Array.isArray(n)||!i.some(({name:t})=>t===s))return r({},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 r({},t,{[s]:n[e[s]]})},{})}l(t){var i;let s=this.u().pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,e="",i)=>{const[s,n]=[t,e].map(t=>t.split(i));return n.reduce((t,e,i)=>/{[^}?]+\??}/.test(e)&&s[i]?r({},t,{[e.replace(/.*{|\??}.*/g,"")]:s[i].replace(e.match(/^[^{]*/g),"").replace(e.match(/[^}]*$/g),"")}):t,{})};return r({},n(this.u().host,t.domain,"."),n(s,t.uri,"/"),e(null==(i=this.u().search)?void 0:i.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}const n={install:(t,e)=>t.mixin({methods:{route:(t,r,i,n=e)=>function(t,e,r,i){const n=new s(t,e,r,i);return t?n.toString():n}(t,r,i,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||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),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}).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 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}).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 e;this.name=n,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},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;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 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}(),h=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.h().host+this.h().pathname:this.h().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.l(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.h=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.l=function(n){var r,e=this.h().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.h().host,n.domain,"."),u(e,n.uri,"/"),t.parse(null==(r=this.h().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.l(this.t.routes[this.current()])}}]),f}(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 h(n,t,r,e);return n?i.toString():i}(n,r,e,i)}}})}}});
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 n,parse as t}from"qs";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 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 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(/{[^}]+}/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.map(function(n){return{name:n.replace(/{|\??}/g,""),required:!/\?}$/.test(n)}}))?n:[]}}]),n}(),h=function(r){var u,f;function c(n,t,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}),n){if(!o.t.routes[n])throw new Error("Ziggy error: route '"+n+"' is not in the route list.");o.i=new a(n,o.t.routes[n],o.t),o.u=o.o(t)}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 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(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)}})},s.current=function(n,t){var r=this,i=this.t.absolute?this.h().host+this.h().pathname:this.h().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(/\./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.l(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]})},s.h=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.host)?n: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(n){return Object.keys(this.t.routes).includes(n)},s.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))},s.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))},{})},s.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))},{})},s.l=function(n){var r,i=this.h().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.h().host,n.domain,"."),u(i,n.uri,"/"),t(null==(r=this.h().search)?void 0:r.replace(/^\?/,"")))},s.valueOf=function(){return this.toString()},s.check=function(n){return this.has(n)},i(c,[{key:"params",get:function(){return this.l(this.t.routes[this.current()])}}]),c}(s(String)),l={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)}}})}};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.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",
@@ -52,12 +52,12 @@
52
52
  "regex": "^_(?!query)"
53
53
  },
54
54
  "dependencies": {
55
- "qs": "^6.10.1"
55
+ "qs": "~6.9.7"
56
56
  },
57
57
  "devDependencies": {
58
58
  "babel-preset-power-assert": "^3.0.0",
59
59
  "jest": "^27.0.6",
60
- "microbundle": "^0.13.3",
60
+ "microbundle": "^0.14.2",
61
61
  "power-assert": "^1.6.1"
62
62
  }
63
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
 
@@ -85,6 +86,10 @@ export default class Route {
85
86
  throw new Error(`Ziggy error: '${segment}' parameter is required for route '${this.name}'.`)
86
87
  }
87
88
 
89
+ if (this.parameterSegments[this.parameterSegments.length - 1].name === segment && this.wheres[segment] === '.*') {
90
+ return params[segment] ?? '';
91
+ }
92
+
88
93
  return encodeURIComponent(params[segment] ?? '');
89
94
  }).replace(/\/+$/, '');
90
95
  }