(path: string, withPrefix?: string, withSuffix?: string, skipPrefixAndSuffixIfEmpty = true)
| 5 | * Replace ':pathParam' with '{pathParam}' |
| 6 | */ |
| 7 | export function normalisePath(path: string, withPrefix?: string, withSuffix?: string, skipPrefixAndSuffixIfEmpty = true) { |
| 8 | if ((!path || path === '/') && skipPrefixAndSuffixIfEmpty) { |
| 9 | return ''; |
| 10 | } |
| 11 | if (!path || typeof path !== 'string') { |
| 12 | path = '' + path; |
| 13 | } |
| 14 | // normalise beginning and end of the path |
| 15 | let normalised = path.replace(/^[/\\\s]+|[/\\\s]+$/g, ''); |
| 16 | normalised = withPrefix ? withPrefix + normalised : normalised; |
| 17 | normalised = withSuffix ? normalised + withSuffix : normalised; |
| 18 | // normalise / signs amount in all path |
| 19 | normalised = normalised.replace(/[/\\\s]+/g, '/'); |
| 20 | return normalised; |
| 21 | } |
| 22 | |
| 23 | export function convertColonPathParams(path: string) { |
| 24 | if (!path || typeof path !== 'string') { |
no outgoing calls
no test coverage detected