pax_global_header 0000666 0000000 0000000 00000000064 13533646421 0014521 g ustar 00root root 0000000 0000000 52 comment=de23e817bacb9534f00f8f9e48a8debbc0e89327
strip-filename-increment-2.0.1/ 0000775 0000000 0000000 00000000000 13533646421 0016422 5 ustar 00root root 0000000 0000000 strip-filename-increment-2.0.1/.editorconfig 0000664 0000000 0000000 00000000441 13533646421 0021076 0 ustar 00root root 0000000 0000000 # http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
strip-filename-increment-2.0.1/.eslintrc.json 0000664 0000000 0000000 00000007325 13533646421 0021225 0 ustar 00root root 0000000 0000000 {
"extends": [
"eslint:recommended"
],
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"parserOptions":{
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
}
}
strip-filename-increment-2.0.1/.gitattributes 0000664 0000000 0000000 00000000014 13533646421 0021310 0 ustar 00root root 0000000 0000000 * text=auto
strip-filename-increment-2.0.1/.github/ 0000775 0000000 0000000 00000000000 13533646421 0017762 5 ustar 00root root 0000000 0000000 strip-filename-increment-2.0.1/.github/contributing.md 0000664 0000000 0000000 00000011450 13533646421 0023014 0 ustar 00root root 0000000 0000000 # Contributing to strip-filename-increment
First and foremost, thank you! We appreciate that you want to contribute to strip-filename-increment, your time is valuable, and your contributions mean a lot to us.
## Important!
By contributing to this project, you:
* Agree that you have authored 100% of the content
* Agree that you have the necessary rights to the content
* Agree that you have received the necessary permissions from your employer to make the contributions (if applicable)
* Agree that the content you contribute may be provided under the Project license(s)
## Getting started
**What does "contributing" mean?**
Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following:
- Updating or correcting documentation
- Feature requests
- Bug reports
If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information.
**Showing support for strip-filename-increment**
Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use.
Don't have time to contribute? No worries, here are some other ways to show your support for strip-filename-increment:
- star the [project](https://github.com/jonschlinkert/strip-filename-increment)
- tweet your support for strip-filename-increment
## Issues
### Before creating an issue
Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues.
Try to follow these guidelines
- **Avoid creating issues for implementation help**. It's much better for discoverability, SEO, and semantics - to keep the issue tracker focused on bugs and feature requests - to ask implementation-related questions on [stackoverflow.com][so]
- **Investigate the issue**:
- **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue.
- Create the issue in the appropriate repository.
### Creating an issue
Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue:
- **version**: please note the version of strip-filename-increment are you using
- **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using
- **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/)
### Closing issues
The original poster or the maintainer's of strip-filename-increment may close an issue at any time. Typically, but not exclusively, issues are closed when:
- The issue is resolved
- The project's maintainers have determined the issue is out of scope
- An issue is clearly a duplicate of another issue, in which case the duplicate issue will be linked.
- A discussion has clearly run its course
## Next steps
**Tips for creating idiomatic issues**
Spending just a little extra time to review best practices and brush up on your contributing skills will, at minimum, make your issue easier to read, easier to resolve, and more likely to be found by others who have the same or similar issue in the future. At best, it will open up doors and potential career opportunities by helping you be at your best.
The following resources were hand-picked to help you be the most effective contributor you can be:
- The [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) is a great place for newcomers to start, but there is also information for experienced contributors there.
- Take some time to learn basic markdown. We can't stress this enough. Don't start pasting code into GitHub issues before you've taken a moment to review this [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601)
- The GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/) is another great markdown resource.
- Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/).
At the very least, please try to:
- Use backticks to wrap code. This ensures that it retains its formatting and isn't modified when it's rendered by GitHub, and makes the code more readable to others
- When applicable, use syntax highlighting by adding the correct language name after the first "code fence"
[so]: http://stackoverflow.com/questions/tagged/strip-filename-increment
strip-filename-increment-2.0.1/.gitignore 0000664 0000000 0000000 00000000440 13533646421 0020410 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
*.sublime-*
# test related, or directories generated by tests
test/actual
actual
coverage
.nyc*
# npm
node_modules
npm-debug.log
# yarn
yarn.lock
yarn-error.log
# misc
_gh_pages
_draft
_drafts
bower_components
vendor
temp
tmp
TODO.md
package-lock.json strip-filename-increment-2.0.1/.travis.yml 0000664 0000000 0000000 00000000154 13533646421 0020533 0 ustar 00root root 0000000 0000000 sudo: false
os:
- linux
- osx
- windows
language: node_js
node_js:
- node
- '12'
- '10'
- '8'
strip-filename-increment-2.0.1/.verb.md 0000664 0000000 0000000 00000003122 13533646421 0017756 0 ustar 00root root 0000000 0000000 ## Usage
```js
const strip = require('{%= name %}');
```
## API
{%= apidocs("index.js") %}
## Options
### removeRawNumbers
Remove "raw" trailing numbers that might not actually be increments. Use this with caution.
**Type**: `boolean`
**Default**: `undefined`
**Example**:
```js
console.log(strip('foo 1')); //=> 'foo 1'
console.log(strip('foo 1', { removeRawNumbers: true })); //=> 'foo'
console.log(strip('foo (1) 1')); //=> 'foo (1) 1'
console.log(strip('foo (1) 1', { removeRawNumbers: true })); //=> 'foo'
// This following example is not touched either way,
// since it's definitely not an increment.
console.log(strip('foo [1]')); //=> 'foo [1]'
console.log(strip('foo [1]', { removeRawNumbers: true })); //=> 'foo [1]'
```
## Examples
### Windows path increments
All of the following would return `foo`
```js
console.log(strip('foo (1)'));
console.log(strip('foo (2)'));
console.log(strip('foo (22)'));
```
All of the following would return `foo.txt`
```js
console.log(strip('foo (1).txt'));
console.log(strip('foo (2).txt'));
console.log(strip('foo (22).txt'));
```
### MacOS path increments
All of the following would return `foo`
```js
console.log(strip('foo copy'));
console.log(strip('foo copy 1'));
console.log(strip('foo copy 2'));
console.log(strip('foo copy 21'));
console.log(strip('foo copy 219 copy 219'));
```
All of the following would return `foo.txt`
```js
console.log(strip('foo copy.txt'));
console.log(strip('foo copy 1.txt'));
console.log(strip('foo copy 2.txt'));
console.log(strip('foo copy 21.txt'));
console.log(strip('foo copy 219 copy 219.txt'));
``` strip-filename-increment-2.0.1/LICENSE 0000664 0000000 0000000 00000002103 13533646421 0017423 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
strip-filename-increment-2.0.1/README.md 0000664 0000000 0000000 00000020675 13533646421 0017713 0 ustar 00root root 0000000 0000000 # strip-filename-increment [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/strip-filename-increment) [](https://npmjs.org/package/strip-filename-increment) [](https://npmjs.org/package/strip-filename-increment) [](https://travis-ci.org/jonschlinkert/strip-filename-increment)
> Operating systems commonly add a trailing increment, or the word 'copy', or something similar to duplicate files. This strips those increments. Tested on Windows, MacOS, and Linux.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=8):
```sh
$ npm install --save strip-filename-increment
```
## Usage
```js
const strip = require('strip-filename-increment');
```
## API
### [strip](index.js#L34)
Remove trailing increments from the `dirname` and/or `stem` (basename
without extension) of the given file path or object.
**Params**
* `file` **{Sring|Object}**: If the file is an object, it must have a `path` property.
* `options` **{Object}**: See [available options](#options).
* `returns` **{String|Object}**: Returns the same type that was given.
### [.increment](index.js#L62)
Removes trailing increments from the given string.
**Params**
* `input` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**
**Example**
```js
console.log(strip.increment('foo (2)')); => 'foo'
console.log(strip.increment('foo (copy)')); => 'foo'
console.log(strip.increment('foo copy 2')); => 'foo'
```
### [.dirname](index.js#L86)
Removes trailing increments and returns the `dirname` of the given `filepath`.
**Params**
* `filepath` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**: Returns the `dirname` of the filepath, without increments.
**Example**
```js
console.log(strip.dirname('foo (2)/bar.txt')); => 'foo'
console.log(strip.dirname('foo (copy)/bar.txt')); => 'foo'
console.log(strip.dirname('foo copy 2/bar.txt')); => 'foo'
```
### [.stem](index.js#L107)
Removes trailing increments and returns the `stem` of the given `filepath`.
**Params**
* `filepath` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**: Returns the `stem` of the filepath, without increments.
**Example**
```js
console.log(strip.stem('foo/bar (2).txt')); //=> 'bar'
console.log(strip.stem('foo/bar (copy).txt')); //=> 'bar'
console.log(strip.stem('foo/bar copy 2.txt')); //=> 'bar'
console.log(strip.stem('foo/bar (2) copy.txt')); //=> 'bar'
console.log(strip.stem('foo/bar (2) - copy.txt')); //=> 'bar'
```
### [.basename](index.js#L128)
Removes trailing increments and returns the `basename` of the given `filepath`.
**Params**
* `filepath` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**: Returns the `basename` of the filepath, without increments.
**Example**
```js
console.log(strip.basename('foo/bar (2).txt')); //=> 'bar.txt'
console.log(strip.basename('foo/bar (copy).txt')); //=> 'bar.txt'
console.log(strip.basename('foo/bar copy 2.txt')); //=> 'bar.txt'
console.log(strip.basename('foo/bar (2) copy.txt')); //=> 'bar.txt'
console.log(strip.basename('foo/bar (2) - copy.txt')); //=> 'bar.txt'
```
### [.path](index.js#L151)
Removes trailing increments from the `dirname` and `stem` of the given `filepath`.
**Params**
* `filepath` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**: Returns the `basename` of the filepath, without increments.
**Example**
```js
console.log(strip.path('foo copy/bar (2).txt')); //=> 'foo/bar.txt'
console.log(strip.path('foo (2)/bar (copy).txt')); //=> 'foo/bar.txt'
console.log(strip.path('foo (2)/bar copy 2.txt')); //=> 'foo/bar.txt'
console.log(strip.path('foo copy/bar (2) copy.txt')); //=> 'foo/bar.txt'
console.log(strip.path('foo copy/bar (2) - copy.txt')); //=> 'foo/bar.txt'
```
### [.file](index.js#L181)
Removes trailing increments from the `dirname` and `stem` properties of the given `file`.
**Params**
* `filepath` **{String}**
* `options` **{Object}**: See [available options](#options).
* `returns` **{String}**: Returns the `basename` of the filepath, without increments.
**Example**
```js
console.log(strip({ path: 'foo copy/bar (2).txt' }));
//=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
console.log(strip({ path: 'foo (2)/bar (copy).txt' }));
//=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
console.log(strip({ path: 'foo (2)/bar copy 2.txt' }));
//=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
console.log(strip({ path: 'foo copy/bar (2) copy.txt' }));
//=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
console.log(strip({ path: 'foo copy/bar (2) - copy.txt' }));
//=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
```
## Options
### removeRawNumbers
Remove "raw" trailing numbers that might not actually be increments. Use this with caution.
**Type**: `boolean`
**Default**: `undefined`
**Example**:
```js
console.log(strip('foo 1')); //=> 'foo 1'
console.log(strip('foo 1', { removeRawNumbers: true })); //=> 'foo'
console.log(strip('foo (1) 1')); //=> 'foo (1) 1'
console.log(strip('foo (1) 1', { removeRawNumbers: true })); //=> 'foo'
// This following example is not touched either way,
// since it's definitely not an increment.
console.log(strip('foo [1]')); //=> 'foo [1]'
console.log(strip('foo [1]', { removeRawNumbers: true })); //=> 'foo [1]'
```
## Examples
### Windows path increments
All of the following would return `foo`
```js
console.log(strip('foo (1)'));
console.log(strip('foo (2)'));
console.log(strip('foo (22)'));
```
All of the following would return `foo.txt`
```js
console.log(strip('foo (1).txt'));
console.log(strip('foo (2).txt'));
console.log(strip('foo (22).txt'));
```
### MacOS path increments
All of the following would return `foo`
```js
console.log(strip('foo copy'));
console.log(strip('foo copy 1'));
console.log(strip('foo copy 2'));
console.log(strip('foo copy 21'));
console.log(strip('foo copy 219 copy 219'));
```
All of the following would return `foo.txt`
```js
console.log(strip('foo copy.txt'));
console.log(strip('foo copy 1.txt'));
console.log(strip('foo copy 2.txt'));
console.log(strip('foo copy 21.txt'));
console.log(strip('foo copy 219 copy 219.txt'));
```
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
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:
```sh
$ npm install && npm test
```
Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Author
**Jon Schlinkert**
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
### License
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 04, 2019._ strip-filename-increment-2.0.1/index.js 0000664 0000000 0000000 00000016200 13533646421 0020066 0 ustar 00root root 0000000 0000000 /*!
* file-name
*
* Copyright (c) 2015-present, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
const path = require('path');
const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
const constants = {
REGEX_DARWIN: /( copy( [0-9]+)?)+$/i,
REGEX_DEFAULT: /(( copy)?( \([0-9]+\)|[0-9]+)?)+$/i,
REGEX_WIN32: /( \([0-9]+\))+$/i,
REGEX_NON_STANDARD: /( \.\(incomplete\)| \([0-9]+\)|[- ]+)+$/i,
REGEX_LINUX: /( \(((another|[0-9]+(th|st|nd|rd)) )?copy\))+$/i,
REGEX_RAW_NUMBERS: '| [0-9]+',
REGEX_SOURCE: ' \\((?:(another|[0-9]+(th|st|nd|rd)) )?copy\\)|copy( [0-9]+)?|\\.\\(incomplete\\)| \\([0-9]+\\)|[- ]+'
};
/**
* Remove trailing increments from the `dirname` and/or `stem` (basename
* without extension) of the given file path or object.
*
* @name strip
* @param {Sring|Object} `file` If the file is an object, it must have a `path` property.
* @param {Object} `options` See [available options](#options).
* @return {String|Object} Returns the same type that was given.
* @api public
*/
const strip = (file, options) => {
if (!file) return file;
if (isObject(file) && file.path) {
return strip.file(file, options);
}
let filepath = strip.increment(file, options);
let extname = path.extname(filepath);
let dirname = strip.increment(path.dirname(filepath), options);
let stem = strip.increment(path.basename(filepath, extname), options);
return path.join(dirname, stem + extname);
};
/**
* Removes trailing increments from the given string.
*
* ```js
* console.log(strip.increment('foo (2)')); => 'foo'
* console.log(strip.increment('foo (copy)')); => 'foo'
* console.log(strip.increment('foo copy 2')); => 'foo'
* ```
* @name .increment
* @param {String} `input`
* @param {Object} `options` See [available options](#options).
* @return {String}
* @api public
*/
strip.increment = (input, options = {}) => {
if (typeof input === 'string' && input !== '') {
let suffix = options.removeRawNumbers === true ? constants.REGEX_RAW_NUMBERS : '';
let source = constants.REGEX_SOURCE + suffix;
return input.replace(new RegExp(`(${source})+$`, 'i'), '');
}
return input;
};
/**
* Removes trailing increments and returns the `dirname` of the given `filepath`.
*
* ```js
* console.log(strip.dirname('foo (2)/bar.txt')); => 'foo'
* console.log(strip.dirname('foo (copy)/bar.txt')); => 'foo'
* console.log(strip.dirname('foo copy 2/bar.txt')); => 'foo'
* ```
* @name .dirname
* @param {String} `filepath`
* @param {Object} `options` See [available options](#options).
* @return {String} Returns the `dirname` of the filepath, without increments.
* @api public
*/
strip.dirname = (filepath, options) => {
return strip.increment(path.dirname(filepath), options);
};
/**
* Removes trailing increments and returns the `stem` of the given `filepath`.
*
* ```js
* console.log(strip.stem('foo/bar (2).txt')); //=> 'bar'
* console.log(strip.stem('foo/bar (copy).txt')); //=> 'bar'
* console.log(strip.stem('foo/bar copy 2.txt')); //=> 'bar'
* console.log(strip.stem('foo/bar (2) copy.txt')); //=> 'bar'
* console.log(strip.stem('foo/bar (2) - copy.txt')); //=> 'bar'
* ```
* @name .stem
* @param {String} `filepath`
* @param {Object} `options` See [available options](#options).
* @return {String} Returns the `stem` of the filepath, without increments.
* @api public
*/
strip.stem = (filepath, options) => {
return strip.increment(path.basename(filepath, path.extname(filepath)), options);
};
/**
* Removes trailing increments and returns the `basename` of the given `filepath`.
*
* ```js
* console.log(strip.basename('foo/bar (2).txt')); //=> 'bar.txt'
* console.log(strip.basename('foo/bar (copy).txt')); //=> 'bar.txt'
* console.log(strip.basename('foo/bar copy 2.txt')); //=> 'bar.txt'
* console.log(strip.basename('foo/bar (2) copy.txt')); //=> 'bar.txt'
* console.log(strip.basename('foo/bar (2) - copy.txt')); //=> 'bar.txt'
* ```
* @name .basename
* @param {String} `filepath`
* @param {Object} `options` See [available options](#options).
* @return {String} Returns the `basename` of the filepath, without increments.
* @api public
*/
strip.basename = (filepath, options) => {
let extname = path.extname(filepath);
let stem = path.basename(filepath, extname);
return strip.increment(stem, options) + extname;
};
/**
* Removes trailing increments from the `dirname` and `stem` of the given `filepath`.
*
* ```js
* console.log(strip.path('foo copy/bar (2).txt')); //=> 'foo/bar.txt'
* console.log(strip.path('foo (2)/bar (copy).txt')); //=> 'foo/bar.txt'
* console.log(strip.path('foo (2)/bar copy 2.txt')); //=> 'foo/bar.txt'
* console.log(strip.path('foo copy/bar (2) copy.txt')); //=> 'foo/bar.txt'
* console.log(strip.path('foo copy/bar (2) - copy.txt')); //=> 'foo/bar.txt'
* ```
* @name .path
* @param {String} `filepath`
* @param {Object} `options` See [available options](#options).
* @return {String} Returns the `basename` of the filepath, without increments.
* @api public
*/
strip.path = (filepath, options) => {
let extname = path.extname(filepath);
let stem = strip.increment(path.basename(filepath, extname), options);
let dirname = strip.increment(path.dirname(filepath), options);
return path.join(dirname, stem + extname);
};
/**
* Removes trailing increments from the `dirname` and `stem` properties
* of the given `file`.
*
* ```js
* console.log(strip({ path: 'foo copy/bar (2).txt' }));
* //=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
* console.log(strip({ path: 'foo (2)/bar (copy).txt' }));
* //=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
* console.log(strip({ path: 'foo (2)/bar copy 2.txt' }));
* //=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
* console.log(strip({ path: 'foo copy/bar (2) copy.txt' }));
* //=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
* console.log(strip({ path: 'foo copy/bar (2) - copy.txt' }));
* //=> { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }
* ```
* @name .file
* @param {String} `filepath`
* @param {Object} `options` See [available options](#options).
* @return {String} Returns the `basename` of the filepath, without increments.
* @api public
*/
strip.file = (file, options = {}) => {
if (!isObject(file)) return file;
if (!file.path) return file;
if (file.dirname && !file.dir) file.dir = file.dirname;
if (file.basename && !file.base) file.base = file.basename;
if (file.extname && !file.ext) file.ext = file.extname;
if (file.stem && !file.name) file.name = file.stem;
if (file.dir === void 0) file.dir = path.dirname(file.path);
if (file.ext === void 0) file.ext = path.extname(file.path);
if (file.base === void 0) file.base = path.basename(file.path);
if (file.name === void 0) file.name = path.basename(file.path, file.ext);
file.name = strip.increment(file.name, options);
file.dir = strip.increment(file.dir, options);
file.base = file.name + file.ext;
file.path = path.join(file.dir, file.base);
return file;
};
module.exports = strip;
strip-filename-increment-2.0.1/package.json 0000664 0000000 0000000 00000002025 13533646421 0020707 0 ustar 00root root 0000000 0000000 {
"name": "strip-filename-increment",
"description": "Operating systems commonly add a trailing increment, or the word 'copy', or something similar to duplicate files. This strips those increments. Tested on Windows, MacOS, and Linux.",
"version": "2.0.1",
"homepage": "https://github.com/jonschlinkert/strip-filename-increment",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/strip-filename-increment",
"bugs": {
"url": "https://github.com/jonschlinkert/strip-filename-increment/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=8"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"gulp-format-md": "^2.0.0",
"mocha": "^6.2.0"
},
"keywords": [
"filename",
"increment",
"strip"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}
strip-filename-increment-2.0.1/test/ 0000775 0000000 0000000 00000000000 13533646421 0017401 5 ustar 00root root 0000000 0000000 strip-filename-increment-2.0.1/test/darwin.js 0000664 0000000 0000000 00000005222 13533646421 0021224 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
const assert = require('assert').strict;
const strip = require('..');
describe('darwin', () => {
describe('file name (stem)', () => {
it('should remove mac-OS-style increments from a file name', () => {
assert.equal(strip('foo copy.txt'), 'foo.txt');
assert.equal(strip('foo copy 1.txt'), 'foo.txt');
assert.equal(strip('foo copy 2.txt'), 'foo.txt');
assert.equal(strip('foo copy 21.txt'), 'foo.txt');
assert.equal(strip('foo copy 219 copy 219.txt'), 'foo.txt');
assert.equal(strip('foo copy 219 (2).txt'), 'foo.txt');
});
it('should remove mac-OS-style increments from a folder name', () => {
assert.equal(strip('foo copy'), 'foo');
assert.equal(strip('foo copy 1'), 'foo');
assert.equal(strip('foo copy 2'), 'foo');
assert.equal(strip('foo copy 21'), 'foo');
assert.equal(strip('foo copy 219 copy 219'), 'foo');
assert.equal(strip('foo copy 219 (2)'), 'foo');
assert.equal(strip('foo Copy'), 'foo');
assert.equal(strip('foo Copy 1'), 'foo');
assert.equal(strip('foo Copy 2'), 'foo');
assert.equal(strip('foo Copy 21'), 'foo');
assert.equal(strip('foo Copy 219 copy 219'), 'foo');
assert.equal(strip('foo Copy 219 (2)'), 'foo');
});
it('should remove mac-OS-style increments from folder and file name', () => {
assert.equal(strip('bar copy/foo copy 1.txt'), 'bar/foo.txt');
assert.equal(strip('bar copy/foo copy 2.txt'), 'bar/foo.txt');
assert.equal(strip('bar copy/foo copy 21.txt'), 'bar/foo.txt');
assert.equal(strip('bar copy/foo copy 219 (2).txt'), 'bar/foo.txt');
assert.equal(strip('bar copy/foo copy 219 copy 219.txt'), 'bar/foo.txt');
assert.equal(strip('bar copy/foo copy.txt'), 'bar/foo.txt');
});
});
describe('basename (stem + file extension)', () => {
it('should remove mac-OS-style increments from a basename', () => {
assert.equal(strip('foo copy.txt'), 'foo.txt');
assert.equal(strip('foo copy 1.txt'), 'foo.txt');
assert.equal(strip('foo copy 2.txt'), 'foo.txt');
assert.equal(strip('foo copy 21.txt'), 'foo.txt');
assert.equal(strip('foo copy 219 copy 219.txt'), 'foo.txt');
assert.equal(strip('foo copy 219 (2).txt'), 'foo.txt');
});
it('should remove mac-OS-style increments from a basename', () => {
assert.equal(strip('foo.(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo copy 219.(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo copy 219.(incomplete).(incomplete).(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo.(incomplete).(incomplete).txt'), 'foo.txt');
});
});
});
strip-filename-increment-2.0.1/test/linux.js 0000664 0000000 0000000 00000003565 13533646421 0021107 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
const assert = require('assert').strict;
const strip = require('..');
describe('linux', () => {
describe('basename (stem + extension)', () => {
it('should remove linux-style increments from a file name', () => {
assert.equal(strip('foo (copy).txt', { platform: 'linux' }), 'foo.txt');
assert.equal(strip('foo (another copy).txt', { platform: 'linux' }), 'foo.txt');
assert.equal(strip('foo (3rd copy).txt', { platform: 'linux' }), 'foo.txt');
assert.equal(strip('foo (4th copy).txt', { platform: 'linux' }), 'foo.txt');
assert.equal(strip('foo (5th copy).txt', { platform: 'linux' }), 'foo.txt');
assert.equal(strip('foo (111th copy).txt', { platform: 'linux' }), 'foo.txt');
});
});
describe('folder name', () => {
it('should remove linux-style increments from a folder name', () => {
assert.equal(strip('foo (copy)', { platform: 'linux' }), 'foo');
assert.equal(strip('foo (another copy)', { platform: 'linux' }), 'foo');
assert.equal(strip('foo (3rd copy)', { platform: 'linux' }), 'foo');
assert.equal(strip('foo (4th copy)', { platform: 'linux' }), 'foo');
assert.equal(strip('foo (5th copy)', { platform: 'linux' }), 'foo');
assert.equal(strip('foo (111th copy)', { platform: 'linux' }), 'foo');
});
it('should not remove non-incremental numbers from a folder name', () => {
assert.equal(strip('foo 1 (copy)', { platform: 'linux' }), 'foo 1');
assert.equal(strip('foo 1 (another copy)', { platform: 'linux' }), 'foo 1');
assert.equal(strip('foo 1 (3rd copy)', { platform: 'linux' }), 'foo 1');
assert.equal(strip('foo 1 (4th copy)', { platform: 'linux' }), 'foo 1');
assert.equal(strip('foo 1 (5th copy)', { platform: 'linux' }), 'foo 1');
assert.equal(strip('foo 1 (111th copy)', { platform: 'linux' }), 'foo 1');
});
});
});
strip-filename-increment-2.0.1/test/non-standard.js 0000664 0000000 0000000 00000003531 13533646421 0022331 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
const assert = require('assert').strict;
const strip = require('..');
describe('non-standard', () => {
describe('foldres or files without extensions', () => {
it('should not remove raw numbers from file names by default', () => {
assert.equal(strip('foo 1'), 'foo 1');
assert.equal(strip('foo 2'), 'foo 2');
});
it('should remove raw numbers from file names when specified on options', () => {
assert.equal(strip('foo 1', { removeRawNumbers: true }), 'foo');
assert.equal(strip('foo 2', { removeRawNumbers: true }), 'foo');
});
it('should remove (incomplete) from a file name', () => {
assert.equal(strip('foo.(incomplete)'), 'foo');
assert.equal(strip('foo copy 219.(incomplete)'), 'foo');
assert.equal(strip('foo copy 219.(incomplete).(incomplete).(incomplete)'), 'foo');
assert.equal(strip('foo.(incomplete).(incomplete)'), 'foo');
});
it('should remove (incomplete) from a file name with extension', () => {
assert.equal(strip('foo.(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo copy 219.(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo copy 219.(incomplete).(incomplete).(incomplete).txt'), 'foo.txt');
assert.equal(strip('foo.(incomplete).(incomplete).txt'), 'foo.txt');
});
it('should not remove a non-increment from a file or folder name', () => {
assert.equal(strip('foo [1]'), 'foo [1]');
assert.equal(strip('foo [1].txt'), 'foo [1].txt');
assert.equal(strip('bar [1]/foo [1].txt'), 'bar [1]/foo [1].txt');
assert.equal(strip('bar[1]/foo[1].txt'), 'bar[1]/foo[1].txt');
});
});
describe('basename (stem + file extension)', () => {
it('should not remove a non-increment from a basename', () => {
assert.equal(strip('foo [1].txt'), 'foo [1].txt');
});
});
});
strip-filename-increment-2.0.1/test/windows.js 0000664 0000000 0000000 00000003475 13533646421 0021442 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
const path = require('path');
const assert = require('assert').strict;
const strip = require('..');
describe('windows', () => {
describe('folders or files without extensions', () => {
it('should remove windows-style increments from a file name', () => {
assert.equal(strip('foo (1)'), 'foo');
assert.equal(strip('foo (2)'), 'foo');
assert.equal(strip('foo (22)'), 'foo');
});
it('should not remove non-increments', () => {
assert.equal(strip('foo 1'), 'foo 1');
assert.equal(strip('foo (1) 1'), 'foo (1) 1');
assert.equal(strip('foo [1]'), 'foo [1]');
});
it('should not remove non-increments', () => {
assert.equal(strip('foo 1', { removeRawNumbers: true }), 'foo');
assert.equal(strip('foo (1) 1', { removeRawNumbers: true }), 'foo');
assert.equal(strip('foo [1]', { removeRawNumbers: true }), 'foo [1]');
});
it('should remove windows-style increments from absolute paths', () => {
assert.equal(strip(path.resolve('foo (1)')), path.resolve('foo'));
assert.equal(strip(path.resolve('foo (2)')), path.resolve('foo'));
assert.equal(strip(path.resolve('foo (22)')), path.resolve('foo'));
});
it('should remove dash-separated windows-style increments', () => {
assert.equal(strip('foo (3) - Copy'), 'foo');
assert.equal(strip('foo (31) - Copy - Copy'), 'foo');
});
});
describe('basename (stem + extension)', () => {
it('should remove windows-style increments from a basename', () => {
assert.equal(strip('foo (1).txt'), 'foo.txt');
assert.equal(strip('foo (2).txt'), 'foo.txt');
assert.equal(strip('foo (22).txt'), 'foo.txt');
assert.equal(strip('foo copy (22).txt'), 'foo.txt');
assert.equal(strip('foo Copy (22).txt'), 'foo.txt');
});
});
});