This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
generated from mrbrianevans/react-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sessionStorage repository of media URLs GH-35
Signed-off-by: Brian Evans <[email protected]>
- Loading branch information
1 parent
5b915ea
commit 32a4b09
Showing
5 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { normalisePath, onlyFilename } from '../../../lib/common/PathProcessing' | ||
import * as Assert from 'assert-js' | ||
|
||
describe('test path processing utils functions', function () { | ||
it('should normalise a windows style file path', function () { | ||
const path = `C:\\\\Users\\\\abc\\\\Documents\\\\file.txt` | ||
const normalisedPath = normalisePath(path) | ||
Assert.equal(normalisedPath, 'C:/Users/abc/Documents/file.txt') | ||
}) | ||
|
||
it('should get the filename of a windows style path', function () { | ||
const path = `C:\\Users\\abc\\Documents\\file.txt` | ||
const normalisedPath = onlyFilename(path) | ||
Assert.equal(normalisedPath, 'file.txt') | ||
}) | ||
|
||
it('should get only the filename with a leading slash and directory', function () { | ||
const path = `/photos/file.txt` | ||
const normalisedPath = onlyFilename(path) | ||
Assert.equal(normalisedPath, 'file.txt') | ||
}) | ||
|
||
it('should get only the filename with a leading slash', function () { | ||
const path = `/file.txt` | ||
const normalisedPath = onlyFilename(path) | ||
Assert.equal(normalisedPath, 'file.txt') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function normalisePath(path: string) { | ||
// replace seperators | ||
path = path.replace(/\\+/g, '/') | ||
path = path.startsWith('/') ? path.slice(1) : path | ||
return path | ||
} | ||
|
||
export function onlyFilename(path: string) { | ||
const normalPath = normalisePath(path) | ||
return normalPath.split('/').slice(-1)[0] // .at(-1) not yet available | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters