New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ziggy-js

Package Overview
Dependencies
Maintainers
7
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ziggy-js - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

9

CHANGELOG.md

@@ -9,2 +9,8 @@ # Changelog

## [v1.0.1] - 2020-11-10
**Fixed**
- Fix `route().current()` on routes at the domain root ([#356](https://github.com/tighten/ziggy/pull/356))
## [v1.0.0] - 2020-11-06

@@ -89,5 +95,6 @@

[Unreleased]: https://github.com/tighten/ziggy/compare/v1.0.0...HEAD
[Unreleased]: https://github.com/tighten/ziggy/compare/v1.0.1...HEAD
[v1.0.1]: https://github.com/tighten/ziggy/compare/v1.0.0...v1.0.1
[v1.0.0]: https://github.com/tighten/ziggy/compare/0.9.4...v1.0.0
[v0.9.4]: https://github.com/tighten/ziggy/compare/0.9.3...0.9.4
[v0.9.3]: https://github.com/tighten/ziggy/compare/v0.9.2...0.9.3

2

dist/index.es.js

@@ -1,2 +0,2 @@

import{stringify as t,parse as r}from"qs";function e(){return(e=Object.assign||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}).apply(this,arguments)}class i{constructor(t,r,e){var i;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.config=e}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,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var i;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error(`Ziggy error: '${e}' parameter is required for route '${this.name}'.`);return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){var o;if(super(),this.t=null!=(o=null!=n?n:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=e({},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.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>e({},t,{[r]:this.s[r]}),{});return this.i.compile(this.s)+t(e({},r,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new i(t,s,this.t).matchesUrl(e));if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);return r?(r=this.o(r,new i(s,n,this.t)),Object.entries(this.h(n)).filter(([t])=>r.hasOwnProperty(t)).every(([t,e])=>r[t]==e)):o}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){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,s)=>e({},t,{[i[s].name]: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.u(r),this.l(t,r.bindings))}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>e({},t,{[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[i,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===i)return e({},t,{[i]:s});if(!s.hasOwnProperty(r[i])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${r[i]}'.`);r[i]="id"}return e({},t,{[i]:s[r[i]]})},{})}h(t){var i;let s=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,r="",i)=>{const[s,n]=[t,r].map(t=>t.split(i));return n.reduce((t,r,i)=>/^{[^}?]+\??}$/.test(r)&&s[i]?e({},t,{[r.replace(/^{|\??}$/g,"")]:s[i]}):t,{})};return e({},n(window.location.host,t.domain,"."),n(s,t.uri,"/"),r(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,e,i){const n=new s(t,r,e,i);return t?n.toString():n}
import{stringify as t,parse as r}from"qs";function i(){return(i=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var i=arguments[r];for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])}return t}).apply(this,arguments)}class e{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},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,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp(`^${r}$`).test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;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 encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class s extends String{constructor(t,r,s=!0,n){var o;if(super(),this.t=null!=(o=null!=n?n:Ziggy)?o:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t=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 e(t,this.t.routes[t],this.t),this.s=this.o(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>i({},t,{[r]:this.s[r]}),{});return this.i.compile(this.s)+t(i({},r,this.s._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const i=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new e(t,s,this.t).matchesUrl(i))||[void 0,void 0];if(!t)return s;const o=new RegExp(`^${t.replace(".","\\.").replace("*",".*")}$`).test(s);return r?(r=this.o(r,new e(s,n,this.t)),Object.entries(this.h(n)).filter(([t])=>r.hasOwnProperty(t)).every(([t,i])=>r[t]==i)):o}get params(){return this.h(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}o(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,s)=>i({},t,{[e[s].name]:r}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),i({},this.u(r),this.l(t,r.bindings))}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},e)=>i({},t,{[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[e,s])=>{if(!s||"object"!=typeof s||Array.isArray(s)||"_query"===e)return i({},t,{[e]:s});if(!s.hasOwnProperty(r[e])){if(!s.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${e}' parameter is missing route model binding key '${r[e]}'.`);r[e]="id"}return i({},t,{[e]:s[r[e]]})},{})}h(t){var e;let s=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const n=(t,r="",e)=>{const[s,n]=[t,r].map(t=>t.split(e));return n.reduce((t,r,e)=>/^{[^}?]+\??}$/.test(r)&&s[e]?i({},t,{[r.replace(/^{|\??}$/g,"")]:s[e]}):t,{})};return i({},n(window.location.host,t.domain,"."),n(s,t.uri,"/"),r(null===(e=window.location.search)||void 0===e?void 0:e.replace(/^\?/,"")))}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,i,e){const n=new s(t,r,i,e);return t?n.toString():n}
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("qs")):"function"==typeof define&&define.amd?define(["qs"],e):(t=t||self).route=e(t.qs)}(this,function(t){class e{constructor(t,e,i){var r;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},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?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(/^\w+:\/\//,"");return new RegExp("^"+e+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{var r;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 encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class i extends String{constructor(t,i,r=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(i)}}toString(){const e=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+t.stringify({...e,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,i){const r=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r));if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);return i?(i=this.o(i,new e(s,n,this.t)),Object.entries(this.h(n)).filter(([t])=>i.hasOwnProperty(t)).every(([t,e])=>i[t]==e)):o}get params(){return this.h(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,r)=>({...t,[i[r].name]:e}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(e),...this.l(t,e.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}l(t,e={}){return Object.entries(t).reduce((t,[i,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===i)return{...t,[i]:r};if(!r.hasOwnProperty(e[i])){if(!r.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+e[i]+"'.");e[i]="id"}return{...t,[i]:r[e[i]]}},{})}h(e){var i;let r=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,e="",i)=>{const[r,s]=[t,e].map(t=>t.split(i));return s.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&r[i]?{...t,[e.replace(/^{|\??}$/g,"")]:r[i]}:t,{})};return{...s(window.location.host,e.domain,"."),...s(r,e.uri,"/"),...t.parse(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}return function(t,e,r,s){const n=new i(t,e,r,s);return t?n.toString():n}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("qs")):"function"==typeof define&&define.amd?define(["qs"],e):(t=t||self).route=e(t.qs)}(this,function(t){class e{constructor(t,e,i){var r;this.name=t,this.definition=e,this.bindings=null!=(r=e.bindings)?r:{},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?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(/^\w+:\/\//,"");return new RegExp("^"+e+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(e,i)=>{var r;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 encodeURIComponent(null!=(r=t[i])?r:"")}).replace(/\/+$/,""):this.template}}class i extends String{constructor(t,i,r=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:r},t){if(!this.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");this.i=new e(t,this.t.routes[t],this.t),this.s=this.o(i)}}toString(){const e=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((t,e)=>({...t,[e]:this.s[e]}),{});return this.i.compile(this.s)+t.stringify({...e,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}current(t,i){const r=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([i,s])=>new e(t,s,this.t).matchesUrl(r))||[void 0,void 0];if(!t)return s;const o=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);return i?(i=this.o(i,new e(s,n,this.t)),Object.entries(this.h(n)).filter(([t])=>i.hasOwnProperty(t)).every(([t,e])=>i[t]==e)):o}get params(){return this.h(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,r)=>({...t,[i[r].name]:e}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(e.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(e),...this.l(t,e.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:e},i)=>({...t,[e]:this.t.defaults[e]}),{})}l(t,e={}){return Object.entries(t).reduce((t,[i,r])=>{if(!r||"object"!=typeof r||Array.isArray(r)||"_query"===i)return{...t,[i]:r};if(!r.hasOwnProperty(e[i])){if(!r.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+e[i]+"'.");e[i]="id"}return{...t,[i]:r[e[i]]}},{})}h(e){var i;let r=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,e="",i)=>{const[r,s]=[t,e].map(t=>t.split(i));return s.reduce((t,e,i)=>/^{[^}?]+\??}$/.test(e)&&r[i]?{...t,[e.replace(/^{|\??}$/g,"")]:r[i]}:t,{})};return{...s(window.location.host,e.domain,"."),...s(r,e.uri,"/"),...t.parse(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}return function(t,e,r,s){const n=new i(t,e,r,s);return t?n.toString():n}});
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{stringify as t,parse as r}from"qs";class e{constructor(t,r,e){var i;this.name=t,this.definition=r,this.bindings=null!=(i=r.bindings)?i:{},this.config=e}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,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,e)=>{var i;if([null,void 0].includes(t[e])&&this.parameterSegments.find(({name:t})=>t===e).required)throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+this.name+"'.");return encodeURIComponent(null!=(i=t[e])?i:"")}).replace(/\/+$/,""):this.template}}class i extends String{constructor(t,r,i=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...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 e(t,this.t.routes[t],this.t),this.s=this.h(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>({...t,[r]:this.s[r]}),{});return this.i.compile(this.s)+t({...r,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const i=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new e(t,s,this.t).matchesUrl(i));if(!t)return s;const h=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);return r?(r=this.h(r,new e(s,n,this.t)),Object.entries(this.o(n)).filter(([t])=>r.hasOwnProperty(t)).every(([t,e])=>r[t]==e)):h}get params(){return this.o(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){t=["string","number"].includes(typeof t)?[t]:t;const e=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(t)?t=t.reduce((t,r,i)=>({...t,[e[i].name]:r}),{}):1!==e.length||t[e[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[e[0].name]:t}),{...this.u(r),...this.l(t,r.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},e)=>({...t,[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[e,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||"_query"===e)return{...t,[e]:i};if(!i.hasOwnProperty(r[e])){if(!i.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+e+"' parameter is missing route model binding key '"+r[e]+"'.");r[e]="id"}return{...t,[e]:i[r[e]]}},{})}o(t){var e;let i=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,r="",e)=>{const[i,s]=[t,r].map(t=>t.split(e));return s.reduce((t,r,e)=>/^{[^}?]+\??}$/.test(r)&&i[e]?{...t,[r.replace(/^{|\??}$/g,"")]:i[e]}:t,{})};return{...s(window.location.host,t.domain,"."),...s(i,t.uri,"/"),...r(null===(e=window.location.search)||void 0===e?void 0:e.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,e,s){const n=new i(t,r,e,s);return t?n.toString():n}
import{stringify as t,parse as r}from"qs";class i{constructor(t,r,i){var e;this.name=t,this.definition=r,this.bindings=null!=(e=r.bindings)?e:{},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,r;return null!=(t=null===(r=this.template.match(/{[^}?]+\??}/g))||void 0===r?void 0:r.map(t=>({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const r=this.template.replace(/\/{[^}?]*\?}/g,"(/[^/?]+)?").replace(/{[^}]+}/g,"[^/?]+").replace(/^\w+:\/\//,"");return new RegExp("^"+r+"$").test(t.replace(/\/+$/,"").split("?").shift())}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)\??}/g,(r,i)=>{var e;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 encodeURIComponent(null!=(e=t[i])?e:"")}).replace(/\/+$/,""):this.template}}class e extends String{constructor(t,r,e=!0,s){var n;if(super(),this.t=null!=(n=null!=s?s:Ziggy)?n:null===globalThis||void 0===globalThis?void 0:globalThis.Ziggy,this.t={...this.t,absolute:e},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.s=this.h(r)}}toString(){const r=Object.keys(this.s).filter(t=>!this.i.parameterSegments.some(({name:r})=>r===t)).filter(t=>"_query"!==t).reduce((t,r)=>({...t,[r]:this.s[r]}),{});return this.i.compile(this.s)+t({...r,...this.s._query},{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,r)=>"boolean"==typeof t?Number(t):r(t)})}current(t,r){const e=this.t.absolute?window.location.host+window.location.pathname:window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"),[s,n]=Object.entries(this.t.routes).find(([r,s])=>new i(t,s,this.t).matchesUrl(e))||[void 0,void 0];if(!t)return s;const h=new RegExp("^"+t.replace(".","\\.").replace("*",".*")+"$").test(s);return r?(r=this.h(r,new i(s,n,this.t)),Object.entries(this.o(n)).filter(([t])=>r.hasOwnProperty(t)).every(([t,i])=>r[t]==i)):h}get params(){return this.o(this.t.routes[this.current()])}has(t){return Object.keys(this.t.routes).includes(t)}h(t={},r=this.i){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,e)=>({...t,[i[e].name]:r}),{}):1!==i.length||t[i[0].name]||!t.hasOwnProperty(Object.values(r.bindings)[0])&&!t.hasOwnProperty("id")||(t={[i[0].name]:t}),{...this.u(r),...this.l(t,r.bindings)}}u(t){return t.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((t,{name:r},i)=>({...t,[r]:this.t.defaults[r]}),{})}l(t,r={}){return Object.entries(t).reduce((t,[i,e])=>{if(!e||"object"!=typeof e||Array.isArray(e)||"_query"===i)return{...t,[i]:e};if(!e.hasOwnProperty(r[i])){if(!e.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+i+"' parameter is missing route model binding key '"+r[i]+"'.");r[i]="id"}return{...t,[i]:e[r[i]]}},{})}o(t){var i;let e=window.location.pathname.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"");const s=(t,r="",i)=>{const[e,s]=[t,r].map(t=>t.split(i));return s.reduce((t,r,i)=>/^{[^}?]+\??}$/.test(r)&&e[i]?{...t,[r.replace(/^{|\??}$/g,"")]:e[i]}:t,{})};return{...s(window.location.host,t.domain,"."),...s(e,t.uri,"/"),...r(null===(i=window.location.search)||void 0===i?void 0:i.replace(/^\?/,""))}}valueOf(){return this.toString()}check(t){return this.has(t)}}export default function(t,r,i,s){const n=new e(t,r,i,s);return t?n.toString():n}
//# sourceMappingURL=index.m.js.map
{
"name": "ziggy-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "Use your Laravel named routes in JavaScript.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -69,3 +69,3 @@ import { parse, stringify } from 'qs';

* @param {(String|Number|Array|Object)} params - Route parameters.
* @return {(Boolean|String)}
* @return {(Boolean|String|undefined)}
*/

@@ -80,3 +80,3 @@ current(name, params) {

([_, route]) => new Route(name, route, this._config).matchesUrl(url)
);
) || [undefined, undefined];

@@ -83,0 +83,0 @@ // If a name wasn't passed, return the name of the current route

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc