UNPKG

@trapi/utils

Version:

Utils library package for the trapi infrastructure.

31 lines (22 loc) 676 B
/* * 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. */ 'use strict'; 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; }