Socket
Socket
Sign inDemoInstall

pathmap

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pathmap

Rake's pathmap for JavaScript


Version published
Maintainers
1
Install size
17.1 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 25 Jul 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc