easy-renamer
Easily rename files using custom rename functions that are automatically used against any filepaths that match the associated regex or glob patterns.
Last updated 4 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install easy-renamer 
SYNC missed versions from official npm registry.

easy-renamer NPM version NPM downloads Build Status

Easily rename files using custom rename functions that are automatically used against any filepaths that match the associated regex or glob patterns.

Install

Install with npm:

$ npm install easy-renamer --save

Examples

See examples. To run the examples, git clone the project then run the following from the root of the project:

$ npm i && node example

Usage

var Renamer = require('easy-renamer');
var renamer = new Renamer({destBase: 'foo/bar'});

renamer.matcher('*.md', function(file) {
  return path.join(file.dirname, file.filename + '.html');
});

renamer.rename('a/b/c.md');
//=> 'a/b/c.html'

Example with multiple patterns

var Renamer = require('easy-renamer');
var renamer = new Renamer();

function extname(ext) {
  return function(file) {
    return path.join(file.dirname, file.filename + ext);
  };
}

// use glob patterns...
renamer.matcher('**/*.md', extname('.html'));

// or regex
renamer.matcher(/foo\/.*\.less$/, extname('.css'));

glob('**/*', function(err, files) {
  files.forEach(function(fp) {
    fp = renamer.rename(fp);
    //=> do something with fp...
  });
});

Changelog

v0.3.0

  • Renamed .match() method to .matcher() (this is the last time, I promise!)
  • file.name property was renamed to file.filename

v0.2.0

  • Renamed .pattern() method to .match()
  • Implements lazy-caching

Related projects

You might also be interested in these projects:

  • map-files: Return an object for a glob of files. Pass a rename function for the keys,… more | homepage
  • micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… more | homepage
  • parse-filepath: Pollyfill for node.js path.parse, parses a filepath into an object. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v, on April 02, 2016.

Current Tags

  • 0.3.1                                ...           latest (4 years ago)

6 Versions

  • 0.3.1                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |