npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rm-up

v1.1.0

Published

Delete files or empty directories and their empty parents from bottom to up.

Downloads

1,335

Readme

rm-up

Delete files or empty directories and their empty parents from bottom to up.

Synopsis

import rmUp from "rm-up";

await rmUp("generated/template/db/ddl");

await rmUp(["generated/lib/math", "generated/util/helper"], { cwd: "/path/to/project", stop: "." });

Safety

rm-up deletes only files below the options.stop to prevent unintentional delete operations. If the options.stop is not provided rm-up deletes empty directories up to root.

For example:

  • await rmUp("/root/a/b/c", { stop: "root/x" }); // nothing would be deleted.
  • await rmUp("/root/a/b/c", { stop: "root/a" }); // "b" and "c" deleted if empty.

Details

rmUp function deletes files or empty directories and their empty parents from bottom to up. First deletes given files or directories, then checks whether their parent directories are empty and deletes them if empty. Then checks parent's parents and so on.

It's direction is reverse of rm -rf or deltree command.

Ignores system junk files such as .DS_Store and Thumbs.db.

For CLI, please see rm-up-cli.

Why do I need this?

It is most useful when you create a file in a deep path programmatically and want to delete whole created tree, but not sure if other files are added somewhere between by others.

For example you created "generated/template/db/ddl/create.sql" in your project "/path/to/project" and want to delete whole created tree.

Example 1

await rmUp("generated/template/db/ddl/create.sql", { cwd: "/path/to/project" });

create.sql file would be deleted, ddl become empty and deleted, db become empty and deleted, so template and generated directories are deleted likewise.

Example 2

Same options for a little different directory tree:

await rmUp("generated/template/db/ddl/create.sql", { cwd: "/path/to/project" });

create.sql file would be deleted, ddl become empty and deleted, db become empty and deleted, template become empty and deleted, but this time generated directory not become empty because of assets and not deleted.

API

Table of contents

Interfaces

Functions

Functions

default

Const default(paths, __namedParameters?): Promise<string[]>

deprecated Use named export: import { rmUp } from "rm-up"; / const { rmUp } = require("rm-up");

Parameters

| Name | Type | | :------------------ | :-------------------------------- | | paths | string | string[] | | __namedParameters | Options |

Returns

Promise<string[]>

Defined in

index.ts:6


rmUp

rmUp(paths, options?): Promise<string[]>

Delete files or empty directories and their empty parents up to stop path excluding stop path.

Parameters

| Name | Type | Description | | :-------- | :-------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | | paths | string | string[] | are the list of directories to be deleted with their empty parents. All paths must be under the same root. (e.g. you can not mix C: and D: in Windows) | | options | Options | are options. |

Returns

Promise<string[]>

Defined in

main.ts:29

Interfaces

rm-up / Options

Interface: Options

Options

Table of contents

Properties

Properties

cwd

Optional cwd: string

Current working directory to be used with relative input paths.

Defined in

main.ts:8


deleteInitial

Optional deleteInitial: boolean

Delete target path (bottom directory) even it is non-empty directory. For example even if c directory of a/b/c has some files in it, c will be deleted.

Defined in

main.ts:14


dry

Optional dry: boolean

Dry run without deleting any files.

Defined in

main.ts:16


force

Optional force: boolean

If true, no error is thrown if input path is not a directory or does not exists. CWD is used by default.

Defined in

main.ts:12


relative

Optional relative: boolean

If true returns paths are relative to cwd, otherwise absolute paths.

Defined in

main.ts:20


stop

Optional stop: string

Path to stop searching empty directories up. Stop directory is not included (not deleted).

Defined in

main.ts:10


verbose

Optional verbose: boolean

If true returns all deleted directories and files. Otherwise returns only paths which delete command is executed agains.

Defined in

main.ts:18

Related