Skip to content

Commit

Permalink
Add new swtiches (#3)
Browse files Browse the repository at this point in the history
* Add Wikipedia reference

* Add new switches

* Remove troublesome words

* Version bump

* Update README

* Add tests for new switches
  • Loading branch information
rbanffy authored Dec 31, 2016
1 parent 364d7e8 commit 8a1c981
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
42 changes: 40 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
}
]
}
Expand All @@ -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
}
]

Expand All @@ -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)
}
12 changes: 7 additions & 5 deletions lib/nsaname.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Names derived from https://en.wikipedia.org/wiki/NSA_ANT_catalog

const first = [
'Candy',
'Cotton',
Expand Down Expand Up @@ -36,8 +38,6 @@ const first = [
]

const second = [
' CTX',
' EBSR',
'Anglo',
'Auto',
'Beam',
Expand Down Expand Up @@ -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 += ' ' +
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
14 changes: 11 additions & 3 deletions test/name-generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8a1c981

Please sign in to comment.