Create all directories on the way to the path.
npm install @wrote/ensure-path
@wrote/ensure-path Creates All Directories On The Way To The Path.
``sh`
yarn add @wrote/ensure-path
- Table Of Contents
- API
* async ensurePath(path: string): string
* ensurePathSync(path: string): string
- Copyright
The package is available by importing its default and named function:
`js`
import ensurePath, { ensurePathSync } from '@wrote/ensure-path'
Makes sure that the path can be written to by recursively creating all necessary directories. Returns the same path as passed to the function.
`js
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
})()
`
Same as ensurePath, but performed synchronously.
`js
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
``
![]() | © Art Deco for Wrote 2019 | alt="Tech Nation Visa"> | Tech Nation Visa Sucks |
|---|