diff --git a/Resources/js/router.ts b/Resources/js/router.ts index c83bf98..66c780b 100644 --- a/Resources/js/router.ts +++ b/Resources/js/router.ts @@ -155,7 +155,7 @@ export class Router { } }); } else if (typeof params === 'object') { - for (name in params) { + for (const name of Object.keys(params)) { this.buildQueryParams(prefix + '[' + name + ']', params[name], add); } } else { @@ -172,9 +172,9 @@ export class Router { let prefixedSf41i18nName = this.context_.prefix + name + '.' + this.context_.locale; let variants = [prefixedName, sf41i18nName, prefixedSf41i18nName, name]; - for (let i in variants) { - if (variants[i] in this.routes_) { - return this.routes_[variants[i]]; + for (const variant of variants) { + if (variant in this.routes_) { + return this.routes_[variant]; } } @@ -296,10 +296,8 @@ export class Router { queryParams.push(Router.encodeQueryComponent(key) + '=' + Router.encodeQueryComponent(value)); }; - for (const prefix in unusedParams) { - if(unusedParams.hasOwnProperty(prefix)) { - this.buildQueryParams(prefix, unusedParams[prefix], add); - } + for (const prefix of Object.keys(unusedParams)) { + this.buildQueryParams(prefix, unusedParams[prefix], add); } url = url + '?' + queryParams.join('&'); diff --git a/Resources/public/js/router.js b/Resources/public/js/router.js index 0d1c911..3dab10d 100644 --- a/Resources/public/js/router.js +++ b/Resources/public/js/router.js @@ -1,22 +1,22 @@ -(function (root, factory) { - var routing = factory(); - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], routing.Routing); - } else if (typeof module === 'object' && module.exports) { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = routing.Routing; - } else { - // Browser globals (root is window) - root.Routing = routing.Routing; - root.fos = { - Router: routing.Router - }; - } -}(this, function () { - var exports = {}; +(function (root, factory) { + var routing = factory(); + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define([], routing.Routing); + } else if (typeof module === 'object' && module.exports) { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = routing.Routing; + } else { + // Browser globals (root is window) + root.Routing = routing.Routing; + root.fos = { + Router: routing.Router + }; + } +}(this, function () { + var exports = {}; "use strict"; exports.__esModule = true; exports.Routing = exports.Router = void 0; @@ -109,8 +109,9 @@ var Router = /** @class */ (function () { }); } else if (typeof params === 'object') { - for (name in params) { - this.buildQueryParams(prefix + '[' + name + ']', params[name], add); + for (var _i = 0, _a = Object.keys(params); _i < _a.length; _i++) { + var name_1 = _a[_i]; + this.buildQueryParams(prefix + '[' + name_1 + ']', params[name_1], add); } } else { @@ -125,9 +126,10 @@ var Router = /** @class */ (function () { var sf41i18nName = name + '.' + this.context_.locale; var prefixedSf41i18nName = this.context_.prefix + name + '.' + this.context_.locale; var variants = [prefixedName, sf41i18nName, prefixedSf41i18nName, name]; - for (var i in variants) { - if (variants[i] in this.routes_) { - return this.routes_[variants[i]]; + for (var _i = 0, variants_1 = variants; _i < variants_1.length; _i++) { + var variant = variants_1[_i]; + if (variant in this.routes_) { + return this.routes_[variant]; } } throw new Error('The route "' + name + '" does not exist.'); @@ -230,10 +232,9 @@ var Router = /** @class */ (function () { value = (value === null) ? '' : value; queryParams_1.push(Router.encodeQueryComponent(key) + '=' + Router.encodeQueryComponent(value)); }; - for (var prefix in unusedParams) { - if (unusedParams.hasOwnProperty(prefix)) { - this.buildQueryParams(prefix, unusedParams[prefix], add); - } + for (var _i = 0, _a = Object.keys(unusedParams); _i < _a.length; _i++) { + var prefix = _a[_i]; + this.buildQueryParams(prefix, unusedParams[prefix], add); } url = url + '?' + queryParams_1.join('&'); } @@ -277,7 +278,7 @@ var Router = /** @class */ (function () { exports.Router = Router; exports.Routing = new Router(); exports["default"] = exports.Routing; - - - return { Router: exports.Router, Routing: exports.Routing }; -})); \ No newline at end of file + + + return { Router: exports.Router, Routing: exports.Routing }; +})); \ No newline at end of file diff --git a/Resources/public/js/router.min.js b/Resources/public/js/router.min.js index 50f2442..895186c 100644 --- a/Resources/public/js/router.min.js +++ b/Resources/public/js/router.min.js @@ -1 +1 @@ -!function(e){(t={}).__esModule=!0,t.Routing=t.Router=void 0,o=function(){function l(e,t){this.context_=e||{base_url:"",prefix:"",host:"",port:"",scheme:"",locale:""},this.setRoutes(t||{})}return l.getInstance=function(){return t.Routing},l.setData=function(e){l.getInstance().setRoutingData(e)},l.prototype.setRoutingData=function(e){this.setBaseUrl(e.base_url),this.setRoutes(e.routes),void 0!==e.prefix&&this.setPrefix(e.prefix),void 0!==e.port&&this.setPort(e.port),void 0!==e.locale&&this.setLocale(e.locale),this.setHost(e.host),void 0!==e.scheme&&this.setScheme(e.scheme)},l.prototype.setRoutes=function(e){this.routes_=Object.freeze(e)},l.prototype.getRoutes=function(){return this.routes_},l.prototype.setBaseUrl=function(e){this.context_.base_url=e},l.prototype.getBaseUrl=function(){return this.context_.base_url},l.prototype.setPrefix=function(e){this.context_.prefix=e},l.prototype.setScheme=function(e){this.context_.scheme=e},l.prototype.getScheme=function(){return this.context_.scheme},l.prototype.setHost=function(e){this.context_.host=e},l.prototype.getHost=function(){return this.context_.host},l.prototype.setPort=function(e){this.context_.port=e},l.prototype.getPort=function(){return this.context_.port},l.prototype.setLocale=function(e){this.context_.locale=e},l.prototype.getLocale=function(){return this.context_.locale},l.prototype.buildQueryParams=function(o,e,n){var t,r=this,s=new RegExp(/\[\]$/);if(e instanceof Array)e.forEach(function(e,t){s.test(o)?n(o,e):r.buildQueryParams(o+"["+("object"==typeof e?t:"")+"]",e,n)});else if("object"==typeof e)for(t in e)this.buildQueryParams(o+"["+t+"]",e[t],n);else n(o,e)},l.prototype.getRoute=function(e){var t,o=[this.context_.prefix+e,e+"."+this.context_.locale,this.context_.prefix+e+"."+this.context_.locale,e];for(t in o)if(o[t]in this.routes_)return this.routes_[o[t]];throw new Error('The route "'+e+'" does not exist.')},l.prototype.generate=function(r,e,p){var t,s=this.getRoute(r),i=e||{},u=Object.assign({},i),c="",a=!0,o="",e=void 0===this.getPort()||null===this.getPort()?"":this.getPort();if(s.tokens.forEach(function(e){if("text"===e[0]&&"string"==typeof e[1])return c=l.encodePathComponent(e[1])+c,void(a=!1);if("variable"!==e[0])throw new Error('The token type "'+e[0]+'" is not supported.');6===e.length&&!0===e[5]&&(a=!1);var t=s.defaults&&!Array.isArray(s.defaults)&&"string"==typeof e[3]&&e[3]in s.defaults;if(!1===a||!t||"string"==typeof e[3]&&e[3]in i&&!Array.isArray(s.defaults)&&i[e[3]]!=s.defaults[e[3]]){var o,n=void 0;if("string"==typeof e[3]&&e[3]in i)n=i[e[3]],delete u[e[3]];else{if("string"!=typeof e[3]||!t||Array.isArray(s.defaults)){if(a)return;throw new Error('The route "'+r+'" requires the parameter "'+e[3]+'".')}n=s.defaults[e[3]]}(!0===n||!1===n||""===n)&&a||(o=l.encodePathComponent(n),c=e[1]+(o="null"===o&&null===n?"":o)+c),a=!1}else t&&"string"==typeof e[3]&&e[3]in u&&delete u[e[3]]}),""===c&&(c="/"),s.hosttokens.forEach(function(e){var t;"text"!==e[0]?"variable"===e[0]&&(e[3]in i?(t=i[e[3]],delete u[e[3]]):s.defaults&&!Array.isArray(s.defaults)&&e[3]in s.defaults&&(t=s.defaults[e[3]]),o=e[1]+t+o):o=e[1]+o}),c=this.context_.base_url+c,s.requirements&&"_scheme"in s.requirements&&this.getScheme()!=s.requirements._scheme?(t=o||this.getHost(),c=s.requirements._scheme+"://"+t+(-1{(t={__esModule:!0}).Routing=t.Router=void 0,o=(()=>{function d(e,t){this.context_=e||{base_url:"",prefix:"",host:"",port:"",scheme:"",locale:""},this.setRoutes(t||{})}return d.getInstance=function(){return t.Routing},d.setData=function(e){d.getInstance().setRoutingData(e)},d.prototype.setRoutingData=function(e){this.setBaseUrl(e.base_url),this.setRoutes(e.routes),void 0!==e.prefix&&this.setPrefix(e.prefix),void 0!==e.port&&this.setPort(e.port),void 0!==e.locale&&this.setLocale(e.locale),this.setHost(e.host),void 0!==e.scheme&&this.setScheme(e.scheme)},d.prototype.setRoutes=function(e){this.routes_=Object.freeze(e)},d.prototype.getRoutes=function(){return this.routes_},d.prototype.setBaseUrl=function(e){this.context_.base_url=e},d.prototype.getBaseUrl=function(){return this.context_.base_url},d.prototype.setPrefix=function(e){this.context_.prefix=e},d.prototype.setScheme=function(e){this.context_.scheme=e},d.prototype.getScheme=function(){return this.context_.scheme},d.prototype.setHost=function(e){this.context_.host=e},d.prototype.getHost=function(){return this.context_.host},d.prototype.setPort=function(e){this.context_.port=e},d.prototype.getPort=function(){return this.context_.port},d.prototype.setLocale=function(e){this.context_.locale=e},d.prototype.getLocale=function(){return this.context_.locale},d.prototype.buildQueryParams=function(o,e,n){var r=this,s=new RegExp(/\[\]$/);if(e instanceof Array)e.forEach(function(e,t){s.test(o)?n(o,e):r.buildQueryParams(o+"["+("object"==typeof e?t:"")+"]",e,n)});else if("object"==typeof e)for(var t=0,i=Object.keys(e);t