A convenient little wrapper around fs and friends. Providing a container class for
file system paths with a friendly API for dealing with different operating systems. Written in TypeScript.
Paths will be automatically split and joined with the correct separator for the current operating system. For the
following examples we will be using POSIX paths and assume a Linux operating system.
// Create directoryconst dir = awaitnewPath('test', '123').mkdir({recursive: true});
const dir = newPath('test', '123').mkdirSync({recursive: true});
// Remove directoryawaitnewPath('test').rm({recursive: true});
newPath('test').rmSync({recursive: true});
// List files in directoryforawait (const file ofnewPath('test').list()) {
console.log(file.toString());
}
// List files recursivelyforawait (const file ofnewPath('test').list({recursive: true})) {
console.log(file.toString());
}
The creation of temporary directories is supported as well. They will be deleted automatically when node exits, but can
also be removed manually with the destroy and destroySync methods. By default, all temporary directories are created
securely, relative to the operating system temp directory with a node- prefix.
// Create a temporary directory (async)const dir = awaitPath.tempDir();
await dir.child('test.txt').touch();
await dir.destroy();
// Create a temporary directory (sync)const dir = Path.tempDirSync();
dir.child('test.txt').touchSync();
dir.destroySync();
// Create a temporary directory inside of a specific directory with a name prefixconst dir = awaitPath.tempDir({dir: newPath('/tmp'), name: 'mojo-'});
If your version of Node supports the using keyword, or you are using TypeScript, you can also use that to clean up
temporary directories for you.
// Create a temporary directory and delete it at end of scope (async)await using dir = awaitPath.tempDir();
await dir.child('test.txt').touch();
// Create a temporary directory and delete it at end of scope (sync)
using dir = Path.tempDirSync();
dir.child('test.txt').touchSync();
Everything is optimized for modern JavaScript with async/await.
We found that @mojojs/path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 4 open source maintainers collaborating on the project.
Package last updated on 12 Oct 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.