Skip to content

Commit

Permalink
Restructuring and improvements (#2)
Browse files Browse the repository at this point in the history
* Move actual functionality into a lib

* Add test

* Add tap as devDependency

* Make tests cover suffix generation

* Added .travis.yml file

* Added environment to .travis.yml file

* Added tap to dependencies, removed env from .travis.yml

* Fix package.json

* misc fixes

* We can run under an older node

* Remove unused line

* Misc fixes

* Randomly add a suffix

* Remove tap from dependencies

* Removing travis (for now)
  • Loading branch information
rbanffy authored Dec 30, 2016
1 parent 51ddd37 commit a06e528
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 111 deletions.
97 changes: 2 additions & 95 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,9 @@
#! /usr/bin/env node

/* eslint no-console: ["error", { allow: ["log"] }] */

const getUsage = require('command-line-usage')
const commandLineArgs = require('command-line-args')

const first = [
'Candy',
'Cotton',
'Cross',
'Deity',
'Dropout',
'Feed',
'Fire',
'Gopher',
'Gourmet',
'Halux',
'Head',
'Howler',
'Irate',
'Iron',
'Jet',
'Junior',
'Loud',
'Maestro',
'Monkey',
'Night',
'Photo',
'Rage',
'School',
'Sierra',
'Somber',
'Souffle',
'Stucco',
'Surly',
'Swap',
'Tawdry',
'Tote',
'Trinity',
'Water',
'Wistful'
]

const second = [
' CTX',
' EBSR',
'Anglo',
'Auto',
'Beam',
'Bounce',
'Calendar',
'Chef',
'Cyclone',
'Entourage',
'Genesis',
'Ghostly',
'Ginsu',
'Gram',
'Jeep',
'Knave',
'Maestro',
'Master',
'Mint',
'Monk',
'Monkey',
'Montana',
'Mouth',
'Nebula',
'Picasso',
'Plow',
'Set',
'Sparrow',
'Spawn',
'Stand',
'Swap',
'Thorugh',
'Toll',
'Trinity',
'Typhon',
'Walk',
'Watch',
'Water',
'Witch',
'Yard'
]

const suffixes = ['HX', 'I', 'II', 'III', '4000', 'Hx9', '2.0']
const nsaname = require('./lib/nsaname.js')

const helpSections = [
{
Expand Down Expand Up @@ -116,19 +34,8 @@ const commandLineOptionDefinitions = [

const options = commandLineArgs(commandLineOptionDefinitions)

var getName = function () {
var nsaname = first[Math.floor(Math.random() * first.length)] +
second[Math.floor(Math.random() * second.length)]

if (Math.random() > 0.7) {
nsaname += ' ' +
suffixes[Math.floor(Math.random() * suffixes.length)]
}
return nsaname
}

if (options.help) {
console.log(usage)
} else {
console.log(getName())
console.log(nsaname.getNSAName(Math.random() > 0.7))
}
106 changes: 106 additions & 0 deletions lib/nsaname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const first = [
'Candy',
'Cotton',
'Cross',
'Deity',
'Dropout',
'Feed',
'Fire',
'Gopher',
'Gourmet',
'Halux',
'Head',
'Howler',
'Irate',
'Iron',
'Jet',
'Junior',
'Loud',
'Maestro',
'Monkey',
'Night',
'Photo',
'Rage',
'School',
'Sierra',
'Somber',
'Souffle',
'Stucco',
'Surly',
'Swap',
'Tawdry',
'Tote',
'Trinity',
'Water',
'Wistful'
]

const second = [
' CTX',
' EBSR',
'Anglo',
'Auto',
'Beam',
'Bounce',
'Calendar',
'Chef',
'Cyclone',
'Entourage',
'Genesis',
'Ghostly',
'Ginsu',
'Gram',
'Jeep',
'Knave',
'Maestro',
'Master',
'Mint',
'Monk',
'Monkey',
'Montana',
'Mouth',
'Nebula',
'Picasso',
'Plow',
'Set',
'Sparrow',
'Spawn',
'Stand',
'Swap',
'Thorugh',
'Toll',
'Trinity',
'Typhon',
'Walk',
'Watch',
'Water',
'Witch',
'Yard'
]

const suffixes = ['HX', 'I', 'II', 'III', '4000', 'Hx9', '2.0']

/**
* Returns a nice name for a secret project or tool.
*
* @return {string}
*/
function getNSAName (suffix = false) {
var nsaname = first[Math.floor(Math.random() * first.length)] +
second[Math.floor(Math.random() * second.length)]

if (suffix) {
nsaname += ' ' +
suffixes[Math.floor(Math.random() * suffixes.length)]
}
return nsaname
}

module.exports = {
getNSAName: getNSAName,
wordLists: {
first: first,
second: second,
suffixes: suffixes
}
}
40 changes: 24 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"name": "nsaname",
"version": "1.0.1",
"description": "Like petname, but for naming secret projects and tools.",
"main": "index.js",
"author": "Ricardo Banffy <[email protected]>",
"license": "Apache-2.0",
"bin": {
"nsaname": "index.js"
},
"dependencies": {
"command-line-args": ">=3.0.5",
"command-line-usage": ">=3.0.0"
},
"engines": {
"node": ">=0.12.18"
}
"name": "nsaname",
"version": "1.0.2",
"description": "Like petname, but for naming secret projects and tools.",
"main": "index.js",
"author": "Ricardo Banffy <[email protected]>",
"license": "Apache-2.0",
"bin": {
"nsaname": "index.js"
},

"dependencies": {
"command-line-args": ">=3.0.5",
"command-line-usage": ">=3.0.0",
},
"engines": {
"node": ">=6.9.0"
},
"repository": "https://github.com/rbanffy/nsaname.git",
"devDependencies": {
"tap": ">=8.0.1"
},
"scripts": {
"test": "tap test/*.js"
}
}
11 changes: 11 additions & 0 deletions test/name-generation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const tap = require('tap')
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 }))

name = nsaname.getNSAName(true)

tap.true(nsaname.wordLists.suffixes.some(function (n) { return name.indexOf(n) > -1 }))

0 comments on commit a06e528

Please sign in to comment.