Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Prevent duplicate names by appending an incremented prefix.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

nodupes

Prevent duplicate names by appending an incremented suffix.

Build Status

nodupes illustration

Examples

example/nodupes.js

var nodupes = require('nodupes')();
var names = ['name', 'name', 'othername', 'name', 'othername'];
names.forEach(function(name) {
  console.log( nodupes(name) );
});

Output:

$ node example/nodupes.js
name
name-2
othername
name-3
othername-2

Usage

var nodupes = require('nodupes');

var nd = nodupes(options)

Call nodupes() to get a new nodupes function, with its own index and options.

Options:

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

$ npm install nodupes

License

MIT

Credits

Illustration made by Raphaël Bastide with scri.ch.

Something went wrong with that request. Please try again.