Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

path-extra

jprichardson304.9kMIT4.3.0TypeScript support: included

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

fs, file, file system, path

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

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.

Example:

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

normalizeTrim(filePath)

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

Example:

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:

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:

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

fileNameWithPostfix(filePath, postfix)

Append string to the end of the filename.

Example:

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:

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 module instead.

License

(The MIT License)

Copyright (c) 2011-2015 JP Richardson

changelog

4.3.0 / 2019-09-23

  • Add TypeScript typings (#30)

4.2.1 / 2017-09-01

  • Added argument type-checking for fileNameWithPrefix() & fileNameWithPostfix() to prevent unexpected behavior. #28

4.2.0 / 2017-06-24

  • Added fileNameWithPrefix() & fileNameWithPostfix()

4.1.0 / 2017-03-06

  • Added removeExt()

4.0.0 / 2016-09-14

Breaking

  • dropped homedir(), tempdir(), and datadir()

Added

  • replaceExt(), normalizeTrim(), base()

3.0.0 / 2015-11-05

2.0.0 / 2015-10-05

1.0.3 / 2015-05-24

1.0.2 / 2015-03-02

  • bugfix path.delimiter / all properties added

1.0.1 / 2015-03-01

  • bugfix: Windows datadir() was incorrect for default, this is breaking, but is a bugfix

1.0.0 / 2015-02-28

  • added sep support. See #10
  • use standard styling

0.3.0 / 2014-09-08

  • add freebsd support

0.2.1 / 2014-06-23

  • fixed npm warning about homepage field #6

0.2.0 / 2014-04-28

  • added sunos support #5

0.1.1 / 2013-05-14

  • Windows XP support for datadir

0.1.0 / 2013-03-18

  • Added datadir().

0.0.3 / 2012-08-07

  • Removed CoffeeScript dev dependence.
  • Added homedir() method.