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

premove

v4.0.0

Published

A tiny (208B to 260B) utility to remove items recursively

Downloads

41,646

Readme

premove CI codecov

A tiny (208B to 260B) utility to remove items recursively

This is a Promise-based, cross-platform utility that recursively removes files and directories. It's effectively a programmatic rm -rf for Node.js. There's also a CLI for easy, cross-platform usage.

Notice: Node v12.10.0 includes the recursive option for fs.rmdir and fs.rmdirSync.

Install

$ npm install --save premove

Modes

There are two "versions" of premove available:

"async"

Node.js: >= 8.x Size (gzip): 249 bytes Availability: CommonJS, ES Module

This is the primary/default mode. It makes use of async/await and util.promisify.

"sync"

Node.js: >= 6.x Size (gzip): 202 bytes Availability: CommonJS, ES Module

This is the opt-in mode, ideal for scenarios where async usage cannot be supported.In order to use it, simply make the following changes:

-import { premove } from 'premove';
+import { premove } from 'premove/sync';

Usage

import { resolve } from 'path';
import { premove } from 'premove';

// Async/await
try {
  await premove('./foobar');
} catch (err) {
  //
}

// Promise
premove('./foobar').then(val => {
  console.log(typeof val);
  //=> boolean
}).catch(err => {
  //
});

// Using `cwd` option
const dir = resolve('./foo/bar');
await premove('hello.txt', { cwd: dir });

CLI

A premove binary is available as of v3.0.0. It accepts an optional --cwd value and a list of paths to delete.

Important: By default premove refuses to delete:

  • the os.homedir
  • the system root (/, C:\\, etc)
  • items not contained by --cwd path
# remove "foo" and "bar" via `npx`
$ npx premove foo bar

# install globally, use whenever
$ npm install premove -g
$ premove foo bar

API

premove(str, opts={})

Returns: Promise<boolean>

Returns a Promise that resolves with a boolean value. If true, indicates that the str input did exist and was successfully removed. A false value indicates that the str input did not exist, meaning nothing needed to be removed.

Important:The sync and async versions share the same API.The only difference is that sync is not Promise-based.

str

Type: String

The filepath to remove – may be a file or a directory. An initial existence check is made for this filepath.

Important: This value is resolved to a full path. Please be aware of how and from where the Node.js file system is resolving your path!

options.cwd

Type: String Default: .

The directory to resolve your str from. Defaults to the process.cwd() – aka, the directory that your command is run within.

Related

  • totalist - A tiny (195B to 224B) utility to recursively list all (total) files in a directory
  • mk-dirs - A tiny (381B to 419B) utility to make a directory and its parents, recursively
  • escalade - A tiny (183B) and fast utility to ascend parent directories

License

MIT © Luke Edwards