# node-rename-path

> Node.js path renaming made easy

Latest version **5.0.0** (published 2021-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-rename-path
pnpm add node-rename-path
yarn add node-rename-path
bun add node-rename-path
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2021-06-25 |
| First published | 2017-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=14.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mgenware |
| Maintainers | mgenware |

## Links

- npm: https://www.npmjs.com/package/node-rename-path
- Repository: https://github.com/mgenware/node-rename-path
- Issues: https://github.com/mgenware/node-rename-path/issues
- npm.io page: https://npm.io/package/node-rename-path

## Recent versions

- 5.0.0 (latest) — 2021-06-25
- 4.0.1 — 2020-02-06
- 4.0.0 — 2020-02-06
- 3.0.1 — 2019-08-21
- 3.0.0 — 2019-08-21
- 2.0.2 — 2018-01-22
- 2.0.1 — 2018-01-12
- 2.0.0 — 2018-01-12
- 1.0.0 — 2017-10-07

## README

# node-rename-path

[![Build Status](https://github.com/mgenware/node-rename-path/workflows/Build/badge.svg)](https://github.com/mgenware/node-rename-path/actions)
[![npm version](https://badge.fury.io/js/node-rename-path.svg)](https://badge.fury.io/js/node-rename-path)
[![Node.js Version](http://img.shields.io/node/v/node-rename-path.svg)](https://nodejs.org/en/)

Node.js path renaming made easy.

### Installation

```sh
npm add node-rename-path
```

## Example

```js
import rename from 'node-rename-path';

const PATH = 'documents/work/readme.md';
let results = '';

// Do nothing
results = rename(PATH);
console.log(results);
// -> 'documents/work/readme.md'

// Change file name
results = rename(PATH, (pathObj) => {
  return {
    name: 'day1_' + pathObj.name + '_notes',
  };
});
console.log(results);
// -> documents/work/day1_readme_notes.md

// Reset file name
results = rename(PATH, (pathObj) => {
  return {
    name: '___',
  };
});
console.log(results);
// -> documents/work/___.md

// Change extension
results = rename(PATH, (pathObj) => {
  return {
    ext: '.a.b.c.d',
  };
});
console.log(results);
// -> documents/work/readme.a.b.c.d

// Remove extension
results = rename(PATH, (pathObj) => {
  return {
    ext: '',
  };
});
console.log(results);
// -> documents/work/readme

// Set both file name and extension all at once
results = rename(PATH, (pathObj) => {
  return {
    base: 'brand-new.pdf',
  };
});
console.log(results);
// -> documents/work/brand-new.pdf

// Update directory path
results = rename(PATH, (pathObj) => {
  return {
    dir: '/root',
  };
});
console.log(results);
// -> /root/readme.md
```

---
_Source: https://npm.io/package/node-rename-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
