{"id":15685651,"url":"https://github.com/jonschlinkert/strip-filename-increment","last_synced_at":"2025-05-07T17:29:32.718Z","repository":{"id":57372802,"uuid":"96853952","full_name":"jonschlinkert/strip-filename-increment","owner":"jonschlinkert","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.","archived":false,"fork":false,"pushed_at":"2019-09-04T06:30:45.000Z","size":17,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T00:38:16.968Z","etag":null,"topics":["conflicts","dirent","duplicate","file","filename","filepath","increment","javascript","jonschlinkert","name","node","nodejs","number","path","rename","strip","vinyl"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-11T05:25:14.000Z","updated_at":"2024-12-31T03:54:14.000Z","dependencies_parsed_at":"2022-08-29T11:02:12.639Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/strip-filename-increment","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-filename-increment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-filename-increment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-filename-increment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fstrip-filename-increment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/strip-filename-increment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252926206,"owners_count":21826266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conflicts","dirent","duplicate","file","filename","filepath","increment","javascript","jonschlinkert","name","node","nodejs","number","path","rename","strip","vinyl"],"created_at":"2024-10-03T17:28:18.547Z","updated_at":"2025-05-07T17:29:32.676Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68"],"categories":[],"sub_categories":[],"readme":"# strip-filename-increment [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/strip-filename-increment.svg?style=flat)](https://www.npmjs.com/package/strip-filename-increment) [![NPM monthly downloads](https://img.shields.io/npm/dm/strip-filename-increment.svg?style=flat)](https://npmjs.org/package/strip-filename-increment) [![NPM total downloads](https://img.shields.io/npm/dt/strip-filename-increment.svg?style=flat)](https://npmjs.org/package/strip-filename-increment) [![Build Status](https://travis-ci.org/jonschlinkert/strip-filename-increment.svg?branch=master)](https://travis-ci.org/jonschlinkert/strip-filename-increment)\n\n\u003e 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.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) \u003e=8):\n\n```sh\n$ npm install --save strip-filename-increment\n```\n\n## Usage\n\n```js\nconst strip = require('strip-filename-increment');\n```\n\n## API\n\n### [strip](index.js#L34)\n\nRemove trailing increments from the `dirname` and/or `stem` (basename\nwithout extension) of the given file path or object.\n\n**Params**\n\n* `file` **{Sring|Object}**: If the file is an object, it must have a `path` property.\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String|Object}**: Returns the same type that was given.\n\n### [.increment](index.js#L62)\n\nRemoves trailing increments from the given string.\n\n**Params**\n\n* `input` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**\n\n**Example**\n\n```js\nconsole.log(strip.increment('foo (2)')); =\u003e 'foo'\nconsole.log(strip.increment('foo (copy)')); =\u003e 'foo'\nconsole.log(strip.increment('foo copy 2')); =\u003e 'foo'\n```\n\n### [.dirname](index.js#L86)\n\nRemoves trailing increments and returns the `dirname` of the given `filepath`.\n\n**Params**\n\n* `filepath` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**: Returns the `dirname` of the filepath, without increments.\n\n**Example**\n\n```js\nconsole.log(strip.dirname('foo (2)/bar.txt')); =\u003e 'foo'\nconsole.log(strip.dirname('foo (copy)/bar.txt')); =\u003e 'foo'\nconsole.log(strip.dirname('foo copy 2/bar.txt')); =\u003e 'foo'\n```\n\n### [.stem](index.js#L107)\n\nRemoves trailing increments and returns the `stem` of the given `filepath`.\n\n**Params**\n\n* `filepath` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**: Returns the `stem` of the filepath, without increments.\n\n**Example**\n\n```js\nconsole.log(strip.stem('foo/bar (2).txt')); //=\u003e 'bar'\nconsole.log(strip.stem('foo/bar (copy).txt')); //=\u003e 'bar'\nconsole.log(strip.stem('foo/bar copy 2.txt')); //=\u003e 'bar'\nconsole.log(strip.stem('foo/bar (2) copy.txt')); //=\u003e 'bar'\nconsole.log(strip.stem('foo/bar (2) - copy.txt')); //=\u003e 'bar'\n```\n\n### [.basename](index.js#L128)\n\nRemoves trailing increments and returns the `basename` of the given `filepath`.\n\n**Params**\n\n* `filepath` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**: Returns the `basename` of the filepath, without increments.\n\n**Example**\n\n```js\nconsole.log(strip.basename('foo/bar (2).txt')); //=\u003e 'bar.txt'\nconsole.log(strip.basename('foo/bar (copy).txt')); //=\u003e 'bar.txt'\nconsole.log(strip.basename('foo/bar copy 2.txt')); //=\u003e 'bar.txt'\nconsole.log(strip.basename('foo/bar (2) copy.txt')); //=\u003e 'bar.txt'\nconsole.log(strip.basename('foo/bar (2) - copy.txt')); //=\u003e 'bar.txt'\n```\n\n### [.path](index.js#L151)\n\nRemoves trailing increments from the `dirname` and `stem` of the given `filepath`.\n\n**Params**\n\n* `filepath` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**: Returns the `basename` of the filepath, without increments.\n\n**Example**\n\n```js\nconsole.log(strip.path('foo copy/bar (2).txt')); //=\u003e 'foo/bar.txt'\nconsole.log(strip.path('foo (2)/bar (copy).txt')); //=\u003e 'foo/bar.txt'\nconsole.log(strip.path('foo (2)/bar copy 2.txt')); //=\u003e 'foo/bar.txt'\nconsole.log(strip.path('foo copy/bar (2) copy.txt')); //=\u003e 'foo/bar.txt'\nconsole.log(strip.path('foo copy/bar (2) - copy.txt')); //=\u003e 'foo/bar.txt'\n```\n\n### [.file](index.js#L181)\n\nRemoves trailing increments from the `dirname` and `stem` properties of the given `file`.\n\n**Params**\n\n* `filepath` **{String}**\n* `options` **{Object}**: See [available options](#options).\n* `returns` **{String}**: Returns the `basename` of the filepath, without increments.\n\n**Example**\n\n```js\nconsole.log(strip({ path: 'foo copy/bar (2).txt' }));\n//=\u003e { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }\nconsole.log(strip({ path: 'foo (2)/bar (copy).txt' }));\n//=\u003e { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }\nconsole.log(strip({ path: 'foo (2)/bar copy 2.txt' }));\n//=\u003e { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }\nconsole.log(strip({ path: 'foo copy/bar (2) copy.txt' }));\n//=\u003e { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }\nconsole.log(strip({ path: 'foo copy/bar (2) - copy.txt' }));\n//=\u003e { path: 'foo/bar.txt', dir: 'foo', base: 'bar.txt', name: 'bar', ext: '.txt' }\n```\n\n## Options\n\n### removeRawNumbers\n\nRemove \"raw\" trailing numbers that might not actually be increments. Use this with caution.\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\n**Example**:\n\n```js\nconsole.log(strip('foo 1')); //=\u003e 'foo 1'\nconsole.log(strip('foo 1', { removeRawNumbers: true })); //=\u003e 'foo'\n\nconsole.log(strip('foo (1) 1')); //=\u003e 'foo (1) 1'\nconsole.log(strip('foo (1) 1', { removeRawNumbers: true })); //=\u003e 'foo'\n\n// This following example is not touched either way, \n// since it's definitely not an increment.\nconsole.log(strip('foo [1]')); //=\u003e 'foo [1]'\nconsole.log(strip('foo [1]', { removeRawNumbers: true })); //=\u003e 'foo [1]'\n```\n\n## Examples\n\n### Windows path increments\n\nAll of the following would return `foo`\n\n```js\nconsole.log(strip('foo (1)'));  \nconsole.log(strip('foo (2)'));  \nconsole.log(strip('foo (22)')); \n```\n\nAll of the following would return `foo.txt`\n\n```js\nconsole.log(strip('foo (1).txt'));  \nconsole.log(strip('foo (2).txt'));  \nconsole.log(strip('foo (22).txt')); \n```\n\n### MacOS path increments\n\nAll of the following would return `foo`\n\n```js\nconsole.log(strip('foo copy'));\nconsole.log(strip('foo copy 1'));\nconsole.log(strip('foo copy 2'));\nconsole.log(strip('foo copy 21'));\nconsole.log(strip('foo copy 219 copy 219'));\n```\n\nAll of the following would return `foo.txt`\n\n```js\nconsole.log(strip('foo copy.txt'));\nconsole.log(strip('foo copy 1.txt'));\nconsole.log(strip('foo copy 2.txt'));\nconsole.log(strip('foo copy 21.txt'));\nconsole.log(strip('foo copy 219 copy 219.txt'));\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(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.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 04, 2019._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fstrip-filename-increment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fstrip-filename-increment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fstrip-filename-increment/lists"}