ziggy-js 2.0.0-beta.1 → 2.0.0-beta.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
@@ -430,7 +430,7 @@ globalThis.Ziggy = Ziggy;
430
430
 
431
431
  Ziggy's `route()` function is available as an NPM package, for use in JavaScript projects managed separately from their Laravel backend (i.e. without Composer or a `vendor` directory). You can install the NPM package with `npm install ziggy-js`.
432
432
 
433
- To make your routes available on the frontend for this function to use, you can either run `php artisan ziggy:generate` and add the generated config file to your frontend project, or you can return Ziggy's config as JSON from an endpoint in your Laravel API (see [Retrieving Ziggy's config from an API endpoint](#retrieving-ziggys-routes-from-an-api-endpoint) below for an example of how to set this up).
433
+ To make your routes available on the frontend for this function to use, you can either run `php artisan ziggy:generate` and add the generated config file to your frontend project, or you can return Ziggy's config as JSON from an endpoint in your Laravel API (see [Retrieving Ziggy's config from an API endpoint](#retrieving-ziggys-config-from-an-api-endpoint) below for an example of how to set this up).
434
434
 
435
435
  ## Filtering Routes
436
436
 
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{parse as t,stringify as r}from"qs";function n(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,r){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(e.key))?i:String(i),e)}var i}function e(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},i.apply(this,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function o(t,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},o(t,r)}function f(t,r,n){return f=function(){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}}()?Reflect.construct.bind():function(t,r,n){var e=[null];e.push.apply(e,r);var i=new(Function.bind.apply(t,e));return n&&o(i,n.prototype),i},f.apply(null,arguments)}function c(t){var r="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(r){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return f(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,t)},c(t)}var a=/*#__PURE__*/function(){function r(t,r,n){var e,i;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.wheres=null!=(i=r.wheres)?i:{},this.config=n}var n=r.prototype;return n.matchesUrl=function(r){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,r,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+r+o+")?":""+r+o}).replace(/^\w+:\/\//,""),i=r.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(decodeURI(u));if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:t(o)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(i?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(r,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{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 t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),r}(),s=/*#__PURE__*/function(t){var n,u;function f(r,n,e,u){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=u?u:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=i({},o.t,{absolute:e}),r){if(!o.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");o.i=new a(r,o.t.routes[r],o.t),o.u=o.o(n)}return o}u=t,(n=f).prototype=Object.create(u.prototype),n.prototype.constructor=n,o(n,u);var c=f.prototype;return c.toString=function(){var t=this,n=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var e;return i({},r,((e={})[n]=t.u[n],e))},{});return this.i.compile(this.u)+r(i({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},c.l=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new a(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return i({name:e[0]},n,{route:e[1]})},c.v=function(){var t=this.h(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(t,r){var n=this.l(),e=n.name,u=n.params,o=n.query,f=n.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(r)||!c)return c;var s=new a(e,f,this.t);r=this.o(r,s);var l=i({},u,o);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,r,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t: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==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var u,o;return i({},t,e[n]?((u={})[e[n].name]=r,u):"object"==typeof r?r:((o={})[r]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var u;(u={})[e[0].name]=t,t=u}return i({},this.p(r),this.m(t,r))},c.p=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,e){var u,o=n.name;return i({},t,((u={})[o]=r.t.defaults[o],u))},{})},c.m=function(t,r){var n=r.bindings,e=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var u,o,f=r[0],c=r[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return i({},t,((o={})[f]=c,o));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({},t,((u={})[f]=c[n[f]],u))},{})},c.valueOf=function(){return this.toString()},e(f,[{key:"params",get:function(){var t=this.l();return i({},t.params,t.query)}}]),f}(/*#__PURE__*/c(String));function l(t,r,n,e){var i=new s(t,r,n,e);return t?i.toString():i}var h={install:function(t,r){var n=function(t,n,e,i){return void 0===i&&(i=r),l(t,n,e,i)};t.config.globalProperties.route=n,parseInt(t.version)>2&&t.provide("route",n)}};function v(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)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(r,n,e,i){return void 0===i&&(i=t),l(r,n,e,i)}}export{h as ZiggyVue,l as route,v as useRoute};
1
+ import{parse as t,stringify as r}from"qs";function n(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof r?r:String(r)}function e(t,r){for(var e=0;e<r.length;e++){var i=r[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function i(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function u(){return u=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},u.apply(this,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function f(t,r){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},f(t,r)}function c(t,r,n){return c=function(){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}}()?Reflect.construct.bind():function(t,r,n){var e=[null];e.push.apply(e,r);var i=new(Function.bind.apply(t,e));return n&&f(i,n.prototype),i},c.apply(null,arguments)}function a(t){var r="function"==typeof Map?new Map:void 0;return a=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(r){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return c(t,arguments,o(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,t)},a(t)}var s=/*#__PURE__*/function(){function r(t,r,n){var e,i;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},this.wheres=null!=(i=r.wheres)?i:{},this.config=n}var n=r.prototype;return n.matchesUrl=function(r){var n=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,r,e,i){var u,o="(?<"+e+">"+((null==(u=n.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+r+o+")?":""+r+o}).replace(/^\w+:\/\//,""),i=r.replace(/^\w+:\/\//,"").split("?"),u=i[0],o=i[1],f=new RegExp("^"+e+"/?$").exec(decodeURI(u));if(f){for(var c in f.groups)f.groups[c]="string"==typeof f.groups[c]?decodeURIComponent(f.groups[c]):f.groups[c];return{params:f.groups,query:t(o)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(i?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(u=t[e])?u:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},i(r,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{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 t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),r}(),l=/*#__PURE__*/function(t){var n,e;function o(r,n,e,i){var o;if(void 0===e&&(e=!0),(o=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,o.t=u({},o.t,{absolute:e}),r){if(!o.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");o.i=new s(r,o.t.routes[r],o.t),o.u=o.o(n)}return o}e=t,(n=o).prototype=Object.create(e.prototype),n.prototype.constructor=n,f(n,e);var c=o.prototype;return c.toString=function(){var t=this,n=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var e;return u({},r,((e={})[n]=t.u[n],e))},{});return this.i.compile(this.u)+r(u({},n,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},c.l=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var n={},e=Object.entries(this.t.routes).find(function(e){return n=new s(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return u({name:e[0]},n,{route:e[1]})},c.v=function(){var t=this.h(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},c.current=function(t,r){var n=this.l(),e=n.name,i=n.params,o=n.query,f=n.route;if(!t)return e;var c=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(e);if([null,void 0].includes(r)||!c)return c;var a=new s(e,f,this.t);r=this.o(r,a);var l=u({},i,o);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},c.h=function(){var t,r,n,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t: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==(u=this.t.location)?void 0:u.search)?i:void 0===a?"":a}},c.has=function(t){return Object.keys(this.t.routes).includes(t)},c.o=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var e=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var i,o;return u({},t,e[n]?((i={})[e[n].name]=r,i):"object"==typeof r?r:((o={})[r]="",o))},{});else if(1===e.length&&!t[e[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[e[0].name]=t,t=i}return u({},this.p(r),this.m(t,r))},c.p=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,e){var i,o=n.name;return u({},t,((i={})[o]=r.t.defaults[o],i))},{})},c.m=function(t,r){var n=r.bindings,e=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,o,f=r[0],c=r[1];if(!c||"object"!=typeof c||Array.isArray(c)||!e.some(function(t){return t.name===f}))return u({},t,((o={})[f]=c,o));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 u({},t,((i={})[f]=c[n[f]],i))},{})},c.valueOf=function(){return this.toString()},i(o,[{key:"params",get:function(){var t=this.l();return u({},t.params,t.query)}}]),o}(/*#__PURE__*/a(String));function h(t,r,n,e){var i=new l(t,r,n,e);return t?i.toString():i}var v={install:function(t,r){var n=function(t,n,e,i){return void 0===i&&(i=r),h(t,n,e,i)};t.config.globalProperties.route=n,parseInt(t.version)>2&&t.provide("route",n)}};function d(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)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(r,n,e,i){return void 0===i&&(i=t),h(r,n,e,i)}}export{v as ZiggyVue,h as route,d as useRoute};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziggy-js",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Use your Laravel named routes in JavaScript.",
5
5
  "keywords": [
6
6
  "laravel",
@@ -41,9 +41,8 @@
41
41
  "build": "npm run build:esm && npm run build:umd",
42
42
  "build:esm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --external none --no-generateTypes",
43
43
  "build:npm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --no-generateTypes",
44
- "build:umd": "microbundle -i ./src/js/browser.js -o ./dist/route.js --format umd --no-sourcemap --external none --no-generateTypes",
45
- "test": "vitest",
46
- "typecheck": "vitest typecheck",
44
+ "build:umd": "microbundle -i ./src/js/browser.js -o ./dist/route.js --format umd --name route --no-sourcemap --external none --no-generateTypes",
45
+ "test": "vitest --typecheck",
47
46
  "format": "prettier . --write",
48
47
  "prepublishOnly": "rm -r ./dist/* && npm run build:npm"
49
48
  },
@@ -54,11 +53,11 @@
54
53
  "qs": "~6.9.7"
55
54
  },
56
55
  "devDependencies": {
57
- "jsdom": "^22.1.0",
56
+ "jsdom": "^23.0.1",
58
57
  "microbundle": "^0.15.1",
59
- "prettier": "^3.0.3",
60
- "typescript": "^5.2.2",
61
- "vitest": "^1.0.0-beta.1"
58
+ "prettier": "^3.1.1",
59
+ "typescript": "^5.3.3",
60
+ "vitest": "^1.0.4"
62
61
  },
63
62
  "prettier": {
64
63
  "printWidth": 100,