make-empty-dir
Ensures that a directory is empty
Last updated 5 years ago by zkochan .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install make-empty-dir 
SYNC missed versions from official npm registry.

make-empty-dir

Ensures that a directory is empty

npm version

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.

It works faster than emptyDir() of fs-extra because the contents of the directory are not read before the creation of the directory.

Installation

<npm|yarn|pnpm> add make-empty-dir

Usage

'use strict'
const makeEmptyDir = require('make-empty-dir')

await makeEmptyDir('dir-name')

// or create the parent dir as well
await makeEmptyDir('dir/subdir', { recursive: true })

API

makeEmptyDir(dir: string, [opts]): Promise<'created' | 'emptied'>

Arguments:

  • dir - Path - the path of the directory.
  • opts.recursive - Boolean - Optional. If true, parent directories will be created.

Returns:

A string is returned.

  • 'created' - if there was no directory
  • 'emptied' - if there was a directory and the its contents were removed.

License

MIT © Zoltan Kochan

Current Tags

  • 2.1.0                                ...           latest (3 years ago)
  • 1.1.0                                ...           next (5 years ago)

4 Versions

  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |