# path-extra

> path-extra contains methods that aren't included in the vanilla Node.js path package.

Latest version **4.3.0** (published 2019-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install path-extra
pnpm add path-extra
yarn add path-extra
bun add path-extra
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2019-09-23 |
| First published | 2011-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | JP Richardson |
| Maintainers | jprichardson, ryanzim |
| Keywords | fs, file, file system, path |

## Links

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

## Dependencies (2)

- [replace-ext](https://npm.io/package/replace-ext.md) ^1.0.0
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.5

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 4.3.0 (latest) — 2019-09-23
- 4.2.1 — 2017-09-01
- 4.2.0 — 2017-06-24
- 4.1.0 — 2017-03-07
- 4.0.0 — 2016-09-14
- 3.0.0 — 2015-11-05
- 2.0.0 — 2015-10-05
- 1.0.3 — 2015-05-24
- 1.0.2 — 2015-03-03
- 1.0.1 — 2015-03-02
- 1.0.0 — 2015-03-01
- 0.3.0 — 2014-09-09
- 0.2.1 — 2014-06-23
- 0.2.0 — 2014-04-28
- 0.1.1 — 2013-05-14
- … 4 more at https://npm.io/package/path-extra/versions

## README

Node.js: path-extra
===================

This module simply modifies the Node.js 'path' object with extra methods. It is a drop in replacement for the `path` module.



Installation
------------

    $ npm install path-extra



Usage
-----

```javascript
var path = require('path-extra');
```

You can still use all of the vanilla Node.js path methods.

## Methods:

### `replaceExt(filePath, extension)`

Replaces the extension from path with extension and returns the updated path string.

From the module [`replace-ext`](https://github.com/gulpjs/replace-ext).

Example:

```js
path.replaceExt('dir/file.md', '.html')
// => 'dir/file.html'
```

### `normalizeTrim(filePath)`

A `path.normalize()` that trims trailing slashes. Useful for comparing file paths.

Example:

```js
path.normalize('/foo/bar//baz/asdf/quux/../')
// => /foo/bar/baz/asdf/
path.normalizeTrim('/foo/bar//baz/asdf/quux/../')
// => /foo/bar/baz/asdf
```

### `base(filePath, [includeExt])`

A smart wrapper for `path.basename()`.

- When `includeExt` is `false`, returns the basename without an extension (`path.basename(filePath, path.extname(filePath))`).
- When `includeExt` is `true`, works like `path.basename(filePath)`.
- `includeExt` is `false` by default.

Example:

```js
path.base('path/to/file.md')
// => file
path.base('path/to/file.md', false)
// => file
path.base('path/to/file.md', true)
// => file.md
```

### `removeExt(filepath)`

Remove a path's extension.

Example:

```js
path.removeExt('some/dir/file.ext')
// => some/dir/file
```

### `fileNameWithPostfix(filePath, postfix)`

Append string to the end of the filename.

Example:

```js
path.fileNameWithPostfix('path/to/file-name.ext', '-old')
// => path/to/file-name-old.ext
```

### `fileNameWithPrefix(filePath, prefix)`

Append string to the beginning of the filename.

Example:

```js
path.fileNameWithPrefix('path/to/file-name.ext', 'new-')
// => path/to/new-file-name.ext
```

---

`homedir()`, `tempdir()`, and `datadir()` have been removed in version 4.0.0. Please use the [ospath](https://github.com/jprichardson/ospath) module instead.

License
-------

(The MIT License)

Copyright (c) 2011-2015 JP Richardson

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