-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename exported methods, add TypeScript definition (#5)
- Loading branch information
1 parent
7b3755c
commit f6de669
Showing
8 changed files
with
147 additions
and
48 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
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,51 @@ | ||
export type PathTypeFunction = (path: string) => Promise<boolean>; | ||
|
||
/** | ||
* Checks whether the passed `path` is a file. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a file. | ||
*/ | ||
export const isFile: PathTypeFunction; | ||
|
||
/** | ||
* Checks whether the passed `path` is a directory. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
export const isDirectory: PathTypeFunction; | ||
|
||
/** | ||
* Checks whether the passed `path` is a symlink. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a symlink. | ||
*/ | ||
export const isSymlink: PathTypeFunction; | ||
|
||
export type PathTypeSyncFunction = (path: string) => boolean; | ||
|
||
/** | ||
* Synchronously checks whether the passed `path` is a file. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a file. | ||
*/ | ||
export const isFileSync: PathTypeSyncFunction; | ||
|
||
/** | ||
* Synchronously checks whether the passed `path` is a directory. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
export const isDirectorySync: PathTypeSyncFunction; | ||
|
||
/** | ||
* Synchronously checks whether the passed `path` is a symlink. | ||
* | ||
* @param path - The path to check. | ||
* @returns Whether the `path` is a directory. | ||
*/ | ||
export const isSymlinkSync: PathTypeSyncFunction; |
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,17 @@ | ||
import {expectType} from 'tsd-check'; | ||
import { | ||
isFile, | ||
isDirectory, | ||
isSymlink, | ||
isFileSync, | ||
isDirectorySync, | ||
isSymlinkSync | ||
} from '.'; | ||
|
||
expectType<Promise<boolean>>(isFile('package.json')); | ||
expectType<Promise<boolean>>(isDirectory('package.json')); | ||
expectType<Promise<boolean>>(isSymlink('package.json')); | ||
|
||
expectType<boolean>(isFileSync('package.json')); | ||
expectType<boolean>(isDirectorySync('package.json')); | ||
expectType<boolean>(isSymlinkSync('package.json')); |
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
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 |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import test from 'ava'; | ||
import m from '..'; | ||
import pathType from '..'; | ||
|
||
test('.file()', async t => { | ||
t.true(await m.file('package.json')); | ||
await t.throwsAsync(m.file(false)); | ||
t.true(await pathType.isFile('package.json')); | ||
await t.throwsAsync(pathType.isFile(false)); | ||
}); | ||
|
||
test('.dir()', async t => { | ||
t.true(await m.dir('.')); | ||
await t.throwsAsync(m.dir(false)); | ||
t.true(await pathType.isDirectory('.')); | ||
await t.throwsAsync(pathType.isDirectory(false)); | ||
}); | ||
|
||
if (process.platform !== 'win32') { | ||
test('.symlink()', async t => { | ||
t.true(await m.symlink('symlink')); | ||
await t.throwsAsync(m.symlink(false)); | ||
t.true(await pathType.isSymlink('symlink')); | ||
await t.throwsAsync(pathType.isSymlink(false)); | ||
}); | ||
} | ||
|
||
test('.fileSync()', t => { | ||
t.true(m.fileSync('package.json')); | ||
t.true(pathType.isFileSync('package.json')); | ||
}); | ||
|
||
test('.dirSync()', t => { | ||
t.true(m.dirSync('.')); | ||
t.true(pathType.isDirectorySync('.')); | ||
}); | ||
|
||
if (process.platform !== 'win32') { | ||
test('.symlinkSync()', t => { | ||
t.true(m.symlinkSync('symlink')); | ||
t.true(pathType.isSymlinkSync('symlink')); | ||
}); | ||
} | ||
|
||
test('return false if path doesn\'t exist - async', async t => { | ||
t.false(await m.file('unicorn')); | ||
t.false(await pathType.isFile('unicorn')); | ||
}); | ||
|
||
test('return false if path doesn\'t exist - sync', t => { | ||
t.false(m.fileSync('unicorn')); | ||
t.false(pathType.isFileSync('unicorn')); | ||
}); | ||
|
||
test('throws invalid argument - async', async t => { | ||
await t.throwsAsync(m.file(false)); | ||
await t.throwsAsync(pathType.isFile(false)); | ||
}); | ||
|
||
test('throws on invalid argument - sync', t => { | ||
t.throws(() => m.fileSync(false)); | ||
t.throws(() => pathType.isFileSync(false)); | ||
}); |