Skip to content

keift/trufs

Repository files navigation




Contents

About

Trusty file methods.

Features

Installation

You can install it as follows.

// NPM
npm install trufs

// PNPM
pnpm install trufs

// Yarn
yarn add trufs

// Bun
bun add trufs

// Deno
deno install npm:trufs

Documentation

Tree

Briefly as follows.

Trufs

├── fs
   
   ├── readFile(filepath, options?)
   ├── readFileSync(filepath, options?)
   ├── writeFile(filepath, data, options?)
   └── writeFileSync(filepath, data, options?)

└── type Types
    
    ├── Fs
    ├── ReadOptions
    └── WriteOptions

Import

It is enough to change the fs to trufs.

TypeScript

- import fs from "fs";
+ import { fs, type Types as TrufsTypes } from "trufs";

JavaScript

- import fs from "fs";
+ import { fs } from "trufs";

Methods

fs.readFile(filepath, options?)

Read file asynchronous.

Parameter Default Description
filepath String
File path to read.
options ReadOptionsDefault ReadOptions (optional)
Read options.

returns Promise<String | Buffer>

Example:

await fs.readFile("./config.json");

fs.readFileSync(filepath, options?)

Read file synchronous.

Parameter Default Description
filepath String
File path to read.
options ReadOptionsDefault ReadOptions (optional)
Read options.

returns String | Buffer

Example:

fs.readFileSync("./config.json");

fs.writeFile(filepath, data, options?)

Write file asynchronous.

Parameter Default Description
filepath String
File path to write.
data String | Buffer
Data to be written.
options WriteOptionsDefault WriteOptions (optional)
Write options.

returns Promise<Void>

Example:

await fs.writeFile("./config.json", JSON.stringify({}));

fs.writeFileSync(filepath, data, options?)

Write file synchronous.

Parameter Default Description
filepath String
File path to write.
data String | Buffer
Data to be written.
options WriteOptionsDefault WriteOptions (optional)
Write options.

returns Void

Example:

fs.writeFileSync("./config.json", JSON.stringify({}));

Types

Type
Fs
ReadOptions
WriteOptions

Links

License

MIT License

Copyright (c) 2025 Keift

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.