Skip to content

Commit

Permalink
Merge pull request #76 from mrstebo/feature/star-wars
Browse files Browse the repository at this point in the history
Feature/star wars
  • Loading branch information
mrstebo committed Apr 10, 2017
2 parents 9c13ef3 + 6226ce5 commit e5e10bd
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Contents
- [Faker.Name](doc/name.md)
- [Faker.Number](doc/number.md)
- [Faker.Placeholdit](doc/placeholdit.md)
- [Faker.StarWars](doc/star_wars.md)
- [Faker.Time](doc/time.md)

## Installing
Expand Down
172 changes: 172 additions & 0 deletions data/star-wars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"characters": [
"Padme Amidala",
"Jar Jar Binks",
"Borvo the Hutt",
"Darth Caedus",
"Boba Fett",
"Jabba the Hutt",
"Obi-Wan Kenobi",
"Darth Maul",
"Leia Organa",
"Sheev Palpatine",
"Kylo Ren",
"Darth Sidious",
"Anakin Skywalker",
"Luke Skywalker",
"Ben Solo",
"Han Solo",
"Darth Vader",
"Watto",
"Mace Windu",
"Yoda",
"Count Dooku",
"Sebulba",
"Qui-Gon Jinn",
"Chewbacca",
"Jango Fett",
"Lando Calrissian",
"Bail Organa",
"Wedge Antilles",
"Poe Dameron",
"Ki-Adi-Mundi",
"Nute Gunray",
"Panaka",
"Rune Haako"
],
"droids": [
"2-1B",
"4-LOM",
"ASP",
"B2-RP",
"B1",
"BD-3000",
"FA-4",
"GH-7",
"GNK",
"LM-432",
"ID9",
"11-4D",
"2-1B",
"327-T",
"4-LOM",
"B4-D4",
"NR-N99",
"C-3PO",
"R2-D2",
"BB-8",
"R2-Q5"
],
"planets": [
"Alderaan",
"Bespin",
"Coruscant",
"DQar",
"Dagobah",
"Endor",
"Geonosis",
"Hoth",
"Hosnian Prime",
"Jakku",
"Kamino",
"Kashyyyk",
"Lothal",
"Mustafar",
"Naboo",
"Sullust",
"Takodana",
"Tatooine",
"Utapau",
"Yavin"
],
"quotes": [
"Never tell me the odds!",
"Well, you said you wanted to be around when I made a mistake.",
"You will never find a more wretched hive of scum and villainy. We must be cautious.",
"Wars not make one great.",
"You do have your moments. Not many, but you have them.",
"Now, witness the power of this fully operational battle station.",
"No reward is worth this.",
"Shut him up or shut him down.",
"I have a bad feeling about this.",
"Who's the more foolish; the fool, or the fool who follows him?",
"Would somebody get this big walking carpet out of my way?",
"I find your lack of faith disturbing.",
"If they follow standard Imperial procedure, they'll dump their garbage before they go to light-speed.",
"Only at the end do you realize the power of the Dark Side.",
"Bounty hunters! We don't need this scum.",
"It's not impossible. I used to bullseye womp rats in my T-16 back home, they're not much bigger than two meters.",
"Strike me down, and I will become more powerful than you could possibly imagine.",
"You know, that little droid is going to cause me a lot of trouble.",
"If you're saying that coming here was a bad idea, I'm starting to agree with you.",
"You'll find I'm full of surprises!",
"Aren't you a little short for a Stormtrooper?",
"You are unwise to lower your defenses!",
"R2-D2, you know better than to trust a strange computer!",
"Truly wonderful, the mind of a child is.",
"That is why you fail.",
"A Jedi uses the Force for knowledge and defense, never for attack.",
"Adventure. Excitement. A Jedi craves not these things.",
"Judge me by my size, do you?",
"Fear is the path to the dark side... fear leads to anger... anger leads to hate... hate leads to suffering.",
"Do. Or do not. There is no try."
],
"species": [
"Ewok",
"Hutt",
"Gungan",
"Ithorian",
"Jawa",
"Neimoidian",
"Sullustan",
"Wookiee",
"Mon Calamari"
],
"vehicles": [
"V-Wing Fighter",
"ATT Battle Tank",
"Naboo N-1 Starfighter",
"Vulture Droid",
"Republic Cruiser",
"Naboo Royal Starship",
"Gungan Bongo Submarine",
"Flash Speeder",
"Trade Federation Battleship",
"Millennium Falcon",
"Sith Infiltrator",
"AT-ST Walker",
"TIE Bomber",
"Imperial Shuttle",
"Sandcrawler",
"TIE Interceptor",
"Speeder Bike",
"Death Star",
"AT-AT Walker",
"Imperial Star Destroyer",
"X-Wing Fighter"
],
"wookieWords": [
"wyaaaaaa",
"ruh",
"huewaa",
"muaa",
"mumwa",
"wua",
"ga",
"ma",
"ahuma",
"ooma",
"youw",
"kabukk",
"wyogg",
"gwyaaaag",
"roooarrgh",
"ur",
"ru",
"roo",
"hnn-rowr",
"yrroonn",
"nng",
"rarr"
]
}
17 changes: 17 additions & 0 deletions doc/star_wars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Faker.StarWars

```js
Faker.StarWars.character() //=> "Anakin Skywalker"

Faker.StarWars.droid() //=> "C-3PO"

Faker.StarWars.planet() //=> "Tatooine"

Faker.StarWars.quote() //=> "Aren’t you a little short for a Stormtrooper?"

Faker.StarWars.specie() //=> "Gungan"

Faker.StarWars.vehicle() //=> "Sandcrawler"

Faker.StarWars.wookieSentence() //=> "Yrroonn ru ooma roo ahuma ur roooarrgh hnn-rowr."
```
2 changes: 2 additions & 0 deletions src/faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as LoremFlickr from './faker/lorem-flickr';
import * as Name from './faker/name';
import * as Number from './faker/number';
import * as Placeholdit from './faker/placeholdit';
import * as StarWars from './faker/star-wars';
import * as Time from './faker/time';

export default {
Expand All @@ -21,5 +22,6 @@ export default {
Name,
Number,
Placeholdit,
StarWars,
Time
};
38 changes: 38 additions & 0 deletions src/faker/star-wars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import data from '../../data/star-wars.json';
import { randomNumber, itemFromCollection } from '../utils/random';

export function character() {
return itemFromCollection(data['characters']);
}

export function droid() {
return itemFromCollection(data['droids']);
}

export function planet() {
return itemFromCollection(data['planets']);
}

export function quote() {
return itemFromCollection(data['quotes']);
}

export function specie() {
return itemFromCollection(data['species']);
}

export function vehicle() {
return itemFromCollection(data['vehicles']);
}

export function wookieSentence() {
return capitalize(
[...Array(randomNumber(1, 10)).keys()]
.map(_ => itemFromCollection(data['wookieWords']))
.join(' ') + itemFromCollection(['.', '?', '!'])
);
}

function capitalize(text) {
return text.replace(/\b\w/, x => x.toUpperCase());
}
6 changes: 6 additions & 0 deletions test/faker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ describe('#Faker', () => {
});
});

describe('#StarWars', () => {
it('should return an object', () => {
expect(Faker.StarWars).to.be.a('object');
});
});

describe('#Time', () => {
it('should return an object', () => {
expect(Faker.Time).to.be.a('object');
Expand Down
73 changes: 73 additions & 0 deletions test/faker/star-wars.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';
const expect = require('chai').expect;
const StarWars = require('../../src/faker/star-wars');
const data = require('../../data/star-wars.json');

describe('StarWars', () => {
describe('#character', () => {
it('should return a character', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.character()).to.be.oneOf(data['characters']);
});
});
});

describe('#droid', () => {
it('should return a droid', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.droid()).to.be.oneOf(data['droids']);
});
});
});

describe('#planet', () => {
it('should return a planet', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.planet()).to.be.oneOf(data['planets']);
});
});
});

describe('#quote', () => {
it('should return a quote', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.quote()).to.be.oneOf(data['quotes']);
});
});
});

describe('#specie', () => {
it('should return a specie', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.specie()).to.be.oneOf(data['species']);
});
});
});

describe('#vehicle', () => {
it('should return a vehicle', () => {
[...Array(100).keys()].forEach(_ => {
expect(StarWars.vehicle()).to.be.oneOf(data['vehicles']);
});
});
});

describe('#wookieSentence', () => {
it('should return wookie words', () => {
StarWars.wookieSentence()
.split(/(?:\s|[.?!])/) // remove endings
.filter(x => x)
.forEach(word => {
expect(word.toLowerCase()).to.be.oneOf(data['wookieWords']);
});
});

it('should start with a capital letter', () => {
expect(StarWars.wookieSentence()).to.match(/^[A-Z]/);
});

it('should end with period, question mark or explanation mark', () => {
expect(StarWars.wookieSentence()).to.match(/[.?!]$/);
});
});
});

0 comments on commit e5e10bd

Please sign in to comment.