https://github.com/bpierre/nodupes
Prevent duplicate names by appending an incremented prefix.
https://github.com/bpierre/nodupes
Last synced: 12 months ago
JSON representation
Prevent duplicate names by appending an incremented prefix.
- Host: GitHub
- URL: https://github.com/bpierre/nodupes
- Owner: bpierre
- License: mit
- Created: 2013-11-11T17:41:29.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-02-13T17:26:46.000Z (over 7 years ago)
- Last Synced: 2025-06-13T10:56:11.365Z (12 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nodupes
Prevent duplicate names by appending an incremented suffix.
[](https://travis-ci.org/bpierre/nodupes)

## Examples
### example/nodupes.js
```javascript
var nodupes = require('nodupes')();
var names = ['name', 'name', 'othername', 'name', 'othername'];
names.forEach(function(name) {
console.log( nodupes(name) );
});
```
Output:
```shell
$ node example/nodupes.js
name
name-2
othername
name-3
othername-2
```
## Usage
```javascript
var nodupes = require('nodupes');
```
### var nd = nodupes(options)
Call `nodupes()` to get a new nodupes function, with its own index and options.
Options:
```javascript
var options = {
names: {}, // Load a pre-existing names index (see `nd.getNames()`).
suffixFirst: false, // Add a suffix on the first appearance of a name.
separator: '-' // Change the suffix separator.
};
```
### nd('name')
Returns the name with an appended suffix if needed.
### nd.getNames()
Returns the names index that you can pass to `nodupes()` with `options.names`.
## Installation
```shell
$ npm install nodupes
```
## License
[MIT](http://pierre.mit-license.org/)
## Credits
Illustration made by [Raphaël Bastide](http://raphaelbastide.com/) with [scri.ch](http://scri.ch/).