From 8a1c98181563299da32e7341ab52b6de60937d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20B=C3=A1nffy?= Date: Sat, 31 Dec 2016 23:28:21 +0000 Subject: [PATCH] Add new swtiches (#3) * Add Wikipedia reference * Add new switches * Remove troublesome words * Version bump * Update README * Add tests for new switches --- README.md | 19 ++++++++++++++----- index.js | 42 +++++++++++++++++++++++++++++++++++++++-- lib/nsaname.js | 12 +++++++----- package.json | 2 +- test/name-generation.js | 14 +++++++++++--- 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 05446b3..5304511 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,21 @@ NSA Name Options - --help Print this usage guide. + --help Print this usage guide. + --lowercase Output in lowercase. + --no-suffix Don't add a suffix. + --hostname Output a sensible hostname. $ nsaname -MaestroEntourage +SchoolSwap HX $ nsaname -IronGenesis 4000 -$ nsaname -PhotoGinsu 2.0 +WistfulMonkey 4000 +$ nsaname -l +headset iii +$ nsaname -n +SchoolJeep +$ nsaname -h +swap-gram +$ nsaname -h +cotton-witch ``` diff --git a/index.js b/index.js index c6201e3..d5cf324 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,18 @@ const helpSections = [ { name: 'help', description: 'Print this usage guide.' + }, + { + name: 'lowercase', + description: 'Output in lowercase.' + }, + { + name: 'no-suffix', + description: "Don't add a suffix." + }, + { + name: 'hostname', + description: 'Output a sensible hostname.' } ] } @@ -26,9 +38,26 @@ const usage = getUsage(helpSections) const commandLineOptionDefinitions = [ { name: 'help', + type: Boolean, + defaultValue: false + }, + { + name: 'lowercase', + alias: 'l', + type: Boolean, + defaultValue: false + }, + { + name: 'no-suffix', + alias: 'n', + type: Boolean, + defaultValue: false + }, + { + name: 'hostname', alias: 'h', type: Boolean, - defaultOption: false + defaultValue: false } ] @@ -37,5 +66,14 @@ const options = commandLineArgs(commandLineOptionDefinitions) if (options.help) { console.log(usage) } else { - console.log(nsaname.getNSAName(Math.random() > 0.7)) + var name = nsaname.getNSAName( + !(options.hostname || options['no-suffix']), + options.hostname ? '-' : '') + if (options.hostname) { + name.replace(' ', '-') + } + if (options.lowercase || options.hostname) { + name = name.toLowerCase() + } + console.log(name) } diff --git a/lib/nsaname.js b/lib/nsaname.js index 00be489..2d15ece 100644 --- a/lib/nsaname.js +++ b/lib/nsaname.js @@ -1,3 +1,5 @@ +// Names derived from https://en.wikipedia.org/wiki/NSA_ANT_catalog + const first = [ 'Candy', 'Cotton', @@ -36,8 +38,6 @@ const first = [ ] const second = [ - ' CTX', - ' EBSR', 'Anglo', 'Auto', 'Beam', @@ -78,16 +78,18 @@ const second = [ 'Yard' ] -const suffixes = ['HX', 'I', 'II', 'III', '4000', 'Hx9', '2.0'] +const suffixes = [ + 'HX', 'I', 'II', 'III', '2000', '4000', '9000', 'Hx9', '2.0', '3.0' +] /** * Returns a nice name for a secret project or tool. * * @return {string} */ -function getNSAName (suffix = false) { +function getNSAName (suffix = false, separator = '') { var nsaname = first[Math.floor(Math.random() * first.length)] + - second[Math.floor(Math.random() * second.length)] + separator + second[Math.floor(Math.random() * second.length)] if (suffix) { nsaname += ' ' + diff --git a/package.json b/package.json index 0363207..337d0a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nsaname", - "version": "1.0.2a", + "version": "1.0.3", "description": "Like petname, but for naming secret projects and tools.", "main": "index.js", "author": "Ricardo Banffy ", diff --git a/test/name-generation.js b/test/name-generation.js index 746d001..c361449 100644 --- a/test/name-generation.js +++ b/test/name-generation.js @@ -3,9 +3,17 @@ const nsaname = require('../lib/nsaname.js') var name = nsaname.getNSAName() -tap.true(nsaname.wordLists.first.some(function (n) { return name.indexOf(n) > -1 })) -tap.true(nsaname.wordLists.second.some(function (n) { return name.indexOf(n) > -1 })) +// Test default behavior. +tap.true(nsaname.wordLists.first.some( + function (n) { return name.indexOf(n) > -1 })) +tap.true(nsaname.wordLists.second.some( + function (n) { return name.indexOf(n) > -1 })) +// Test with suffixes name = nsaname.getNSAName(true) +tap.true(nsaname.wordLists.suffixes.some( + function (n) { return name.indexOf(n) > -1 })) -tap.true(nsaname.wordLists.suffixes.some(function (n) { return name.indexOf(n) > -1 })) +// Test separator +name = nsaname.getNSAName(false, '-') +tap.true(name.indexOf('-') > -1)