Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iguntur/path-ensure
:rocket: Ensure path exists
https://github.com/iguntur/path-ensure
async await ensure extra fs make-dir micro mkdir mkdirp path sync tiny writefile
Last synced: about 2 months ago
JSON representation
:rocket: Ensure path exists
- Host: GitHub
- URL: https://github.com/iguntur/path-ensure
- Owner: iguntur
- License: mit
- Created: 2017-09-27T21:58:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-03T10:07:35.000Z (about 6 years ago)
- Last Synced: 2024-11-01T22:38:42.858Z (about 2 months ago)
- Topics: async, await, ensure, extra, fs, make-dir, micro, mkdir, mkdirp, path, sync, tiny, writefile
- Language: TypeScript
- Size: 9.77 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# path-ensure
[![Build Status](https://img.shields.io/travis/iguntur/path-ensure.svg?style=flat-square)](https://travis-ci.org/iguntur/path-ensure)
[![node](https://img.shields.io/node/v/path-ensure.svg?style=flat-square)](#)
[![npm](https://img.shields.io/npm/v/path-ensure.svg?style=flat-square)](https://www.npmjs.org/package/path-ensure)> Ensure path exists
---
A simple module to generate the directory before writing the files. See [`fs-extra`](https://github.com/jprichardson/node-fs-extra) for advance.
## Install
```
$ npm install path-ensure
```## API
### pathEnsure([...paths])
- Params:
- paths: `` - A sequence of path segments.
- Return: `>`
- Example:
```js
const fs = require('fs');
const pathEnsure = require('path-ensure');(async () => {
const filepath = await pathEnsure(__dirname, 'some/path/to/create', 'unicorn.txt');
console.log(filepath);
const writeStream = fs.createWriteStream(filepath);
writeStream.write('🦄');
})();
```#### .sync([...paths])
- Params:
- paths: `` - A sequence of path segments.
- Return: ``
- Example:
```js
const fs = require('fs');
const pathEnsure = require('path-ensure');
const writeStream = fs.createWriteStream(
pathEnsure.sync('some/path/to/create', 'unicorn.txt')
);
writeStream.write('🦄');
```## Related
- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed - Think `mkdir -p`
- [fs-extra](https://github.com/jprichardson/node-fs-extra) - Contains methods that aren't included in the vanilla Node.js fs package.## License
MIT © [Guntur Poetra](http://github.com/iguntur)