diff options
Diffstat (limited to 'src/lib/relativePath.ts')
| -rw-r--r-- | src/lib/relativePath.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/relativePath.ts b/src/lib/relativePath.ts new file mode 100644 index 0000000..ad8582c --- /dev/null +++ b/src/lib/relativePath.ts @@ -0,0 +1,12 @@ +export default function (currentPath: string, relativePath: string) { + if (relativePath.length > 2 && relativePath.slice(0, 3) === '../') { + throw new Error('Cannot calculate relative path because it goes up a directory.'); + } + + if (currentPath.at(-1) !== '/') { + currentPath = currentPath + '/'; + } + relativePath = relativePath.replace(/^\.?\//, ''); + + return currentPath + relativePath; +} |
