ziggy-js 2.6.1 → 2.6.2

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Ziggy – Use your Laravel routes in JavaScript
4
4
 
5
- [![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?branch=main&style=flat)](https://github.com/tighten/ziggy/actions?query=workflow:Tests+branch:main)
5
+ [![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?branch=main&style=flat)](https://github.com/tighten/ziggy/actions?query=workflow:Test+branch:2.x)
6
6
  [![Latest Version on Packagist](https://img.shields.io/packagist/v/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
7
7
  [![Downloads on Packagist](https://img.shields.io/packagist/dt/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
8
8
  [![Latest Version on NPM](https://img.shields.io/npm/v/ziggy-js.svg?style=flat)](https://npmjs.com/package/ziggy-js)
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{parse as r,stringify as t}from"qs-esm";function n(r,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,c(e.key),e)}}function e(r,t,e){return t&&n(r.prototype,t),e&&n(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function i(){return i=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)({}).hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},i.apply(null,arguments)}function o(r){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},o(r)}function u(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(u=function(){return!!r})()}function f(r,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},f(r,t)}function c(r){var t=function(r){if("object"!=typeof r||!r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var n=t.call(r,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}(r);return"symbol"==typeof t?t:t+""}function a(r){var t="function"==typeof Map?new Map:void 0;return a=function(r){if(null===r||!function(r){try{return-1!==Function.toString.call(r).indexOf("[native code]")}catch(t){return"function"==typeof r}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,n)}function n(){return function(r,t,n){if(u())return Reflect.construct.apply(null,arguments);var e=[null];e.push.apply(e,t);var i=new(r.bind.apply(r,e));return n&&f(i,n.prototype),i}(r,arguments,o(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,r)},a(r)}var s=/*#__PURE__*/function(){function t(r,t,n){var e,i;this.name=r,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},this.wheres=null!=(i=t.wheres)?i:{},this.config=n}var n=t.prototype;return n.matchesUrl=function(t){var n,e=this;if(!this.definition.methods.includes("GET"))return!1;var i=this.template.replace(/[.*+$()[\]]/g,"\\$&").replace(/(\/?){([^}?]*)(\??)}/g,function(r,t,n,i){var o,u="(?<"+n+">"+((null==(o=e.wheres[n])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+t+u+")?":""+t+u}).replace(/^\w+:\/\//,""),o=t.replace(/^\w+:\/\//,"").split("?"),u=o[0],f=o[1],c=null!=(n=new RegExp("^"+i+"/?$").exec(u))?n:new RegExp("^"+i+"/?$").exec(decodeURI(u));if(c){for(var a in c.groups)c.groups[a]="string"==typeof c.groups[a]?decodeURIComponent(c.groups[a]):c.groups[a];return{params:c.groups,query:r(f)}}return!1},n.compile=function(r){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var o,u;if(!i&&[null,void 0].includes(r[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");if(t.wheres[e]&&!new RegExp("^"+(i?"("+t.wheres[e]+")?":t.wheres[e])+"$").test(null!=(u=r[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter '"+r[e]+"' does not match required format '"+t.wheres[e]+"' for route '"+t.name+"'.");return encodeURI(null!=(o=r[e])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.config.absolute?/(\.[^/]+?)(\/\/)/:/(^)(\/\/)/,"$1/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var r=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===r?"/":r}},{key:"origin",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:""}},{key:"parameterSegments",get:function(){var r,t;return null!=(r=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(r){return{name:r.replace(/{|\??}/g,""),required:!/\?}$/.test(r)}}))?r:[]}}])}(),l=/*#__PURE__*/function(r){function n(t,n,e,o){var u;if(void 0===e&&(e=!0),(u=r.call(this)||this).t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,!u.t&&"undefined"!=typeof document&&document.getElementById("ziggy-routes-json")&&(globalThis.Ziggy=JSON.parse(document.getElementById("ziggy-routes-json").textContent),u.t=globalThis.Ziggy),u.t=i({},u.t,{absolute:e}),t){if(!u.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");u.i=new s(t,u.t.routes[t],u.t),u.o=u.u(n)}return u}var o,u;u=r,(o=n).prototype=Object.create(u.prototype),o.prototype.constructor=o,f(o,u);var c=n.prototype;return c.toString=function(){var r=this,n=Object.keys(this.o).filter(function(t){return!r.i.parameterSegments.some(function(r){return r.name===t})}).filter(function(r){return"_query"!==r}).reduce(function(t,n){var e;return i({},t,((e={})[n]=r.o[n],e))},{});return this.i.compile(this.o)+t(i({},n,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(r,t){return"boolean"==typeof r?Number(r):t(r)}})},c.l=function(r){var t=this;r?this.t.absolute&&r.startsWith("/")&&(r=this.h().host+r):r=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new s(e[0],e[1],t.t).matchesUrl(r)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.v=function(){var r=this.h(),t=r.pathname,n=r.search;return(this.t.absolute?r.host+t:t.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(r,t){var n=this.l(),e=n.name,o=n.params,u=n.query,f=n.route;if(!r)return e;var c=new RegExp("^"+r.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(t)||!c)return c;var a=new s(e,f,this.t);t=this.u(t,a);var l=i({},o,u);if(Object.values(t).every(function(r){return!r})&&!Object.values(l).some(function(r){return void 0!==r}))return!0;var h=function(r,t){return Object.entries(r).every(function(r){var n=r[0],e=r[1];return Array.isArray(e)&&Array.isArray(t[n])?e.every(function(r){return t[n].includes(r)||t[n].includes(decodeURIComponent(r))}):"object"==typeof e&&"object"==typeof t[n]&&null!==e&&null!==t[n]?h(e,t[n]):t[n]==e||t[n]==decodeURIComponent(e)})};return h(t,l)},c.h=function(){var r,t,n,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(r=null==(t=this.t.location)?void 0:t.host)?r:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(o=this.t.location)?void 0:o.search)?i:void 0===a?"":a}},c.has=function(r){return this.t.routes.hasOwnProperty(r)},c.u=function(r,t){var n=this;void 0===r&&(r={}),void 0===t&&(t=this.i),null!=r||(r={}),r=["string","number"].includes(typeof r)?[r]:r;var e=t.parameterSegments.filter(function(r){return!n.t.defaults[r.name]});if(Array.isArray(r))r=r.reduce(function(r,t,n){var o,u;return i({},r,e[n]?((o={})[e[n].name]=t,o):"object"==typeof t?t:((u={})[t]="",u))},{});else if(1===e.length&&!r[e[0].name]&&(r.hasOwnProperty(Object.values(t.bindings)[0])||r.hasOwnProperty("id"))){var o;(o={})[e[0].name]=r,r=o}return i({},this.p(t),this.m(r,t))},c.p=function(r){var t=this;return r.parameterSegments.filter(function(r){return t.t.defaults[r.name]}).reduce(function(r,n,e){var o,u=n.name;return i({},r,((o={})[u]=t.t.defaults[u],o))},{})},c.m=function(r,t){var n=t.bindings,e=t.parameterSegments;return Object.entries(r).reduce(function(r,t){var o,u,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(r){return r.name===f}))return i({},r,((u={})[f]=c,u));if(!c.hasOwnProperty(n[f])){if(!c.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return i({},r,((o={})[f]=c[n[f]],o))},{})},c.valueOf=function(){return this.toString()},e(n,[{key:"params",get:function(){var r=this.l();return i({},r.params,r.query)}},{key:"routeParams",get:function(){return this.l().params}},{key:"queryParams",get:function(){return this.l().query}}])}(/*#__PURE__*/a(String));function h(r,t,n,e){var i=new l(r,t,n,e);return r?i.toString():i}var v={install:function(r,t){var n=function(r,n,e,i){return void 0===i&&(i=t),h(r,n,e,i)};parseInt(r.version)>2?(r.config.globalProperties.route=n,r.provide("route",n)):r.mixin({methods:{route:n}})}};function d(r){if(!r&&!globalThis.Ziggy&&"undefined"==typeof Ziggy&&!document.getElementById("ziggy-routes-json"))throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return function(t,n,e,i){return void 0===i&&(i=r),h(t,n,e,i)}}export{v as ZiggyVue,h as route,d as useRoute};
1
+ import{parse as r,stringify as t}from"qs-esm";function n(r,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,c(e.key),e)}}function e(r,t,e){return t&&n(r.prototype,t),e&&n(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function i(){return i=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)({}).hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},i.apply(null,arguments)}function o(r){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},o(r)}function u(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(u=function(){return!!r})()}function f(r,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},f(r,t)}function c(r){var t=function(r){if("object"!=typeof r||!r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var n=t.call(r,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}(r);return"symbol"==typeof t?t:t+""}function a(r){var t="function"==typeof Map?new Map:void 0;return a=function(r){if(null===r||!function(r){try{return-1!==Function.toString.call(r).indexOf("[native code]")}catch(t){return"function"==typeof r}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,n)}function n(){return function(r,t,n){if(u())return Reflect.construct.apply(null,arguments);var e=[null];e.push.apply(e,t);var i=new(r.bind.apply(r,e));return n&&f(i,n.prototype),i}(r,arguments,o(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,r)},a(r)}var s=/*#__PURE__*/function(){function t(r,t,n){var e,i;this.name=r,this.definition=t,this.bindings=null!=(e=t.bindings)?e:{},this.wheres=null!=(i=t.wheres)?i:{},this.config=n}var n=t.prototype;return n.matchesUrl=function(t){var n,e=this;if(!this.definition.methods.includes("GET"))return!1;var i=this.template.replace(/[.*+$()[\]]/g,"\\$&").replace(/(\/?){([^}?]*)(\??)}/g,function(r,t,n,i){var o,u="(?<"+n+">"+((null==(o=e.wheres[n])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+t+u+")?":""+t+u}).replace(/^\w+:\/\//,""),o=t.replace(/^\w+:\/\//,"").split("?"),u=o[0],f=o[1],c=null!=(n=new RegExp("^"+i+"/?$").exec(u))?n:new RegExp("^"+i+"/?$").exec(decodeURI(u));if(c){for(var a in c.groups)c.groups[a]="string"==typeof c.groups[a]?decodeURIComponent(c.groups[a]):c.groups[a];return{params:c.groups,query:r(f)}}return!1},n.compile=function(r){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var o,u;if(!i&&[null,void 0].includes(r[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");if(t.wheres[e]&&!new RegExp("^"+(i?"("+t.wheres[e]+")?":t.wheres[e])+"$").test(null!=(u=r[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter '"+r[e]+"' does not match required format '"+t.wheres[e]+"' for route '"+t.name+"'.");return encodeURI(null!=(o=r[e])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.config.absolute?/(\.[^/]+?)(\/\/)/:/(^)(\/\/)/,"$1/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var r=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===r?"/":r}},{key:"origin",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:""}},{key:"parameterSegments",get:function(){var r,t;return null!=(r=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(r){return{name:r.replace(/{|\??}/g,""),required:!/\?}$/.test(r)}}))?r:[]}}])}(),l=/*#__PURE__*/function(r){function n(t,n,e,o){var u;if(void 0===e&&(e=!0),(u=r.call(this)||this).t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,!u.t&&"undefined"!=typeof document&&document.getElementById("ziggy-routes-json")&&(globalThis.Ziggy=JSON.parse(document.getElementById("ziggy-routes-json").textContent),u.t=globalThis.Ziggy),u.t=i({},u.t,{absolute:e}),t){if(!u.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");u.i=new s(t,u.t.routes[t],u.t),u.o=u.u(n)}return u}var o,u;u=r,(o=n).prototype=Object.create(u.prototype),o.prototype.constructor=o,f(o,u);var c=n.prototype;return c.toString=function(){var r=this,n=Object.keys(this.o).filter(function(t){return!r.i.parameterSegments.some(function(r){return r.name===t})}).filter(function(r){return"_query"!==r}).reduce(function(t,n){var e;return i({},t,((e={})[n]=r.o[n],e))},{});return this.i.compile(this.o)+t(i({},n,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(r,t){return"boolean"==typeof r?Number(r):t(r)}})},c.l=function(r){var t=this;r?this.t.absolute&&r.startsWith("/")&&(r=this.v().host+r):r=this.h();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new s(e[0],e[1],t.t).matchesUrl(r)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.h=function(){var r=this.v(),t=r.pathname,n=r.search;return(this.t.absolute?r.host+t:t.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(r,t){var n=this.l(),e=n.name,o=n.params,u=n.query,f=n.route;if(!r)return e;var c=new RegExp("^"+r.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(t)||!c)return c;var a=new s(e,f,this.t);t=this.u(t,a);var l=i({},o,u);if(Object.values(t).every(function(r){return!r})&&!Object.values(l).some(function(r){return void 0!==r}))return!0;var v=function(r,t){return Object.entries(r).every(function(r){var n=r[0],e=r[1];return Array.isArray(e)&&Array.isArray(t[n])?e.every(function(r){return t[n].includes(r)||t[n].includes(decodeURIComponent(r))}):"object"==typeof e&&"object"==typeof t[n]&&null!==e&&null!==t[n]?v(e,t[n]):t[n]==e||t[n]==decodeURIComponent(e)})};return v(t,l)},c.v=function(){var r,t,n,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,c=u.pathname,a=u.search;return{host:null!=(r=null==(t=this.t.location)?void 0:t.host)?r:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===c?"":c,search:null!=(i=null==(o=this.t.location)?void 0:o.search)?i:void 0===a?"":a}},c.has=function(r){return this.t.routes.hasOwnProperty(r)},c.u=function(r,t){var n=this;void 0===r&&(r={}),void 0===t&&(t=this.i),null!=r||(r={}),r=["string","number"].includes(typeof r)?[r]:r;var e=t.parameterSegments.filter(function(r){return!n.t.defaults[r.name]});if(Array.isArray(r))r=r.reduce(function(r,t,n){var o,u;return i({},r,e[n]?((o={})[e[n].name]=t,o):"object"==typeof t?t:((u={})[t]="",u))},{});else if(1===e.length&&!r.hasOwnProperty(e[0].name)&&(r.hasOwnProperty(Object.values(t.bindings)[0])||r.hasOwnProperty("id"))){var o;(o={})[e[0].name]=r,r=o}return i({},this.p(t),this.m(r,t))},c.p=function(r){var t=this;return r.parameterSegments.filter(function(r){return t.t.defaults[r.name]}).reduce(function(r,n,e){var o,u=n.name;return i({},r,((o={})[u]=t.t.defaults[u],o))},{})},c.m=function(r,t){var n=t.bindings,e=t.parameterSegments;return Object.entries(r).reduce(function(r,t){var o,u,f=t[0],c=t[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(r){return r.name===f}))return i({},r,((u={})[f]=c,u));var a=c.hasOwnProperty(n[f])?n[f]:c.hasOwnProperty("id")?"id":void 0;if(void 0===a)throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");return i({},r,((o={})[f]=c[a],o))},{})},c.valueOf=function(){return this.toString()},e(n,[{key:"params",get:function(){var r=this.l();return i({},r.params,r.query)}},{key:"routeParams",get:function(){return this.l().params}},{key:"queryParams",get:function(){return this.l().query}}])}(/*#__PURE__*/a(String));function v(r,t,n,e){var i=new l(r,t,n,e);return r?i.toString():i}var h={install:function(r,t){var n=function(r,n,e,i){return void 0===i&&(i=t),v(r,n,e,i)};parseInt(r.version)>2?(r.config.globalProperties.route=n,r.provide("route",n)):r.mixin({methods:{route:n}})}};function d(r){if(!r&&!globalThis.Ziggy&&"undefined"==typeof Ziggy&&!document.getElementById("ziggy-routes-json"))throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return function(t,n,e,i){return void 0===i&&(i=r),v(t,n,e,i)}}export{h as ZiggyVue,v as route,d as useRoute};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{parse as t,stringify as e}from"qs-esm";function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},r.apply(null,arguments)}class n{constructor(t,e,r){var n,i;this.name=t,this.definition=e,this.bindings=null!=(n=e.bindings)?n:{},this.wheres=null!=(i=e.wheres)?i:{},this.config=r}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){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:""}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(e){var r;if(!this.definition.methods.includes("GET"))return!1;const n=this.template.replace(/[.*+$()[\]]/g,"\\$&").replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var i;const s=`(?<${r}>${(null==(i=this.wheres[r])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${s})?`:`${e}${s}`}).replace(/^\w+:\/\//,""),[i,s]=e.replace(/^\w+:\/\//,"").split("?"),o=null!=(r=new RegExp(`^${n}/?$`).exec(i))?r:new RegExp(`^${n}/?$`).exec(decodeURI(i));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:t(s)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var i,s;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(s=t[r])?s:""))throw new Error(`Ziggy error: '${r}' parameter '${t[r]}' does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(i=t[r])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.config.absolute?/(\.[^/]+?)(\/\/)/:/(^)(\/\/)/,"$1/").replace(/\/+$/,""):this.template}}class i extends String{constructor(t,e,i=!0,s){if(super(),this.t=null!=s?s:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,!this.t&&"undefined"!=typeof document&&document.getElementById("ziggy-routes-json")&&(globalThis.Ziggy=JSON.parse(document.getElementById("ziggy-routes-json").textContent),this.t=globalThis.Ziggy),this.t=r({},this.t,{absolute:i}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new n(t,this.t.routes[t],this.t),this.o=this.u(e)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>r({},t,{[e]:this.o[e]}),{});return this.i.compile(this.o)+e(r({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}h(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.m();let e={};const[i,s]=Object.entries(this.t.routes).find(([r,i])=>e=new n(r,i,this.t).matchesUrl(t))||[void 0,void 0];return r({name:i},e,{route:s})}m(){const{host:t,pathname:e,search:r}=this.l();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(t,e){const{name:i,params:s,query:o,route:u}=this.h();if(!t)return i;const h=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(i);if([null,void 0].includes(e)||!h)return h;const a=new n(i,u,this.t);e=this.u(e,a);const l=r({},s,o);if(Object.values(e).every(t=>!t)&&!Object.values(l).some(t=>void 0!==t))return!0;const c=(t,e)=>Object.entries(t).every(([t,r])=>Array.isArray(r)&&Array.isArray(e[t])?r.every(r=>e[t].includes(r)||e[t].includes(decodeURIComponent(r))):"object"==typeof r&&"object"==typeof e[t]&&null!==r&&null!==e[t]?c(r,e[t]):e[t]==r||e[t]==decodeURIComponent(r));return c(e,l)}l(){var t,e,r,n,i,s;const{host:o="",pathname:u="",search:h=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:o,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:u,search:null!=(i=null==(s=this.t.location)?void 0:s.search)?i:h}}get params(){const{params:t,query:e}=this.h();return r({},t,e)}get routeParams(){return this.h().params}get queryParams(){return this.h().query}has(t){return this.t.routes.hasOwnProperty(t)}u(t={},e=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,i)=>r({},t,n[i]?{[n[i].name]:e}:"object"==typeof e?e:{[e]:""}),{}):1!==n.length||t[n[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[n[0].name]:t}),r({},this.p(e),this.$(t,e))}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},n)=>r({},t,{[e]:this.t.defaults[e]}),{})}$(t,{bindings:e,parameterSegments:n}){return Object.entries(t).reduce((t,[i,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||!n.some(({name:t})=>t===i))return r({},t,{[i]:s});if(!s.hasOwnProperty(e[i])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${e[i]}'.`);e[i]="id"}return r({},t,{[i]:s[e[i]]})},{})}valueOf(){return this.toString()}}function s(t,e,r,n){const s=new i(t,e,r,n);return t?s.toString():s}const o={install(t,e){const r=(t,r,n,i=e)=>s(t,r,n,i);parseInt(t.version)>2?(t.config.globalProperties.route=r,t.provide("route",r)):t.mixin({methods:{route:r}})}};function u(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy&&!document.getElementById("ziggy-routes-json"))throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return(e,r,n,i=t)=>s(e,r,n,i)}export{o as ZiggyVue,s as route,u as useRoute};
1
+ import{parse as t,stringify as e}from"qs-esm";function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},r.apply(null,arguments)}class n{constructor(t,e,r){var n,i;this.name=t,this.definition=e,this.bindings=null!=(n=e.bindings)?n:{},this.wheres=null!=(i=e.wheres)?i:{},this.config=r}get template(){const t=`${this.origin}/${this.definition.uri}`.replace(/\/+$/,"");return""===t?"/":t}get origin(){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:""}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(e){var r;if(!this.definition.methods.includes("GET"))return!1;const n=this.template.replace(/[.*+$()[\]]/g,"\\$&").replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var i;const s=`(?<${r}>${(null==(i=this.wheres[r])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${s})?`:`${e}${s}`}).replace(/^\w+:\/\//,""),[i,s]=e.replace(/^\w+:\/\//,"").split("?"),o=null!=(r=new RegExp(`^${n}/?$`).exec(i))?r:new RegExp(`^${n}/?$`).exec(decodeURI(i));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:t(s)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var i,s;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(s=t[r])?s:""))throw new Error(`Ziggy error: '${r}' parameter '${t[r]}' does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(i=t[r])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.config.absolute?/(\.[^/]+?)(\/\/)/:/(^)(\/\/)/,"$1/").replace(/\/+$/,""):this.template}}class i extends String{constructor(t,e,i=!0,s){if(super(),this.t=null!=s?s:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,!this.t&&"undefined"!=typeof document&&document.getElementById("ziggy-routes-json")&&(globalThis.Ziggy=JSON.parse(document.getElementById("ziggy-routes-json").textContent),this.t=globalThis.Ziggy),this.t=r({},this.t,{absolute:i}),t){if(!this.t.routes[t])throw new Error(`Ziggy error: route '${t}' is not in the route list.`);this.i=new n(t,this.t.routes[t],this.t),this.o=this.u(e)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>r({},t,{[e]:this.o[e]}),{});return this.i.compile(this.o)+e(r({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}h(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.m();let e={};const[i,s]=Object.entries(this.t.routes).find(([r,i])=>e=new n(r,i,this.t).matchesUrl(t))||[void 0,void 0];return r({name:i},e,{route:s})}m(){const{host:t,pathname:e,search:r}=this.l();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(t,e){const{name:i,params:s,query:o,route:u}=this.h();if(!t)return i;const h=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(i);if([null,void 0].includes(e)||!h)return h;const a=new n(i,u,this.t);e=this.u(e,a);const l=r({},s,o);if(Object.values(e).every(t=>!t)&&!Object.values(l).some(t=>void 0!==t))return!0;const c=(t,e)=>Object.entries(t).every(([t,r])=>Array.isArray(r)&&Array.isArray(e[t])?r.every(r=>e[t].includes(r)||e[t].includes(decodeURIComponent(r))):"object"==typeof r&&"object"==typeof e[t]&&null!==r&&null!==e[t]?c(r,e[t]):e[t]==r||e[t]==decodeURIComponent(r));return c(e,l)}l(){var t,e,r,n,i,s;const{host:o="",pathname:u="",search:h=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:o,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:u,search:null!=(i=null==(s=this.t.location)?void 0:s.search)?i:h}}get params(){const{params:t,query:e}=this.h();return r({},t,e)}get routeParams(){return this.h().params}get queryParams(){return this.h().query}has(t){return this.t.routes.hasOwnProperty(t)}u(t={},e=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const n=e.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,e,i)=>r({},t,n[i]?{[n[i].name]:e}:"object"==typeof e?e:{[e]:""}),{}):1!==n.length||t.hasOwnProperty(n[0].name)||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[n[0].name]:t}),r({},this.p(e),this.$(t,e))}p(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},n)=>r({},t,{[e]:this.t.defaults[e]}),{})}$(t,{bindings:e,parameterSegments:n}){return Object.entries(t).reduce((t,[i,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||!n.some(({name:t})=>t===i))return r({},t,{[i]:s});const o=s.hasOwnProperty(e[i])?e[i]:s.hasOwnProperty("id")?"id":void 0;if(void 0===o)throw new Error(`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${e[i]}'.`);return r({},t,{[i]:s[o]})},{})}valueOf(){return this.toString()}}function s(t,e,r,n){const s=new i(t,e,r,n);return t?s.toString():s}const o={install(t,e){const r=(t,r,n,i=e)=>s(t,r,n,i);parseInt(t.version)>2?(t.config.globalProperties.route=r,t.provide("route",r)):t.mixin({methods:{route:r}})}};function u(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy&&!document.getElementById("ziggy-routes-json"))throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into the useRoute hook.");return(e,r,n,i=t)=>s(e,r,n,i)}export{o as ZiggyVue,s as route,u as useRoute};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziggy-js",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",