path-to-regexp#compile TypeScript Examples
The following examples show how to use
path-to-regexp#compile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From erda-ui with GNU Affero General Public License v3.0 | 6 votes |
generatePath = (path: string, params?: Obj) => {
try {
const toPathRepeated = compile(path);
return toPathRepeated(params);
} catch (error) {
// eslint-disable-next-line no-console
console.error('path:', path, 'Error parsing url parameters');
throw error;
}
}
Example #2
Source File: index.ts From erda-ui with GNU Affero General Public License v3.0 | 6 votes |
generatePath = (path: string, params?: Obj) => {
try {
const toPathRepeated = compile(path);
return toPathRepeated(params);
} catch (error) {
// eslint-disable-next-line no-console
console.error('path:', path, 'Error parsing url parameters');
throw error;
}
}
Example #3
Source File: index.ts From riot-api with MIT License | 6 votes |
async request<T>(
platformId: PlatformId,
methodKey: string,
pathData: { [key: string]: string | number },
options?: RiotAPITypes.RequestOptions
): Promise<T> {
const path = getPath(methodKey);
const createPath = compile(path, { encode: encodeURIComponent });
let url = `https://${createHost({ platformId })}${createPath(pathData)}`;
if (options?.params) url += `?${qs.encode(options.params)}`;
const cacheValue = await this.checkCache<T>(methodKey, url);
if (cacheValue) return cacheValue as T;
const resp = await this.riotRateLimiter.execute(
{ url, options: this.getOptions(options) },
this.getJobOptions(options)
);
await this.setCache(methodKey, url, resp);
return resp;
}
Example #4
Source File: matchPath.ts From next-core with GNU General Public License v3.0 | 5 votes |
export function toPath(path: string, pathParams: Record<string, any>): string {
return compile(path)(pathParams);
}
Example #5
Source File: index.ts From riot-api with MIT License | 5 votes |
createHost = compile(HOST, { encode: encodeURIComponent })