createFile
Description
Creates a file based on the fileLocationAndName parameter. It resolves the fileLocationAndName string if sucessful or rejects CreatingFileError.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function createFile(fileLocationAndName, content = ''[, tuple]): Promise<string || Array> |
Examples
1
2
3
4
import {createFile} from 'puddy-m/lib/fileFunctions'
createFile('path/to/file.ext')
.then(filePath=>console.log(filePath)) // prints 'path/to/file.ext'
1
2
3
4
import {createFile} from 'puddy-m/lib/fileFunctions'
createFile(true)
.catch(e=>e) // rejects an instance of CreatingFileError.
1
2
3
4
5
6
// Using it with tuple parameter
import {createFile} from 'puddy-m/lib/fileFunctions'
createFile('path/to/file1.ext', [])
.then(tuple=>validateString('World', tuple))
.then(([first, second])=> first + second) // 'path/to/file1.txtWorld'