Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// Generate the regex matcher and params keys
routes[i].paramKeys = [];
// Any URL
if (routes[i].path == '*') {
routes[i].matcher = /.*/i;
routes[i].generator = () => '/';
// Regex based
} else {
routes[i].matcher = pathToRegexp(
routes[i].path,
routes[i].paramKeys, {
end: routes[i].children.length == 0,
});
routes[i].generator = pathToRegexp.compile(routes[i].path);
}
// Process children
if (routes[i].children.length > 0) {
this._preprocessRoutes(routes[i].children, routes[i]);
}
}
}
let {
data,
url,
} = options;
const cloneData = lodash.cloneDeep(data);
try {
let domin = '';
if (url.match(/[a-zA-z]+:\/\/[^/]*/)) {
domin = url.match(/[a-zA-z]+:\/\/[^/]*/)[0];
url = url.slice(domin.length);
}
const match = pathToRegexp.parse(url);
url = pathToRegexp.compile(url)(data);
for (const item of match) {
// eslint-disable-next-line
if (item instanceof Object && item.name in cloneData) {
delete cloneData[item.name];
}
}
url = domin + url;
} catch (e) {
message.error(e.message);
}
if (fetchType === 'JSONP') {
return new Promise((resolve, reject) => {
jsonp(url, {
param: `${qs.stringify(data)}&callback`,
name: `jsonp_${new Date().getTime()}`,
function compilePath(path: string): PathMapping {
// Prefix all the path patterns with / because path-to-regexp requires one
path = '/' + path;
const cons = p2r.compile(path);
// Because the patterns were prefixed with slashes, we remove them on construction
return {re: p2r(path), cons: (params: Params) => cons(params).substring(1)};
}
export const generateLanguage = (locale, location) => {
const ROUTE = "/:locale/:path*";
const definePath = compile(ROUTE);
const routeComponents = PathToRegexp(ROUTE).exec(location.pathname);
let subPaths = null;
if (routeComponents && routeComponents[2]) {
subPaths = routeComponents[2].split("/");
}
return definePath({
locale,
path: subPaths,
});
};
function compileRoute (route, options) {
var re
var compiled
var keys = []
var querySeparator = options.querySeparator || '?'
re = pathToRegexp(route, keys)
keys = keys.map(getKeyName)
compiled = pathToRegexp.compile(route)
return {
parse: function (url) {
var path = url
var result = {}
if (~path.indexOf('#') && !~querySeparator.indexOf('#')) {
path = path.split('#')[0]
}
if (~path.indexOf(querySeparator)) {
if (options.query) {
var queryString = '$' + path.slice(path.indexOf(querySeparator) + querySeparator.length)
result = URLON.parse(queryString)
}
path = path.split(querySeparator)[0]
routes.forEach(route => {
const [name, path] = route
this._compilers[name] = pathToRegexp.compile(path)
})
}
constructor({url, dataProvider = () => Promise.resolve([])}) {
this.url = url;
this.toPath = pathToRegexp.compile(this.url);
this.dataProvider = dataProvider;
}
spec.path = spec.url;
}
this.path = spec.path || '';
if (this.path.indexOf('/') === 0) {
this.fullPath = this.path;
} else {
const parentPath = this.parentState ? this.parentState.fullPath : '/';
this.fullPath = parentPath.replace(/\/+$/, '') +
(this.path ? '/' + this.path : '');
}
if (!this.fullPath) {
this.fullPath = '/';
}
this._pathParams = [];
this._pathRegex = pathToRegexp(this.fullPath, this._pathParams);
this._pathFormat = pathToRegexp.compile(this.fullPath);
}
function tryCompilePath(path, values) {
try {
return pathToRegexp.compile(path)(values);
} catch (e) {
return path.replace(/:/g, "");
}
}
ApiMethod.prototype.makeHref = function(query) {
query = query || {};
if (!this._toPath) this._toPath = pathToRegexp.compile(this.fullPath());
return this._toPath(query);
};