Skip to content
This repository was archived by the owner on May 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ generate({ words: 4, number: true }).dashed; // 'breakable-judicious-luxuriant-t

generate({ words: 2, alliterative: true }).spaced; // 'elegant experience'

generate({ words: 2, alliterative: 'c' }).dashed; // 'crabby-cactus'

```

##API
Expand All @@ -43,7 +45,7 @@ The `options` argument object can have properties

* **words** (number) - Number of words generated (excluding number). All words will be adjectives, except the last one which will be a noun. Defaults to **2**.
* **number** (boolean) - Whether a numeric suffix is generated or not. The number is between 1 - 9999, both inclusive. Defaults to **false**.
* **alliterative** (boolean) - Whether to output words beginning with the same letter or not. Defaults to **false**.
* **alliterative** (boolean/string) - Whether to output words beginning with the same letter or not. If a string is passed, returns only words starting with that character. Defaults to **false**.

`generate({ words: 3 })` will return:
```javascript
Expand Down Expand Up @@ -72,6 +74,15 @@ The `options` argument object can have properties
}
```

`generate({ words: 2, number: false, alliterative: 'c' })` will return:
```javascript
{
raw: [ 'crabby', 'cactus' ],
dashed: 'crabby-cactus',
spaced: 'crabby cactus'
}
```

##Tests
To run tests locally:
```
Expand Down
9 changes: 9 additions & 0 deletions spec/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ describe('generator', function () {
expect(_.includes(nouns, projName.raw[1])).to.be(true);
expect(projName.raw[0].substring(0, 1).toLowerCase() === projName.raw[1].substring(0, 1).toLowerCase()).to.be(true);
});

it('with {words: 2, number: false, alliterative: "d"}, has 1 adjective and 1 noun beginning with the letter "d"', function() {
projName = generate({words: 2, number: false, alliterative: 'd'});
expect(projName.raw.length).to.be(2);
expect(_.includes(adjectives, projName.raw[0])).to.be(true);
expect(_.includes(nouns, projName.raw[1])).to.be(true);
expect(projName.raw[0].substring(0, 1).toLowerCase() === 'd').to.be(true);
expect(projName.raw[1].substring(0, 1).toLowerCase() === 'd').to.be(true);
});
});
});

Expand Down
8 changes: 6 additions & 2 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ function getRawProjName(options) {
_.times(options.words - 1, function () {
if (options.alliterative && raw.length)
raw.push(_.sample(getAlliterativeMatches(adjectives, raw[0].substring(0, 1))));
else
raw.push(_.sample(adjectives).toLowerCase());
else {
if (typeof options.alliterative === 'string' && options.alliterative.length)
raw.push(_.sample(getAlliterativeMatches(adjectives, options.alliterative.substring(0, 1))));
else
raw.push(_.sample(adjectives).toLowerCase());
}
});

if (options.alliterative)
Expand Down