@wrote/ensure-path

1.1.0 • Public • Published

@wrote/ensure-path

npm version

@wrote/ensure-path Creates All Directories On The Way To The Path.

yarn add @wrote/ensure-path

Table Of Contents

API

The package is available by importing its default and named function:

import ensurePath, { ensurePathSync } from '@wrote/ensure-path'

async ensurePath(
  path: string,
): string

Makes sure that the path can be written to by recursively creating all necessary directories. Returns the same path as passed to the function.

import { resolve } from 'path'
import ensurePath from '@wrote/ensure-path'

(async () => {
  const path = 'example/path/to/temp/file.data'
  await ensurePath(path)
  // path/to/temp is created in the cwd

  const absolutePath = resolve('example/path/to/temp/file.data')
  await ensurePath(absolutePath)
  // $(pwd)/path/to/temp/file.data is created
})()

ensurePathSync(
  path: string,
): string

Same as ensurePath, but performed synchronously.

import { resolve } from 'path'
import { ensurePathSync } from '@wrote/ensure-path'

const path = 'example/path/to/temp/file.data'
ensurePathSync(path)
// path/to/temp is created in the cwd

const absolutePath = resolve('example/path/to/temp/file.data')
ensurePathSync(absolutePath)
// $(pwd)/path/to/temp/file.data is created

Copyright

Art Deco © Art Deco for Wrote 2019 Wrote Tech Nation Visa Tech Nation Visa Sucks

Package Sidebar

Install

npm i @wrote/ensure-path

Weekly Downloads

66

Version

1.1.0

License

MIT

Unpacked Size

11.1 kB

Total Files

9

Last publish

Collaborators

  • zvr