-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
12e2a26
commit 1e6f18d
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Unit Tests - isDrivePath | ||
* @module pathe/internal/tests/unit/isDrivePath | ||
*/ | ||
|
||
import testSubject from '../is-drive-path' | ||
|
||
describe('unit:internal/isDrivePath', () => { | ||
it('should return false if path does not start with disk designator', () => { | ||
expect(testSubject('/tmp/myfile.html')).to.be.false | ||
}) | ||
|
||
it('should return true if path starts with disk designator', () => { | ||
expect(testSubject('C:\\temp\\myfile.html')).to.be.true | ||
}) | ||
}) |
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,19 @@ | ||
/** | ||
* @file Internal - Constants | ||
* @module pathe/internal/constants | ||
*/ | ||
|
||
/** | ||
* Drive path regex. | ||
* | ||
* Determines if a path starts with a [drive letter][1]. | ||
* | ||
* [1]: https://computerhope.com/jargon/d/drivelet.htm | ||
* | ||
* @see https://regex101.com/r/FsoDwJ | ||
* | ||
* @const {RegExp} DRIVE_PATH_REGEX | ||
*/ | ||
const DRIVE_PATH_REGEX: RegExp = /^(?<drive>(?<letter>[a-z]):)/i | ||
|
||
export { DRIVE_PATH_REGEX } |
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,30 @@ | ||
/** | ||
* @file Internal - isDrivePath | ||
* @module pathe/internal/isDrivePath | ||
*/ | ||
|
||
import { DRIVE_PATH_REGEX } from './constants' | ||
import validateString from './validate-string' | ||
|
||
/** | ||
* Determines if a path starts with a disk designator. | ||
* | ||
* [1]: https://computerhope.com/jargon/d/drivelet.htm | ||
* | ||
* @see https://docs.microsoft.com/windows/win32/fileio/naming-a-file | ||
* | ||
* @example | ||
* isDrivePath('C:\\temp\\myfile.html') // true | ||
* @example | ||
* isDrivePath('/tmp/myfile.html') // false | ||
* @example | ||
* isDrivePath('myfile.html') // false | ||
* | ||
* @param {string} path - Path to evaluate | ||
* @return {boolean} `true` if path starts with [drive letter][1] | ||
*/ | ||
const isDrivePath = (path: string): boolean => { | ||
return validateString(path, 'path') && DRIVE_PATH_REGEX.test(path) | ||
} | ||
|
||
export default isDrivePath |