@trapi/utils
Version:
Utils library package for the trapi infrastructure.
27 lines • 905 B
JavaScript
/*
* 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.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizePathParameters = exports.normalizePath = void 0;
function normalizePath(str) {
// remove slashes
str = str.replace(/^[/\\\s]+|[/\\\s]+$/g, '');
str = str.replace(/([^:]\/)\/+/g, "$1");
return str;
}
exports.normalizePath = normalizePath;
function normalizePathParameters(str) {
// <:id> -> {id}
str = str.replace(/<:([^\/]+)>/g, '{$1}');
// :id -> {id}
str = str.replace(/:([^\/]+)/g, '{$1}');
// <id> -> {id}
str = str.replace(/<([^\/]+)>/g, '{$1}');
return str;
}
exports.normalizePathParameters = normalizePathParameters;
//# sourceMappingURL=path.js.map