path-extra
path-extra contains methods that aren't included in the vanilla Node.js path package.
Last updated 5 years ago by ryanzim .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install path-extra 
SYNC missed versions from official npm registry.

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

Current Tags

  • 4.3.0                                ...           latest (5 years ago)

19 Versions

  • 4.3.0                                ...           5 years ago
  • 4.2.1                                ...           7 years ago
  • 4.2.0                                ...           7 years ago
  • 4.1.0                                ...           8 years ago
  • 4.0.0                                ...           8 years ago
  • 3.0.0                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
  • 0.0.3                                ...           12 years ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |