https://github.com/hugoalh/fs-es
An ES (JavaScript & TypeScript) module for enhanced file system operation.
https://github.com/hugoalh/fs-es
es file file-system fs javascript js modulejs ts typescript
Last synced: 8 months ago
JSON representation
An ES (JavaScript & TypeScript) module for enhanced file system operation.
- Host: GitHub
- URL: https://github.com/hugoalh/fs-es
- Owner: hugoalh
- License: other
- Created: 2024-11-07T05:11:08.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-01-21T08:45:31.000Z (9 months ago)
- Last Synced: 2025-01-21T09:29:53.194Z (9 months ago)
- Topics: es, file, file-system, fs, javascript, js, modulejs, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 66.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# File System (ES)
[**โ๏ธ** MIT](./LICENSE.md)
[](https://github.com/hugoalh/fs-es)
[](https://jsr.io/@hugoalh/fs)
[](https://www.npmjs.com/package/@hugoalh/fs)An ES (JavaScript & TypeScript) module for enhanced file system operation.
## ๐ฐ Begin
### ๐ฏ Targets
| | **Remote** | **JSR** | **NPM** |
|:--|:--|:--|:--|
| **[Bun](https://bun.sh/)** >= v1.1.0 | โ | โ | โ๏ธ |
| **[Deno](https://deno.land/)** >= v2.1.0 | โ๏ธ | โ๏ธ | โ๏ธ |
| **[NodeJS](https://nodejs.org/)** >= v22.11.0 | โ | โ | โ๏ธ |> [!NOTE]
> - It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.### #๏ธโฃ Resources Identifier
- **Remote - GitHub Raw:**
```
https://raw.githubusercontent.com/hugoalh/fs-es/{Tag}/mod.ts
```
- **JSR:**
```
[jsr:]@hugoalh/fs[@{Tag}]
```
- **NPM:**
```
[npm:]@hugoalh/fs[@{Tag}]
```> [!NOTE]
> - For usage of remote resources, it is recommended to import the entire module with the main path `mod.ts`, however it is also able to import part of the module with sub path if available, but do not import if:
>
> - it's path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
> - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
> - it's symbol has an underscore prefix (e.g.: `_bar`, `_foo`).
>
> These elements are not considered part of the public API, thus no stability is guaranteed for them.
> - For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub entrypoints.
> - It is recommended to use this module with tag for immutability.### ๐ก๏ธ Runtime Permissions
- File System - Read \[Deno: `read`; NodeJS ๐งช: `fs-read`\]
- *Resources*
- File System - Write \[Deno: `write`; NodeJS ๐งช: `fs-write`\]
- *Resources* (Optional)
- Subprocesses \[Deno: `run`\]
- `pwsh` (Optional)
- System Information \[Deno: `sys`\]
- `gid` (Optional, POSIX/UNIX Platforms)
- `uid` (Optional, POSIX/UNIX Platforms)## ๐งฉ APIs
- ```ts
function compareDirectories(oldPath: string | URL, newPath: string | URL): Promise;
```
- ```ts
function emptyDir(path: string | URL): Promise;
```
- ```ts
function ensureDir(path: string | URL): Promise;
```
- ```ts
function ensureFile(path: string | URL): Promise;
```
- ```ts
function ensureLink(src: string | URL, dest: string | URL): Promise;
```
- ```ts
function ensureSymlink(src: string | URL, dest: string | URL): Promise;
```
- ```ts
function exist(path: string | URL, options?: FSExistOptions): Promise;
```
- ```ts
function getDriveInfo(options?: FSGetDriveInfoOptions): Promise;
```
- ```ts
function getHash(path: string | URL, options?: FSGetHashOptions): Promise;
```
- ```ts
function getSize(path: string | URL): Promise;
```
- ```ts
function walk(root: string | URL, options?: FSWalkOptions & { extraInfo?: false; }): Promise>;
function walk(root: string | URL, options: FSWalkOptions & { extraInfo: true; }): Promise>;
```> [!NOTE]
> - For the full or prettier documentation, can visit via:
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/documentation_generator/)
> - [JSR](https://jsr.io/@hugoalh/fs)## โ๏ธ Examples
- ```ts
await emptyDir("./foo");
```
- ```ts
await ensureDir("./foo");
```
- ```ts
await ensureFile("./foo.dat");
```
- ```ts
await ensureLink("./path/to/source.dat", "./path/to/link.dat");
```
- ```ts
await ensureSymlink("./path/to/source.dat", "./path/to/link.dat");
```
- ```ts
await exist("./exist");
//=> true
```
- ```ts
await getHash(Deno.cwd());
//=> "87C77A27D4779AB3078B941B86FF07CA0929A4E9D9581F6BAE380F3194287E3ADF4863355711426E79D4B673B71E9DE5F2A3E3F9D12C93FF2BDBD376DE93065D"
```