Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
A tiny (208B to 260B) utility to remove items recursively
This is a Promise
-based, cross-platform utility that recursively removes files and directories. It's effectively a programmatic rm -rf
for Node.js. There's also a CLI for easy, cross-platform usage.
Notice: Node v12.10.0 includes the
recursive
option forfs.rmdir
andfs.rmdirSync
.
$ npm install --save premove
There are two "versions" of premove
available:
Node.js: >= 8.x
Size (gzip): 249 bytes
Availability: CommonJS, ES Module
This is the primary/default mode. It makes use of async
/await
and util.promisify
.
Node.js: >= 6.x
Size (gzip): 202 bytes
Availability: CommonJS, ES Module
This is the opt-in mode, ideal for scenarios where async
usage cannot be supported.
In order to use it, simply make the following changes:
-import { premove } from 'premove';
+import { premove } from 'premove/sync';
import { resolve } from 'path';
import { premove } from 'premove';
// Async/await
try {
await premove('./foobar');
} catch (err) {
//
}
// Promise
premove('./foobar').then(val => {
console.log(typeof val);
//=> boolean
}).catch(err => {
//
});
// Using `cwd` option
const dir = resolve('./foo/bar');
await premove('hello.txt', { cwd: dir });
A premove
binary is available as of v3.0.0.
It accepts an optional --cwd
value and a list of paths to delete.
Important: By default
premove
refuses to delete:
- the
os.homedir
- the system root (
/
,C:\\
, etc)- items not contained by
--cwd
path
# remove "foo" and "bar" via `npx`
$ npx premove foo bar
# install globally, use whenever
$ npm install premove -g
$ premove foo bar
Returns: Promise<boolean>
Returns a Promise that resolves with a boolean value.
If true
, indicates that the str
input did exist and was successfully removed. A false
value indicates that the str
input did not exist, meaning nothing needed to be removed.
Important:
Thesync
andasync
versions share the same API.
The only difference is thatsync
is not Promise-based.
Type: String
The filepath to remove – may be a file or a directory.
An initial existence check is made for this filepath.
Important: This value is resolved to a full path.
Please be aware of how and from where the Node.js file system is resolving your path!
Type: String
Default: .
The directory to resolve your str
from.
Defaults to the process.cwd()
– aka, the directory that your command is run within.
MIT © Luke Edwards
FAQs
A tiny (208B to 260B) utility to remove items recursively
The npm package premove receives a total of 5,255 weekly downloads. As such, premove popularity was classified as popular.
We found that premove demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.