Comparing version 1.8.1 to 2.0.0-beta.1
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("qs")):"function"==typeof define&&define.amd?define(["qs"],n):(t||self).route=n(t.qs)}(this,function(t){function n(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.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 r(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},e.apply(this,arguments)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function u(t,n){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},u(t,n)}function o(t,n,r){return o=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,n,r){var e=[null];e.push.apply(e,n);var i=new(Function.bind.apply(t,e));return r&&u(i,r.prototype),i},o.apply(null,arguments)}function f(t){var n="function"==typeof Map?new Map:void 0;return f=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 o(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)},f(t)}var c=/*#__PURE__*/function(){function n(t,n,r){var e,i;this.name=t,this.definition=n,this.bindings=null!=(e=n.bindings)?e:{},this.wheres=null!=(i=n.wheres)?i:{},this.config=r}var e=n.prototype;return e.matchesUrl=function(n){var r=this;if(!this.definition.methods.includes("GET"))return!1;var e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,function(t,n,e,i){var u,o="(?<"+e+">"+((null==(u=r.wheres[e])?void 0:u.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+n+o+")?":""+n+o}).replace(/^\w+:\/\//,""),i=n.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.parse(o)}}return!1},e.compile=function(t){var n=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(r,e,i){var u,o;if(!i&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+n.name+"'.");if(n.wheres[e]&&!new RegExp("^"+(i?"("+n.wheres[e]+")?":n.wheres[e])+"$").test(null!=(o=t[e])?o:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+n.wheres[e]+"' for route '"+n.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},r(n,[{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,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:[]}}]),n}(),a=/*#__PURE__*/function(n){var i,o;function f(t,r,i,u){var o;if(void 0===i&&(i=!0),(o=n.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 c(t,o.t.routes[t],o.t),o.u=o.o(r)}return o}o=n,(i=f).prototype=Object.create(o.prototype),i.prototype.constructor=i,u(i,o);var a=f.prototype;return a.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.stringify(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)}})},a.l=function(t){var n=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.h().host+t):t=this.v();var r={},i=Object.entries(this.t.routes).find(function(e){return r=new c(e[0],e[1],n.t).matchesUrl(t)})||[void 0,void 0];return e({name:i[0]},r,{route:i[1]})},a.v=function(){var t=this.h(),n=t.pathname,r=t.search;return(this.t.absolute?t.host+n:n.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r},a.current=function(t,n){var r=this.l(),i=r.name,u=r.params,o=r.query,f=r.route;if(!t)return i;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(i);if([null,void 0].includes(n)||!a)return a;var s=new c(i,f,this.t);n=this.o(n,s);var l=e({},u,o);return!(!Object.values(n).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(n).every(function(t){return l[t[0]]==t[1]})},a.h=function(){var t,n,r,e,i,u,o="undefined"!=typeof window?window.location:{},f=o.host,c=o.pathname,a=o.search;return{host:null!=(t=null==(n=this.t.location)?void 0:n.host)?t: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===a?"":a}},a.has=function(t){return Object.keys(this.t.routes).includes(t)},a.o=function(t,n){var r=this;void 0===t&&(t={}),void 0===n&&(n=this.i),null!=t||(t={}),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):"object"==typeof n?n:((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.g(n),this.p(t,n))},a.g=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))},{})},a.p=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))},{})},a.valueOf=function(){return this.toString()},a.check=function(t){return this.has(t)},r(f,[{key:"params",get:function(){var t=this.l();return e({},t.params,t.query)}}]),f}(/*#__PURE__*/f(String));return function(t,n,r,e){var i=new a(t,n,r,e);return t?i.toString():i}}); | ||
import{parse as t,stringify as r}from"qs";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},e.apply(this,arguments)}class i{constructor(t,r,e){var i,n;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.wheres=null!=(n=r.wheres)?n:{},this.config=e}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,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(r){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,r,e,i)=>{var n;const s=`(?<${e}>${(null==(n=this.wheres[e])?void 0:n.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return i?`(${r}${s})?`:`${r}${s}`}).replace(/^\w+:\/\//,""),[i,n]=r.replace(/^\w+:\/\//,"").split("?"),s=new RegExp(`^${e}/?$`).exec(decodeURI(i));if(s){for(const t in s.groups)s.groups[t]="string"==typeof s.groups[t]?decodeURIComponent(s.groups[t]):s.groups[t];return{params:s.groups,query:t(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(r,e,i)=>{var n,s;if(!i&&[null,void 0].includes(t[e]))throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);if(this.wheres[e]&&!new RegExp(`^${i?`(${this.wheres[e]})?`:this.wheres[e]}$`).test(null!=(s=t[e])?s:""))throw new Error(`Ziggy error: '${e}' parameter does not match required format '${this.wheres[e]}' for route '${this.name}'.`);return encodeURI(null!=(n=t[e])?n:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class n extends String{constructor(t,r,n=!0,s){if(super(),this.t=null!=s?s:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=e({},this.t,{absolute:n}),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.o=this.h(r)}}toString(){const t=Object.keys(this.o).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.o[r]}),{});return this.i.compile(this.o)+r(e({},t,this.o._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}u(t){t?this.t.absolute&&t.startsWith("/")&&(t=this.l().host+t):t=this.m();let r={};const[n,s]=Object.entries(this.t.routes).find(([e,n])=>r=new i(e,n,this.t).matchesUrl(t))||[void 0,void 0];return e({name:n},r,{route:s})}m(){const{host:t,pathname:r,search:e}=this.l();return(this.t.absolute?t+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e}current(t,r){const{name:n,params:s,query:o,route:h}=this.u();if(!t)return n;const u=new RegExp(`^${t.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!u)return u;const a=new i(n,h,this.t);r=this.h(r,a);const l=e({},s,o);return!(!Object.values(r).every(t=>!t)||Object.values(l).some(t=>void 0!==t))||Object.entries(r).every(([t,r])=>l[t]==r)}l(){var t,r,e,i,n,s;const{host:o="",pathname:h="",search:u=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:o,pathname:null!=(e=null==(i=this.t.location)?void 0:i.pathname)?e:h,search:null!=(n=null==(s=this.t.location)?void 0:s.search)?n:u}}get params(){const{params:t,query:r}=this.u();return e({},t,r)}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;const i=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,n)=>e({},t,i[n]?{[i[n].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),e({},this.$(r),this.p(t,r))}$(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}p(t,{bindings:r,parameterSegments:i}){return Object.entries(t).reduce((t,[n,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||!i.some(({name:t})=>t===n))return e({},t,{[n]:s});if(!s.hasOwnProperty(r[n])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${n}' parameter is missing route model binding key '${r[n]}'.`);r[n]="id"}return e({},t,{[n]:s[r[n]]})},{})}valueOf(){return this.toString()}}function s(t,r,e,i){const s=new n(t,r,e,i);return t?s.toString():s}const o={install(t,r){const e=(t,e,i,n=r)=>s(t,e,i,n);t.config.globalProperties.route=e,parseInt(t.version)>2&&t.provide("route",e)}};function h(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(r,e,i,n=t)=>s(r,e,i,n)}export{o as ZiggyVue,s as route,h as useRoute}; |
{ | ||
"name": "ziggy-js", | ||
"version": "1.8.1", | ||
"version": "2.0.0-beta.1", | ||
"description": "Use your Laravel named routes in JavaScript.", | ||
@@ -13,2 +13,6 @@ "keywords": [ | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tighten/ziggy.git" | ||
}, | ||
"authors": [ | ||
@@ -32,26 +36,16 @@ { | ||
], | ||
"source": "src/js/index.js", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.js", | ||
"unpkg": "dist/index.js", | ||
"browser": "dist/index.js", | ||
"module": "dist/index.m.js", | ||
"esmodule": "dist/index.es.js", | ||
"types": "src/js/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tighten/ziggy.git" | ||
}, | ||
"type": "module", | ||
"source": "./src/js/index.js", | ||
"exports": "./dist/ziggy.js", | ||
"module": "./dist/ziggy.esm.js", | ||
"types": "./src/js/index.d.ts", | ||
"scripts": { | ||
"build": "microbundle --name route --format modern,es,umd --external none --no-sourcemap --no-generateTypes", | ||
"build:vue": "microbundle --entry src/js/vue.js --output dist/vue.js --name ZiggyVue --format modern,es,umd --external none --no-sourcemap --no-generateTypes", | ||
"build:react": "microbundle --entry src/js/react.js --output dist/react.js --name ZiggyReact --format modern,es,umd --external none --no-sourcemap --no-generateTypes", | ||
"watch": "npm run build watch", | ||
"build:npm": "microbundle --name route --format modern,es,umd --no-sourcemap --no-generateTypes", | ||
"build:npm:vue": "microbundle --entry src/js/vue.js --output dist/vue.js --name ZiggyVue --format modern,es,umd --no-sourcemap --no-generateTypes", | ||
"build:npm:react": "microbundle --entry src/js/react.js --output dist/react.js --name ZiggyReact --format modern,es,umd --no-sourcemap --no-generateTypes", | ||
"build": "npm run build:esm && npm run build:umd", | ||
"build:esm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --external none --no-generateTypes", | ||
"build:npm": "microbundle -i ./src/js/index.js -o ./dist/index.js --format modern,esm --no-sourcemap --no-generateTypes", | ||
"build:umd": "microbundle -i ./src/js/browser.js -o ./dist/route.js --format umd --no-sourcemap --external none --no-generateTypes", | ||
"test": "vitest", | ||
"typecheck": "vitest typecheck", | ||
"format": "prettier . --write", | ||
"prepublishOnly": "npm run build:npm && npm run build:npm:vue && npm run build:npm:react" | ||
"prepublishOnly": "rm -r ./dist/* && npm run build:npm" | ||
}, | ||
@@ -65,2 +59,3 @@ "mangle": { | ||
"devDependencies": { | ||
"jsdom": "^22.1.0", | ||
"microbundle": "^0.15.1", | ||
@@ -67,0 +62,0 @@ "prettier": "^3.0.3", |
@@ -13,4 +13,2 @@ ![Ziggy - Use your Laravel routes in JavaScript](https://raw.githubusercontent.com/tighten/ziggy/main/ziggy-banner.png) | ||
Ziggy supports all versions of Laravel from `5.4` onward, and all modern browsers. | ||
- [**Installation**](#installation) | ||
@@ -274,3 +272,3 @@ - [**Usage**](#usage) | ||
```ts | ||
import routeFn from 'ziggy-js'; | ||
import { route as routeFn } from 'ziggy-js'; | ||
@@ -341,3 +339,3 @@ declare global { | ||
```js | ||
import route from '../../vendor/tightenco/ziggy/dist'; | ||
import { route } from '../../vendor/tightenco/ziggy'; | ||
import { Ziggy } from './ziggy.js'; | ||
@@ -356,4 +354,3 @@ | ||
alias: { | ||
'ziggy-js': 'vendor/tightenco/ziggy/dist', | ||
// 'vendor/tightenco/ziggy/dist/vue.es' if using the Vue plugin | ||
'ziggy-js': path.resolve('vendor/tightenco/ziggy'), | ||
}, | ||
@@ -367,3 +364,3 @@ }, | ||
```js | ||
import route from 'ziggy-js'; | ||
import { route } from 'ziggy-js'; | ||
``` | ||
@@ -400,4 +397,2 @@ | ||
If you use the Vue plugin with the `ziggy-js` import alias shown above, make sure to update the alias to `vendor/tightenco/ziggy/dist/vue.es`. | ||
### React | ||
@@ -537,3 +532,3 @@ | ||
use Tightenco\Ziggy\Ziggy; | ||
use Tighten\Ziggy\Ziggy; | ||
@@ -540,0 +535,0 @@ Route::get('api/ziggy', fn () => response()->json(new Ziggy)); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
Yes
41807
5
6
207
597