An open API service indexing awesome lists of open source software.

https://github.com/jonschlinkert/easy-renamer

Easily rename files using custom rename functions that are automatically used against any file paths that match the associated regex or glob patterns.
https://github.com/jonschlinkert/easy-renamer

file filepath javascript name nodejs path rename renamer

Last synced: 7 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# easy-renamer [![NPM version](https://img.shields.io/npm/v/easy-renamer.svg?style=flat)](https://www.npmjs.com/package/easy-renamer) [![NPM downloads](https://img.shields.io/npm/dm/easy-renamer.svg?style=flat)](https://npmjs.org/package/easy-renamer) [![Build Status](https://img.shields.io/travis/jonschlinkert/easy-renamer.svg?style=flat)](https://travis-ci.org/jonschlinkert/easy-renamer)

> 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](https://www.npmjs.com/):

```sh
$ npm install easy-renamer --save
```

## Examples

See [examples](example.js). To run the examples, git clone the project then run the following from the root of the project:

```sh
$ npm i && node example
```

## Usage

```js
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**

```js
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](https://www.npmjs.com/package/map-files): Return an object for a glob of files. Pass a `rename` function for the keys,… [more](https://www.npmjs.com/package/map-files) | [homepage](https://github.com/jonschlinkert/map-files)
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://www.npmjs.com/package/micromatch) | [homepage](https://github.com/jonschlinkert/micromatch)
* [parse-filepath](https://www.npmjs.com/package/parse-filepath): Pollyfill for node.js `path.parse`, parses a filepath into an object. | [homepage](https://github.com/jonschlinkert/parse-filepath)

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/easy-renamer/issues/new).

## Building docs

Generate readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install verb && npm run docs
```

Or, if [verb](https://github.com/verbose/verb) is installed globally:

```sh
$ verb
```

## Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

## Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/easy-renamer/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v, on April 02, 2016._