Skip to content

Commit

Permalink
added new id generator, removeDeadVariables, lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoverson committed May 12, 2020
1 parent 36bf39f commit 8e27b6b
Show file tree
Hide file tree
Showing 10 changed files with 4,907 additions and 70 deletions.
642 changes: 642 additions & 0 deletions src/adjectives.js

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/id-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,40 @@ const jsKeywords = Object
.filter(_ => _.name && _.klass.name === 'Keyword')
.map(_ => _.name);

const nouns = require('./nouns');
const adjectives = require('./adjectives');
const seedrandom = require('seedrandom');

exports.IdGenerator = class IdGenerator {
constructor(seed = 0) {
this.rng = seedrandom(0);

}

randomNoun() {
const index = Math.floor(this.rng() * nouns.length);
return nouns[index];
}

randomAdjective() {
const index = Math.floor(this.rng() * adjectives.length);
return adjectives[index];
}

next() {
const noun = this.randomNoun();

return `${this.randomAdjective()}${noun[0].toUpperCase()}${noun.slice(1)}`;
}

*[Symbol.iterator]() {
while (true) {
yield this.next();
}
}
}

exports.BasicIdGenerator = class BasicIdGenerator {
constructor(
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
reservedWords = jsKeywords
Expand Down
Loading

0 comments on commit 8e27b6b

Please sign in to comment.