fs-extender
Version:
Extras suite for node fs module
134 lines (133 loc) • 4.38 kB
TypeScript
/// <reference types="node" />
import * as fs from "../patch";
export declare type MkdirpOptions = {
/**
* A file mode. If a string is passed, it is parsed as an octal integer. If not specified
* @default 0o777
*/
mode?: fs.Mode | undefined;
};
/**
* Asynchronously creates a directory.
*
* The callback is given a possible exception and, the last directory paths created,
* `(err[, path])`.`path` can still be `undefined`, if no directory was
* created.
*
* The optional `options` argument can be an integer specifying `mode` (permission
* and sticky bits), or an object with a `mode` property and a optional `fs` property.
*
* ```js
* import * as fs from 'fs-extender';
*
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
* fs.mkdirp('/tmp/a/apple', (err) => {
* if (err) throw err;
* });
* ```
*
* ```js
* fs.mkdirp('/path/{to1,to2}/{dir1,dir2}',(err)=>{
* if(err) throw(err);
* });
* ```
* will create the directories:
* /path/to1/dir1
* /path/to1/dir2
* /path/to2/dir1
* /path/to2/dir2
*
* On Windows, using `fs.mkdirp()` on the root directory even with recursion will
* result in an error:
*
* ```js
* import { mkdirp } from 'fs-extender';
*
* fs.mkdir('/', (err) => {
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
* });
* ```
*
*
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
*/
export declare function mkdirp(path: fs.PathLike | fs.PathLike[], options: fs.Mode | MkdirpOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path?: fs.PathLike | fs.PathLike[]) => void): void;
/**
* Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
export declare function mkdirp(path: fs.PathLike | fs.PathLike[], callback: (err: NodeJS.ErrnoException | null, path?: fs.PathLike | fs.PathLike[]) => void): void;
export declare namespace promises {
/**
* Asynchronously creates a directory.
*
* Will return all the paths created
*
* The optional `options` argument can be an integer specifying `mode` (permission
* and sticky bits), or an object with a `mode` property and a optional `fs` property.
*
* ```js
* import * as fs from 'fs-extender';
*
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
* fs.promises.mkdirp('/tmp/a/apple');
* ```
*
* ```js
* fs.promises.mkdirp('/path/{to1,to2}/{dir1,dir2}');
* ```
* will create the directories:
* /path/to1/dir1
* /path/to1/dir2
* /path/to2/dir1
* /path/to2/dir2
*
* On Windows, using `fs.mkdirp()` on the root directory even with recursion will
* result in an error:
*
* ```js
* fs.promises.mkdir('/');
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
* ```
*
*
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
*/
function mkdirp(path: fs.PathLike | fs.PathLike[], options?: MkdirpOptions | fs.Mode | null | undefined): Promise<fs.PathLike | fs.PathLike[]>;
}
/**
* Synchronously creates a directory.
*
* Will return all the paths created
*
* The optional `options` argument can be an integer specifying `mode` (permission
* and sticky bits), or an object with a `mode` property and a optional `fs` property.
*
* ```js
* import * as fs from 'fs-extender';
*
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
* fs.mkdirpSync('/tmp/a/apple');
* ```
*
* ```js
* fs.mkdirpSync('/path/{to1,to2}/{dir1,dir2}');
* ```
* will create the directories:
* /path/to1/dir1
* /path/to1/dir2
* /path/to2/dir1
* /path/to2/dir2
*
* On Windows, using `fs.mkdirp()` on the root directory even with recursion will
* result in an error:
*
* ```js
* fs.mkdirpSync('/');
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
* ```
*
*
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
*/
export declare function mkdirpSync(path: fs.PathLike | fs.PathLike[], options?: MkdirpOptions | fs.Mode | null | undefined): fs.PathLike | fs.PathLike[];