Add createDirIfNotExists snippet
This commit is contained in:
14
snippets/createDirIfNotExists.md
Normal file
14
snippets/createDirIfNotExists.md
Normal 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
|
||||||
|
```
|
||||||
@ -38,6 +38,7 @@ copyToClipboard:browser,string,advanced
|
|||||||
countBy:array,object,intermediate
|
countBy:array,object,intermediate
|
||||||
counter:browser,advanced
|
counter:browser,advanced
|
||||||
countOccurrences:array,intermediate
|
countOccurrences:array,intermediate
|
||||||
|
createDirIfNotExists:node,beginner
|
||||||
createElement:browser,utility,beginner
|
createElement:browser,utility,beginner
|
||||||
createEventHub:browser,event,advanced
|
createEventHub:browser,event,advanced
|
||||||
CSVToArray:string,array,utility,intermediate
|
CSVToArray:string,array,utility,intermediate
|
||||||
|
|||||||
3000
test/_30s.js
3000
test/_30s.js
File diff suppressed because it is too large
Load Diff
6
test/createDirIfNotExists.js
Normal file
6
test/createDirIfNotExists.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const expect = require('expect');
|
||||||
|
const {createDirIfNotExists} = require('./_30s.js');
|
||||||
|
|
||||||
|
test('createDirIfNotExists is a Function', () => {
|
||||||
|
expect(createDirIfNotExists).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user