emp

2.0.0 • Public • Published

emp

Remove all the stuff inside a directory Synchronously or Asynchronously

Installation

npm install emp

Usage

const dirPath = 'path/to/folder'
 
/**
 * Removes everything inside the folder
 */
 
const { empSync, emp } = require('emp')
 
// async version
emp(dirPath).then()
// sync version
empSync(dirPath)
 
/**
 * Check if a dir is empty
 */
 
const { isEmpty, isEmptySync } = require('emp')
 
// async version
isEmpty(dirPath).then(result => {})
// sync version
isEmptySync(dirPath) // true or false

API Documentation

A little bit setup for demonstration:

const { emp, empSync, isEmpty, isEmptySync } = require('emp')
const dirPath = 'path/to/folder'

Empty a directory

// async
emp(path, removeDir).then()
// sync
empSync(path, removeDir)

where

  • path is the location of the directory
  • removeDir is a Boolean flag tells whether you want to remove the current directory or just to empty its content, default to false(not to remove)

If there's nothing at the given path, nothing happens(No error will be thrown)

Check if a directory is empty

// async
isEmpty(path).then(result => {})
// sync
isEmptySync(path) // returns true or false

where

  • path is the location of the directory

Result is either true or false. If the path is not a directory, error will be thrown

Readme

Keywords

Package Sidebar

Install

npm i emp

Weekly Downloads

17

Version

2.0.0

License

ISC

Last publish

Collaborators

  • ohmyxm