Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@wrote/ensure-path

wrote190MIT1.1.0

Create all directories on the way to the path.

@wrote, path, ensure, traverse, tree, fs, filesystem, directory, dir, folder, file, create, mkdirp, mkdir

readme

@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

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

changelog

3 July 2019

1.1.0

  • [feature] Add the sync version of the function.
  • [build] Compiler with newer ÀLaMode for tidier code.

18 April 2019

1.0.8

  • [deps] Do unlock dependencies.

1.0.7

  • [deps] Update and unlock dependencies.

2 April 2019

1.0.6

  • [dep] Update makepromise.

14 January 2019

1.0.5

  • [deps] Update makepromise.

14 January 2019

1.0.4

  • [package] Add the "module" field.
  • [package] Remove source maps.

15 September 2018

1.0.3

  • [fix] Make sure there is no error when multiple calls are made in parallel.
  • [build] Build with alamode.

4 July 2018

1.0.2

  • [package] Move to wrote github org, and add tags.

3 July 2018

1.0.1

  • [build] Add build files.

1.0.0