1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02: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;
};