Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/prepare-write
Prepare for writing a file to the given path – create ancestor directories and verify no directory exists in the path
https://github.com/shinnn/prepare-write
check filesystem javascript mkdir mkdirp nodejs prepare promise write
Last synced: 26 days ago
JSON representation
Prepare for writing a file to the given path – create ancestor directories and verify no directory exists in the path
- Host: GitHub
- URL: https://github.com/shinnn/prepare-write
- Owner: shinnn
- License: isc
- Created: 2017-05-25T10:32:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-26T19:15:38.000Z (over 5 years ago)
- Last Synced: 2024-09-16T04:25:56.557Z (about 2 months ago)
- Topics: check, filesystem, javascript, mkdir, mkdirp, nodejs, prepare, promise, write
- Language: JavaScript
- Size: 146 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prepare-write
[![npm version](https://img.shields.io/npm/v/prepare-write.svg)](https://www.npmjs.com/package/prepare-write)
[![Build Status](https://travis-ci.com/shinnn/prepare-write.svg?branch=master)](https://travis-ci.com/shinnn/prepare-write)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/prepare-write.svg)](https://coveralls.io/github/shinnn/prepare-write?branch=master)Prepare for writing a file to the given path – create ancestor directories and verify no directory exists in the path
```javascript
const {existsSync} = require('fs');
const prepareWrite = require('prepare-write');(async () => {
existsSync('dir0'); //=> falseawait prepareWrite('dir0/dir1/dir2/file.txt');
existsSync('dir0'); //=> true
existsSync('dir0/dir1'); //=> true
existsSync('dir0/dir1/dir2'); //=> true
existsSync('dir0/dir1dir2/file.txt'); //=> false
})();
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install prepare-write
```## API
```javascript
const prepareWrite = require('prepare-write');
```### prepareWrite(*path*)
*path*: `string` (directory path)
Return: `Promise`It ensures you can soon write a file to the given path by:
1. Creating ancestor directories if they don't exist
2. Checking if no directory already exists in the path```javascript
(async () => {
// a directory /foo doesn't existawait prepareWrite('/foo/bar/baz');
// a directory /foo/bar now exists
await prepareWrite('/foo/bar');
// Error: Tried to create a file as /foo/bar, but a directory with the same name already exists.
})();
```## License
[ISC License](./LICENSE) © 2017 - 2019 Watanabe Shinnosuke