diff --git a/README.md b/README.md index d3f22bc..fdbd629 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ A name generator. Be sure to `.use()` some dictionaries afterward. Options may include: { - glue: '-' + capitalize: true, + noglue: true, } **generator.use(dictionary, options)** diff --git a/lib/moniker.js b/lib/moniker.js index bc4834d..74c84a0 100644 --- a/lib/moniker.js +++ b/lib/moniker.js @@ -77,11 +77,14 @@ Dictionary.prototype.choose = function() { function Generator(opt) { this.dicts = []; this.glue = (opt && opt.glue) || '-'; + this.capitalize = (opt && opt.capitalize) || false; + if (opt && opt.noglue) this.glue = ''; } Generator.prototype.choose = function() { var dicts = this.dicts, size = dicts.length; + capitalize = this.capitalize; if (size === 0) throw new Error('no available dictionaries.'); @@ -100,6 +103,9 @@ Generator.prototype.choose = function() { throw new Error('too many tries to find a unique word'); used[probe] = true; + + if (capitalize) probe = probe.charAt(0).toUpperCase() + probe.slice(1); + return probe; }); diff --git a/package.json b/package.json index b67c193..ba13290 100644 --- a/package.json +++ b/package.json @@ -3,5 +3,12 @@ "version": "0.1.2", "description": "Generate random names.", "author": "Ben Weaver ", - "main": "./lib/moniker" + "main": "./lib/moniker", + "scripts": { + "test": "mocha && eslint lib/ test/" + }, + "devDependencies": { + "eslint": "^1.1.0", + "mocha": "^2.2.5" + } } \ No newline at end of file diff --git a/test/moniker.js b/test/moniker.js index 79ba069..e83db13 100644 --- a/test/moniker.js +++ b/test/moniker.js @@ -1,14 +1,18 @@ var Assert = require('assert'), M = require('../lib/moniker'); -module.exports = { - 'the default generator works': function() { - Assert.equal(typeof M.choose(), 'string'); - }, - - 'names are random': function() { - var names = M.generator([M.adjective, M.noun], { maxSize: 7 }); - Assert.equal(typeof names.choose(), 'string'); - Assert.notEqual(names.choose(), names.choose()); - } -}; \ No newline at end of file +describe('all', function() { + it('the default generator works', function() { + var G = M.generator([M.adjective, M.noun], { maxSize: 7, capitalize: true }); + console.log(G); + var name = G.choose(); + console.log(name); + Assert.equal(typeof name, 'string'); + }); + it('names are random', function() { + var names = M.generator([M.adjective, M.noun], { maxSize: 7 }); + console.log(names); + Assert.equal(typeof names.choose(), 'string'); + Assert.notEqual(names.choose(), names.choose()); + }); +});