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

safe-wipe

v0.2.5

Published

> Safely wipe a folder.

Downloads

43,986

Readme

safe-wipe npm version

Safely wipe a folder.

Overview

This is the perfect library for when you want to wipe a folder with user's confirmation.

  • If the folder is empty (or contains only useless files like .DS_Store or Thumbs.db as configured with config.ignore), the folder will be removed without asking anything.
  • If config.force is set to true, wipe anyway.
  • If the session is not interactive, raise an exception.
  • Prompt the user for confirmation, and raise an exception if the answer is negative.

You can configure the following variables:

| Name | Description | Default | |-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------| | stdin, stdout, stderr | Streams to use for I/O. | process.* streams | | ignore | An array of files to ignore when checking if a directory is empty. | .DS_Store and Thumbs.db | | parent | A (supposed) parent directory of the directory to wipe. If the parent is contained in the directory to wipe, the process will be aborted in all cases. | | | interactive | Whether the session is interactive. | true | | force | Whether to force the wipe if the folder is not empty. | false | | silent | The error messages are not printed if this is set to true. | false | | messages | An object of messages for user prompt and error display. | |

The messages are:

| Name | Description | |-------------|-------------------------------------------------------------------------------------| | contained | Error message when the folder to wipe is contained in the configured parent folder. | | confirm | Text to prompt the user to confirm the (not empty) directory wipe. | | abort | Error message when the user refuses to wipe the folder. |

The function is asynchronous and return a promise. Nothing is passed to the success function, but you'll get an Error instance in the error function. It can have the following code property:

| Code | Description | |-------------|--------------------------------------------------------------------------------------------------------| | CONTAINED | Refused to remove the directory since it's containing the supposed parent. | | ABORT | The user aborted the operation (or we're not in an interactive session and config.force is false). |

Examples

Simple usage

var safeWipe = require('safe-wipe');

safeWipe('directory', {
  parent: __dirname,
  messages: {
    abort: 'Nope.',
  },
}).then(function () {
  console.log('Successfully removed!');
}, function (e) {
  console.error(e.message, e.code);
});

Bind a config object

var mySafeWipe = safeWipe({
  interactive: false,
});

mySafeWipe('some-directory').then(function () {
  // ...
});

mySafeWipe('another-directory', {
  force: true,
});