Skip to content

refactored #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = false
43 changes: 19 additions & 24 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@
],

"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
"es2021": true,
"node": true
},

"parserOptions":{
"ecmaVersion": 9,
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},

"globals": {
"document": false,
"navigator": false,
"window": false
"ecmaVersion": 12
},

"rules": {
"accessor-pairs": 2,
"arrow-parens": [2, "as-needed"],
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
Expand All @@ -39,7 +28,7 @@
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"handle-callback-err": [2, "^(err|error)$"],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
Expand Down Expand Up @@ -68,18 +57,20 @@
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-implicit-coercion": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-spaces": 0,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
Expand All @@ -89,7 +80,7 @@
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
Expand All @@ -100,28 +91,32 @@
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-useless-call": 2,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"object-curly-spacing": ["error", "always", { "objectsInObjects": true }],
"one-var": [2, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"prefer-const": [2, { "destructuring": "all", "ignoreReadBeforeAssign": false }],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-before-function-paren": [2, { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"strict": 2,
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tests
on: [push, pull_request]

jobs:
test:
name: Node.js ${{ matrix.node-version }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [12, 14, 16]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

23 changes: 7 additions & 16 deletions .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

```js
const deleteEmpty = require('{%= name %}');
import deleteEmpty from 'delete-empty';
```

## API

Given the following directory structure, the **highlighted directories** would be deleted.
Given the following directory structure, the **marked directories** would be deleted.

```diff
foo/
Expand All @@ -23,36 +24,26 @@ foo/

### async-await (promise)

If no callback is passed, a promise is returned. Returns the array of deleted directories.
Returns a promise that returns an object with the array of deleted directories.

```js
(async () => {
let deleted = await deleteEmpty('foo');
const { deleted } = await deleteEmpty('foo');
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
})();

// or
deleteEmpty('foo/')
.then(deleted => console.log(deleted)) //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
.then(({ deleted }) => console.log(deleted)) //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
.catch(console.error);
```

### async callback

Returns the array of deleted directories in the callback.

```js
deleteEmpty('foo/', (err, deleted) => {
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
});
```

### sync

Returns the array of deleted directories.
Returns an object with the array of deleted directories.

```js
console.log(deleteEmpty.sync('foo/')); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
console.log(deleteEmpty.sync('foo/')); //=> { deleted: ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/'] }
```


Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-present, Jon Schlinkert.
Copyright (c) Jon Schlinkert <[email protected]> (jonschlinkert.dev)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# delete-empty [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/delete-empty.svg?style=flat)](https://www.npmjs.com/package/delete-empty) [![NPM monthly downloads](https://img.shields.io/npm/dm/delete-empty.svg?style=flat)](https://npmjs.org/package/delete-empty) [![NPM total downloads](https://img.shields.io/npm/dt/delete-empty.svg?style=flat)](https://npmjs.org/package/delete-empty) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/delete-empty.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/delete-empty)
# delete-empty [![NPM version](https://img.shields.io/npm/v/delete-empty.svg?style=flat)](https://www.npmjs.com/package/delete-empty) [![NPM monthly downloads](https://img.shields.io/npm/dm/delete-empty.svg?style=flat)](https://npmjs.org/package/delete-empty) [![NPM total downloads](https://img.shields.io/npm/dt/delete-empty.svg?style=flat)](https://npmjs.org/package/delete-empty) [![Tests](https://github.com/jonschlinkert/delete-empty/actions/workflows/test.yml/badge.svg)](https://github.com/jonschlinkert/delete-empty/actions/workflows/test.yml)

> Recursively delete all empty folders in a directory and child directories.

Expand All @@ -8,7 +8,6 @@ Please consider following this project's author, [Jon Schlinkert](https://github
- [Usage](#usage)
- [API](#api)
* [async-await (promise)](#async-await-promise)
* [async callback](#async-callback)
* [sync](#sync)
- [CLI](#cli)
- [About](#about)
Expand All @@ -17,7 +16,7 @@ _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](

## Install

Install with [npm](https://www.npmjs.com/):
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=10):

```sh
$ npm install --save delete-empty
Expand All @@ -27,57 +26,48 @@ $ npm install --save delete-empty

```js
const deleteEmpty = require('delete-empty');
import deleteEmpty from 'delete-empty';
```

## API

Given the following directory structure, the **highlighted directories** would be deleted.
Given the following directory structure, the **marked directories** would be deleted.

```diff
foo/
└─┬ a/
- ├── aa/
- ├── aa/
├── bb/
│ └─┬ bbb/
│ │ ├── one.txt
│ │ └── two.txt
- ├── cc/
- ├ b/
- └ c/
- ├── cc/
- ├ b/
- └ c/
```

### async-await (promise)

If no callback is passed, a promise is returned. Returns the array of deleted directories.
Returns a promise that returns an object with the array of deleted directories.

```js
(async () => {
let deleted = await deleteEmpty('foo');
const { deleted } = await deleteEmpty('foo');
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
})();

// or
deleteEmpty('foo/')
.then(deleted => console.log(deleted)) //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
.then(({ deleted }) => console.log(deleted)) //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
.catch(console.error);
```

### async callback

Returns the array of deleted directories in the callback.

```js
deleteEmpty('foo/', (err, deleted) => {
console.log(deleted); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
});
```

### sync

Returns the array of deleted directories.
Returns an object with the array of deleted directories.

```js
console.log(deleteEmpty.sync('foo/')); //=> ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/']
console.log(deleteEmpty.sync('foo/')); //=> { deleted: ['foo/aa/', 'foo/a/cc/', 'foo/b/', 'foo/c/'] }
```

## CLI
Expand Down Expand Up @@ -144,16 +134,17 @@ You might also be interested in these projects:

* [copy](https://www.npmjs.com/package/copy): Copy files or directories using globs. | [homepage](https://github.com/jonschlinkert/copy "Copy files or directories using globs.")
* [delete](https://www.npmjs.com/package/delete): Delete files and folders and any intermediate directories if they exist (sync and async). | [homepage](https://github.com/jonschlinkert/delete "Delete files and folders and any intermediate directories if they exist (sync and async).")
* [fs-utils](https://www.npmjs.com/package/fs-utils): fs extras and utilities to extend the node.js file system module. Used in Assemble and… [more](https://github.com/assemble/fs-utils) | [homepage](https://github.com/assemble/fs-utils "fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.")
* [matched](https://www.npmjs.com/package/matched): Adds array support to node-glob, sync and async. Also supports tilde expansion (user home) and… [more](https://github.com/jonschlinkert/matched) | [homepage](https://github.com/jonschlinkert/matched "Adds array support to node-glob, sync and async. Also supports tilde expansion (user home) and resolving to global npm modules.")
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A replacement and faster alternative to minimatch and multimatch.")

### Contributors

| **Commits** | **Contributor** |
| --- | --- |
| 31 | [jonschlinkert](https://github.com/jonschlinkert) |
| 35 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [treble-snake](https://github.com/treble-snake) |
| 1 | [doowb](https://github.com/doowb) |
| 1 | [Ronald-Baars](https://github.com/Ronald-Baars) |
| 1 | [svenschoenung](https://github.com/svenschoenung) |
| 1 | [vpalmisano](https://github.com/vpalmisano) |

Expand All @@ -167,9 +158,9 @@ You might also be interested in these projects:

### License

Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2021, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 02, 2019._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 02, 2019._
Loading