Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

strip-filename-increment

1.0.0 • Public • Published

strip-filename-increment NPM version NPM monthly downloads NPM total downloads Linux Build Status

Strips the numerical increment and/or the word copy that is automatically generated and added to the end of a filename by an operating system. Works with windows and mac-OS style increments. Useful when it's necessary to normalize filenames for doing file comparisons, checking for duplicates, etc.

Install

Install with npm:

$ npm install --save strip-filename-increment

Usage

var stripIncrement = require('strip-filename-increment');

Does NOT strip non-increments

console.log(stripIncrement('foo 1'));
//=> 'foo 1'
console.log(stripIncrement('foo [1]'));
//=> 'foo [1]'
console.log(stripIncrement('foo (1) 1'));
//=> 'foo (1) 1'

Windows-style increments

All of the following would return foo

console.log(stripIncrement('foo (1)'));  
console.log(stripIncrement('foo (2)'));  
console.log(stripIncrement('foo (22)')); 

All of the following would return foo.txt

console.log(stripIncrement('foo (1).txt'));  
console.log(stripIncrement('foo (2).txt'));  
console.log(stripIncrement('foo (22).txt')); 

mac OS-style increments

All of the following would return foo

console.log(stripIncrement('foo copy'));
console.log(stripIncrement('foo copy 1'));
console.log(stripIncrement('foo copy 2'));
console.log(stripIncrement('foo copy 21'));
console.log(stripIncrement('foo copy 219 copy 219'));

All of the following would return foo.txt

console.log(stripIncrement('foo copy.txt'));
console.log(stripIncrement('foo copy 1.txt'));
console.log(stripIncrement('foo copy 2.txt'));
console.log(stripIncrement('foo copy 21.txt'));
console.log(stripIncrement('foo copy 219 copy 219.txt'));

About

Contributing

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

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 11, 2017.

install

npm i strip-filename-increment

Downloadsweekly downloads

1

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability