1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/format-base-uri.ts
Fredrik Strand Oseberg 85a544bbd6
Feat/format base path (#828)
* chore: update changelog

* feat: add formatBaseUri helper

* feat: call formatBaseUri on server options

* feat: call formatBaseUri on user options

* fix: update test

* fix: disable consistent return
2021-05-03 12:28:59 +02:00

20 lines
467 B
TypeScript

export const formatBaseUri = (input: string): string => {
if (!input) return '';
const firstChar = input[0];
const lastChar = input[input.length - 1];
if (firstChar === '/' && lastChar === '/') {
return input.substr(0, input.length - 1);
}
if (firstChar !== '/' && lastChar === '/') {
return `/${input.substr(0, input.length - 1)}`;
}
if (firstChar !== '/') {
return `/${input}`;
}
return input;
};