forked from getsentry/sentry-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversioning.ts
More file actions
26 lines (20 loc) · 860 Bytes
/
Copy pathversioning.ts
File metadata and controls
26 lines (20 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {stripTrailingSlash} from './utils';
export const VERSION_INDICATOR = '__v';
export const getLocalStorageVersionKey = (platform: string) => `version:${platform}`;
export const getUnversionedPath = (path: string | string[], trailingSlash = true) => {
const joined = Array.isArray(path) ? path.join('/') : path;
const unversioned = joined.split(VERSION_INDICATOR)[0];
if (trailingSlash) {
return unversioned[unversioned.length - 1] === '/' ? unversioned : `${unversioned}/`;
}
return unversioned;
};
export const isVersioned = (path: string) => path.includes(VERSION_INDICATOR);
export const stripVersion = (path: string) => path.split(VERSION_INDICATOR)[0];
export const getVersion = (path: string) => {
const version = path.split(VERSION_INDICATOR)[1];
if (!version) {
return '';
}
return stripTrailingSlash(version);
};