Add createDirIfNotExists snippet

This commit is contained in:
Angelos Chalaris
2018-12-12 19:25:16 +02:00
parent b1f985e026
commit a2794c150e
4 changed files with 1522 additions and 1499 deletions

View File

@ -0,0 +1,14 @@
### 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;
```
```js
createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist
```

View File

@ -38,6 +38,7 @@ copyToClipboard:browser,string,advanced
countBy:array,object,intermediate
counter:browser,advanced
countOccurrences:array,intermediate
createDirIfNotExists:node,beginner
createElement:browser,utility,beginner
createEventHub:browser,event,advanced
CSVToArray:string,array,utility,intermediate

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
const expect = require('expect');
const {createDirIfNotExists} = require('./_30s.js');
test('createDirIfNotExists is a Function', () => {
expect(createDirIfNotExists).toBeInstanceOf(Function);
});