make-dir

  • Version 5.0.0
  • Published
  • 9.5 kB
  • No dependencies
  • MIT license

Install

npm i make-dir
yarn add make-dir
pnpm add make-dir

Overview

Make a directory and its parents if needed - Think `mkdir -p`

Index

Functions

function makeDirectory

makeDirectory: (path: string, options?: Options) => Promise<string>;
  • Make a directory and its parents if needed - Think mkdir -p.

    Parameter path

    The directory to create.

    Returns

    The path to the created directory.

    Example 1

    import {makeDirectory} from 'make-dir';
    const path = await makeDirectory('unicorn/rainbow/cake');
    console.log(path);
    //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
    // Multiple directories:
    const paths = await Promise.all([
    makeDirectory('unicorn/rainbow'),
    makeDirectory('foo/bar')
    ]);
    console.log(paths);
    // [
    // '/Users/sindresorhus/fun/unicorn/rainbow',
    // '/Users/sindresorhus/fun/foo/bar'
    // ]

function makeDirectorySync

makeDirectorySync: (path: string, options?: Options) => string;
  • Synchronously make a directory and its parents if needed - Think mkdir -p.

    Parameter path

    The directory to create.

    Returns

    The path to the created directory.

    Example 1

    import {makeDirectorySync} from 'make-dir';
    const path = makeDirectorySync('unicorn/rainbow/cake');
    console.log(path);
    //=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'

Type Aliases

type Options

type Options = {
/**
The directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
@default 0o777
*/
readonly mode?: number;
/**
Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
Default: `import fs from 'node:fs'`
*/
readonly fs?: typeof fs;
};

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (8)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/make-dir.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/make-dir)
    • HTML
      <a href="https://www.jsdocs.io/package/make-dir"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>