pathmap

v1.2.0
Rake's pathmap for JavaScript
rake pathmap path sprintf format

pathmap

Rake's pathmap for JavaScript. Think of it like sprintf for paths.

NPM version Build Status

Usage

pathmap accepts a path and a pathmap spec and returns a formatted string.

var pathmap = require('pathmap');

pathmap('a/b/c/d/file.txt', 'rm %f'); // => 'rm file.txt'
pathmap('file.coffee', 'mv %p %X.js'); // => 'mv file.coffee file.js'

The following patterns are supported:

  • %p - The complete path.
  • %f - The base file name of the path, with its file extension, but without any directories.
  • %n - The file name of the path without its file extension.
  • %d - The directory list of the path.
  • %x - The file extension of the path. An empty string if there is no extension.
  • %X - Everything but the file extension.
  • %s - The file separator. This can be configured by setting pathmap.sep.
  • %% - A percent sign.

The %d pattern supports a count argument to specify the number of directories to return from either side.

pathmap('a/b/c/d/file.txt', '%2d'); // => 'a/b'
pathmap('a/b/c/d/file.txt', '%-2d'); // => 'c/d'

%p, %f, %n, %d, %x and %X support a replacement argument that can be used to replace portions of the resulting string. The pattern looks like "{old,new}".

pathmap('file.md', '%X%{md,mdown}x'); // => 'file.mdown'

License

MIT License

npm i pathmap

Metadata

  • MIT
  • Whatever
  • Jeremy Ruppel
  • released 7/25/2014

Downloads

Maintainers