-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tsconfig types and added some fs tests
- Loading branch information
Showing
8 changed files
with
85 additions
and
2 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,17 @@ | ||
import { statSync } from 'node:fs'; | ||
|
||
/** | ||
* Determines if a directory exists and that it is indeed a directory. | ||
* | ||
* @param dir - The directory to check | ||
* @returns `true` if the directory exists and is a directory, otherwise | ||
* `false` | ||
*/ | ||
export function isDir(dir: string) { | ||
try { | ||
return statSync(dir).isDirectory(); | ||
} catch (e) { | ||
// squelch | ||
} | ||
return false; | ||
} |
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,14 @@ | ||
import { statSync } from 'node:fs'; | ||
|
||
/** | ||
* Determines if a file exists and that it is indeed a file. | ||
* | ||
* @param file - The file to check | ||
* @returns `true` if the file exists and is a file, otherwise `false` | ||
*/ | ||
export function isFile(file: string) { | ||
try { | ||
return statSync(file).isFile(); | ||
} catch {} | ||
return false; | ||
} |
Empty file.
Empty file.
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,23 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { isDir } from '../../src/fs/is-dir.js'; | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
describe('fs', () => { | ||
describe('isDir()', () => { | ||
it('should succeed if a directory exists', () => { | ||
const thisDir = dirname(fileURLToPath(import.meta.url)); | ||
expect(isDir(thisDir)).to.be.true; | ||
}); | ||
|
||
it('should fail if a directory does not exist', () => { | ||
const thisDir = dirname(fileURLToPath(import.meta.url)); | ||
expect(isDir(join(thisDir, 'doesnotexist'))).to.be.false; | ||
}); | ||
|
||
it('should fail if a directory is a file', () => { | ||
const thisFile = fileURLToPath(import.meta.url); | ||
expect(isDir(thisFile)).to.be.false; | ||
}); | ||
}); | ||
}); |
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,23 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { isFile } from '../../src/fs/is-file.js'; | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
describe('fs', () => { | ||
describe('isFile()', () => { | ||
it('should succeed if a file exists', () => { | ||
const thisFile = fileURLToPath(import.meta.url); | ||
expect(isFile(thisFile)).to.be.true; | ||
}); | ||
|
||
it('should fail if a file does not exist', () => { | ||
const thisDir = dirname(fileURLToPath(import.meta.url)); | ||
expect(isFile(join(thisDir, 'doesnotexist'))).to.be.false; | ||
}); | ||
|
||
it('should fail if a file is a directory', () => { | ||
const thisDir = dirname(fileURLToPath(import.meta.url)); | ||
expect(isFile(thisDir)).to.be.false; | ||
}); | ||
}); | ||
}); |
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