nodupes
v0.1.0
Published
Prevent duplicate names by appending an incremented suffix.
Downloads
544
Readme
nodupes
Prevent duplicate names by appending an incremented prefix.
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.
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.
Installation
$ npm install nodupes