Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

safe-wipe

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-wipe

> Safely wipe a folder.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
decreased by-51.85%
Maintainers
1
Weekly downloads
 
Created
Source

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:

NameDescription
stdin, stdout, stderrStreams to use for I/O. Defaults to the process streams.
ignoreAn array of files to ignore when checking if a directory is empty. Defaults to .DS_Store and Thumbs.db.
parentA (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.
interactiveWhether the session is interactive. true by default.
forceWhether to force the wipe if the folder is not empty. false by default.
silentThe error messages are not printed if this is et to true. false by default.
messagesAn object of messages for user prompt and error display.

The messages are:

NameDescription
containedError message when the folder to wipe is contained in the configured parent folder.
confirmText to prompt the user to confirm the (not empty) directory wipe.
abortError 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:

CodeDescription
CONTAINEDRefused to remove the directory since it's containing the supposed parent.
ABORTThe 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,
});

FAQs

Package last updated on 07 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc