Skip to content

Commit

Permalink
feat: support for upsertDirectory and pathExists
Browse files Browse the repository at this point in the history
Enabling quicker and simpler fs support.
  • Loading branch information
joamag committed Oct 25, 2023
1 parent d5e8368 commit 110a5f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Support for `upsertDirectory()` and `pathExists()` functions

### Changed

Expand Down
18 changes: 18 additions & 0 deletions ts/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { access, mkdir } from "fs/promises";

export const upsertDirectory = async (dirPath: string) => {
try {
await access(dirPath);
} catch (error) {
await mkdir(dirPath, { recursive: true });
}
};

export const pathExists = async (path: string): Promise<boolean> => {
try {
await access(path);
return true;
} catch (err) {
return false;
}
};
1 change: 1 addition & 0 deletions ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./fs";
export * from "./boot";
export * from "./logging";

0 comments on commit 110a5f6

Please sign in to comment.