Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)