Skip to content

Commit

Permalink
Prettier!
Browse files Browse the repository at this point in the history
TODO: Must implement CI tests to enforce style! (See #1)
  • Loading branch information
stemail23 committed Oct 25, 2018
1 parent 8e59558 commit fb80bd1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const adjectives = require('./adjectives.json');
const nouns = require('./nouns.json');

function findLengths(items) {
const lengths = [3,4,5,6,7,8,9];
const lengths = [3, 4, 5, 6, 7, 8, 9];
const response = {};
items.forEach(function(item) {
lengths.forEach(function(length) {
Expand All @@ -16,17 +16,19 @@ function findLengths(items) {
return response;
}

adjectives.sort((a, b) => a.length === b.length ? a.localeCompare(b) : a.length - b.length);
adjectives.sort((a, b) => (a.length === b.length ? a.localeCompare(b) : a.length - b.length));
const adjectiveLengths = findLengths(adjectives);
nouns.sort((a, b) => a.length === b.length ? a.localeCompare(b) : a.length - b.length);
nouns.sort((a, b) => (a.length === b.length ? a.localeCompare(b) : a.length - b.length));
const nounLengths = findLengths(nouns);

function codenameParticles(options) {
if (!options || typeof options !== 'object') {
options = {};
}
options.maxItemChars = options.maxItemChars > 0 ? Math.max(3, options.maxItemChars) : 0;
if (options.maxItemChars > 9) { options.maxItemChars = 0; }
if (options.maxItemChars > 9) {
options.maxItemChars = 0;
}
options.adjectiveCount = options.adjectiveCount || 1;
options.seed = (options.seed || '').toString();
options.hashAlgorithm = options.hashAlgorithm || 'md5';
Expand All @@ -35,8 +37,12 @@ function codenameParticles(options) {
const useNouns = options.maxItemChars > 0 ? nouns.slice(0, nounLengths[options.maxItemChars]) : nouns;
const useAdjectives = options.maxItemChars > 0 ? adjectives.slice(0, adjectiveLengths[options.maxItemChars]) : adjectives;
const particles = [useNouns];
for (let i = 0; i < options.adjectiveCount; i++) { particles.push(useAdjectives); }
const totalWords = bigInt(useAdjectives.length).pow(options.adjectiveCount).multiply(bigInt(useNouns.length));
for (let i = 0; i < options.adjectiveCount; i++) {
particles.push(useAdjectives);
}
const totalWords = bigInt(useAdjectives.length)
.pow(options.adjectiveCount)
.multiply(bigInt(useNouns.length));

const hash = crypto.createHash(options.hashAlgorithm);
hash.update(options.seed);
Expand Down

0 comments on commit fb80bd1

Please sign in to comment.