Giter Club home page Giter Club logo

node-fs's Introduction

About

File system manipulation without headache.

๐Ÿ“ฆ Scoped @xan105 packages are for my own personal use but feel free to use them.

Install / Runtime

๐Ÿ“ฆ Package manager

npm install @xan105/fs
Compatibility
  • Node โœ”๏ธ

API

โš ๏ธ This module is only available as an ECMAScript module (ESM) starting with version 2.0.0.
Previous version(s) are CommonJS (CJS) with an ESM wrapper.

Named export

readFile(filePath: string, options?: object | string): Promise<string | Buffer>

Auto remove utf bom (string only).

readJSON(filePath: string): Promise<string>

Parse JSON and remove utf bom if any.

writeFile(filePath: string, data: unknown, options?: object | string): Promise<string>

Create target parent dir if doesn't exist.

โš™๏ธ Options:

  • bom (default: false)

    add utf bom (string only).

writeJSON(filePath: string, data: unknown, option?: object): Promise<string>

Write JSON to file and return filePath for convenience.

โš™๏ธ Options:

  • pretty (default: true)

    insert white space into the output JSON string for readability purposes.

  • bigint2str (default: true)

    convert bigint to string.

copyFile(src: string, dest: string, flags: number): Promise<void>

Create target parent dir if doesn't exist.

mv(oldPath: string, newPath: string): Promise<string>

Create target parent dir if doesn't exist.
Move on same drive otherwise copy to target and delete origin.

exists(path: string): Promise<boolean>

existsAndIsOlderOrYoungerThan(path: string, option?: object): Promise<boolean>

โš™๏ธ Options:

  • time: amount of time unit (default 1)
  • timeUnit: s|m|h|d|w|M|Y (default day)
  • younger: compare mode younger than (true) or older than (false/default)

existsAndIsOlderThan(path: string, option?: object): Promise<boolean>

โš™๏ธ Options:

  • time: amount of time unit (default 1)
  • timeUnit: s|m|h|d|w|M|Y (default day)

existsAndIsYoungerThan(path: string, option?: object): Promise<boolean>

โš™๏ธ Options:

  • time: amount of time unit (default 1)
  • timeUnit: s|m|h|d|w|M|Y (default day))

stat(path: string): Promise<object>

alias stats(path: string): Promise<object>

On error returns an empty object.

mkdir(dirPath: string): Promise<string | undefined>

Recursive.

rm(path: string): Promise<void>

alias unlink(path: string): Promise<void>
alias deleteFile(path: string): Promise<void>
alias rmdir(path: string): Promise<void>

Nuke the target ๐Ÿš€๐Ÿ’ฅ.

hashFile(filePath: string, algo?: string): Promise<string>

Hash specified file (use stream). algo defaults to "sha256".

touch(filePath: string): Promise<void>

Create, change and modify timestamps of a file.

ls(dirPath: string, option?: object): Promise<string[] | object[]>

List directory contents.

โš™๏ธ Options:

  • verbose: boolean (false)

  • recursive: boolean (false)

  • absolute: boolean false)

    Return absolute or relative path

  • follow: boolean (false)

    Whether or not to follow symlink

  • normalize: boolean (false)

    Whether or not to normalize path seperator to "/"

  • ignore:

    • dir: boolean (false)
    • file: boolean (false)
    • symlink: boolean (false)
    • socket: boolean (false)
    • dot: boolean (true)
  • filter: string[] (empty)

  • whitelist: boolean (false)

    Turn the filter list into a whitelist

  • ext: string[] (empty)

    Allowed file extension

  • pattern: RegExp (none)

Return value:

If verbose is true returns a detailed list as

[
  {
    name: string, //file name
    path: string, //path of file
    link?: string | undefined //symlink target
  },
  ...
]

Otherwise string[] (path of file)

compareFile(a: string, b:string, algo?: string): Promise<boolean>

Compare files to determine if they are identical.

Comparison is by default done with "sha1" algo (cf: hashFile()) unless files size don't match.

path

resolve(path: string): string

Resolve fileURL and path if necessary.

dirname(path: string): string

Handles path and fileURL.

normalize(path: string, win32?: boolean): string

replace every \\ with /

When win32 is set to true (default is false)
replace every / with \\

isRoot(path: string): boolean

win32

sanitizeFileName(string: string): string

setHidden(path: string): Promise<void>

removeHidden(path: string): Promise<void>

setReadOnly(path: string): Promise<void>

removeReadOnly(path: string): Promise<void>

isHidden(path: string): Promise<boolean>

isReadOnly(path: string): Promise<boolean>

isHiddenAndReadOnly(path: string): Promise<boolean>

node-fs's People

Contributors

xan105 avatar

Stargazers

 avatar

Watchers

 avatar

node-fs's Issues

AW issue (plz don't delete this)

As it says in the title, I have an issue with Achievement watcher and this is the only way I know to contact you. So here's a long story of what happened- I downloaded Gotham Knight's fitgirl repack and figured it would find it automatically seeing as the it's appid is in a folder that AW is supposed to check, but it didn't find it. What's weirder than that and the big issue I have is that Achievement watcher takes like a minute and a half to load which is very weird considering it took like 10 seconds before. That's not the only issue though, I installed FitGirl's Batman arkham asylum and applied the Goldberg crack to it (I know it worked because as soon as I started the game, the app id of Baa showed up in the goldberg folder) and it didn't get detected by AW neither!. At this moment I realized there is probably an issue that causes all of this so I uninstalled AW, reinstalled it, and it didn't fix the issue as well!. And now because it can't detect games, it doesn't detect any of the games that were there before. I know it's long but if you could help with that, I would appreciate it alot!.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.