Use JavaScript Optional chaining in vendors/*

This commit is contained in:
the-djmaze 2022-09-12 22:07:51 +02:00
parent e5e4675c1b
commit ef8b1f40e4
28 changed files with 619 additions and 750 deletions

View file

@ -34,7 +34,7 @@
while (n--) {
route = routes[n];
if ((!i || route.greedy) && route.match(request)) {
route.callback && route.callback(...route._getParamsArray(request));
route.callback?.(...route._getParamsArray(request));
++i;
}
}
@ -68,14 +68,14 @@
var val = values[key],
isValid = false;
if (key === 'normalize_'
|| (val == null && this._optionalParamsIds && this._optionalParamsIds.indexOf(key) !== -1)) {
|| (val == null && this._optionalParamsIds?.includes(key))) {
isValid = true;
}
else if (validationRule instanceof RegExp) {
isValid = validationRule.test(val);
}
else if (Array.isArray(validationRule)) {
isValid = validationRule.indexOf(val) !== -1;
isValid = validationRule.includes(val);
}
else if (isFunction(validationRule)) {
isValid = validationRule(val, request, values);
@ -133,7 +133,7 @@
captureVals = (regex, pattern) => {
var vals = [], match;
while (match = regex.exec(pattern)) {
while ((match = regex.exec(pattern))) {
vals.push(match[1]);
}
return vals;
@ -141,9 +141,7 @@
getParamValues = (request, regexp) => {
var vals = regexp.exec(request);
if (vals) {
vals.shift();
}
vals?.shift();
return vals;
},
compilePattern = pattern => {

View file

@ -15,11 +15,11 @@
_hashValRegexp = /#(.*)$/,
_hashRegexp = /^[#/]+/,
_hashTrim = /^\/|\$/g,
_trimHash = hash => hash ? hash.replace(_hashTrim, '') : '',
_trimHash = hash => hash?.replace(_hashTrim, '') || '',
_getWindowHash = () => {
//parsed full URL instead of getting window.location.hash because Firefox decode hash value (and all the other browsers don't)
var result = _hashValRegexp.exec( location.href );
return (result && result[1]) ? decodeURIComponent(result[1]) : '';
return result?.[1] ? decodeURIComponent(result[1]) : '';
},
_registerChange = newHash => {
if (_hash !== newHash) {