@trapi/utils
Version:
Utils library package for the trapi infrastructure.
31 lines (22 loc) • 676 B
text/typescript
/*
* Copyright (c) 2021.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
;
export function normalizePath(str: string) : string {
// remove slashes
str = str.replace(/^[/\\\s]+|[/\\\s]+$/g, '');
str = str.replace(/([^:]\/)\/+/g, "$1");
return str;
}
export function normalizePathParameters(str: string) : string {
// <:id> -> {id}
str = str.replace(/<:([^\/]+)>/g, '{$1}');
// :id -> {id}
str = str.replace(/:([^\/]+)/g, '{$1}');
// <id> -> {id}
str = str.replace(/<([^\/]+)>/g, '{$1}');
return str;
}