nodupes
Prevent duplicate names by appending an incremented prefix.
Last updated 7 years ago by bpierre .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nodupes 
SYNC missed versions from official npm registry.

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

License

MIT

Current Tags

  • 0.1.0                                ...           latest (7 years ago)

2 Versions

  • 0.1.0                                ...           7 years ago
  • 0.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |