diff --git a/README.md b/README.md index e1f57ad8d..546d75659 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,7 @@ _30s.average(1, 2, 3); * [`atob`](#atob) * [`btoa`](#btoa) * [`colorize`](#colorize) +* [`createDirIfNotExists`](#createdirifnotexists) * [`hasFlags`](#hasflags) * [`hashNode`](#hashnode) * [`isDuplexStream`](#isduplexstream) @@ -2316,9 +2317,9 @@ The `func` is invoked with three arguments (`value, index, array`). const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; ``` @@ -6318,6 +6319,28 @@ console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); //
[⬆ Back to top](#contents) +### createDirIfNotExists + +Creates a directory, if it does not exist. + +Use `fs.existsSync()` to check if the directory exists, `fs.mkdirSync()` to create it. + +```js +const fs = require('fs'); +const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined); +``` + +
+Examples + +```js +createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist +``` + +
+ +
[⬆ Back to top](#contents) + ### hasFlags Check if the current process's arguments contain the specified flags. diff --git a/docs/about.html b/docs/about.html index 4cd8c918e..7a6c0bcb5 100644 --- a/docs/about.html +++ b/docs/about.html @@ -362,6 +362,7 @@