npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teasource/est-fuga-animi

v1.0.0

Published

The native fs, fs/promises and fs-extra package functions wrapped with try/catch.

Downloads

600

Readme

@teasource/est-fuga-animi

npm version license

Table of contents

Description

When using native fs or fs-extra functions, you often care more about the operation's success than the specifics of any error.

This package wraps the native fs, fs/promises and fs-extra package of functions so that you don't need to use try/catch to prevent errors from stopping your program.

The original return void function is wrapped so that it will return true if it succeeds and false if it fails.

The rest of the functions return the original data if they succeed, or undefined if they fail.

Prerequisites

This package requires Node v16 or above.

However, please note that some functions are affected by the Node version.

To check your installed version, run the following command.

$ node -v
v20.5.1

Installation

Before installing, please read the prerequisites.

To install and use this package, run:

$ npm i @teasource/est-fuga-animi     # Npm
$ pnpm add @teasource/est-fuga-animi  # Pnpm
$ yarn add @teasource/est-fuga-animi  # Yarn

For full type hinting and checking in a development environment, install the @types/fs-extra package:

$ npm i -D @types/fs-extra    # Npm
$ pnpm add -D @types/fs-extra # Pnpm
$ yarn add -D @types/fs-extra # Yarn

Examples

You can simplify your code using this package as follows:

readJson

Original approach:

import fse from 'fs-extra';

async function rJ(path: string) {
  try {
    return await fse.readJson(path);
  } catch (error) { }
}

const result = await rJ(path);
// Any json data - successfully read
// undefined - an error occurred

Using this package:

import kFse from '@teasource/est-fuga-animi';

const result = await kFse.readJson(path);
// Any json data - successfully read
// undefined - an error occurred

rename

Original approach:

import fse from 'fs-extra';

async function r(o: string, n: string) {
  try {
    await fse.rename(o, n);
    return true;
  } catch (error) { }
  return false;
}

const result = await r(oldPath, newPath);
// true - successfully renamed
// false - an error occurred

Using this package:

import kFse from '@teasource/est-fuga-animi';

const result = await kFse.rename(oldPath, newPath);
// true - successfully renamed
// false - an error occurred

Functions

You can use most of the functions exported from the native fs, fs/promises and fs-extra package.

However, all functions that do not end with "Sync" return a promise and do not accept callback arguments.

This is because with callback, errors are passed into the callback, which makes no sense when using wrappers.

If you need to use callbacks, import them in from the original package.

Additional

  • getFileSize - Use stat to get file size.
  • getFileSizeSync - Use statSync to get file size.

Not exported

Deprecated functions will not be exported.

These functions do not need to be wrapped and have similar names but different functions. To avoid confusion, please import them yourself from fs or fs/promises:

  • fs.watch
  • fs.watchFile
  • fs.promise.watch

Overloads types

The overloads type of these functions have been broken or merged.

Please note that the current type hints may not be completely accurate. We will correct this in a future update.

  • fstat
  • fstatSync
  • lstat
  • lstatSync
  • mkdir
  • mkdirSync
  • mkdtemp
  • mkdtempSync
  • read
  • readFile
  • readFileSync
  • readSync
  • readdir
  • readdirSync
  • readlink
  • readlinkSync
  • realpath
  • realpathSync
  • stat
  • statSync
  • statfs
  • statfsSync
  • write
  • writeSync

Will be affected by the node version

fs.cpSync and fsp.cp are available starting from Node v16.7.0.

fs.statfsSync and fsp.statfs are available starting from Node v18.15.0 up to but not including v19, as well as v19.6.0 and later.

Avoid using these functions if your Node version falls outside the specified ranges.

Versioning

We adhere to Semantic Versioning for this project.

For the versions available, see the versions on npm.

Authors

License

MIT License © kiki-kanri