Skip to content

Commit

Permalink
Fixed regex to include names with dashes and no split up words after …
Browse files Browse the repository at this point in the history
…dashes. Added picture to read me and adjust the user story slightly.

#14
#22
#39
#57
#64
  • Loading branch information
mineshmshah committed Jul 21, 2017
1 parent 7373437 commit 9fa9ea7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

## Why
### User Persona
Ash __loves__ Pokemon. And we mean LOVES. He can't for the life of him remember let alone spell half of their names. Poor Ash.
Ash __loves__ Pokemon. And we mean LOVES. After 20 years he has finally caught 'em all..until the next generation. He can't for the life of him remember let alone spell half of their names. Even worse he cant tell his balls apart! Poor Ash.
Currently he has to look in his Pokédex which is totally unreliable. He feels like he's living in the '90s, still using his Pokedex. He wishes he could just search using his smartphone for any Pokemon name and find the crucial stats he needs to become a true Pokemon master.

### User Journey
Ash would simply go to (insert URL) and type the starting letter of the Pokemon he wants information on. Hey Presto! The auto complete will populate the drop down with the top 10 matching Pokemon to the letters he can remember.
He can then select the one he wants and press go to release the Pokémon on the grass to get some nice fresh air!

## What
We're creating a Pokemon auto complete search bar to help Ash.
We're creating a Pokemon auto complete search bar to help Ash find the pokemon he wants.

## How
The main tasks we had to do were:
Expand All @@ -26,7 +27,7 @@ We did this by blah blah blah .....
- [ ] Add Poké theme tune and color scheme because we want to be the very best.

## How did we split up work?

![alt text](media/architecture_sketch.JPG)
## How did you pair?

## What did you learn?
Expand Down
6 changes: 3 additions & 3 deletions data/pokemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Ferroseed
Ferrothorn
Finneon
Flaaffy
Flabébé
Flabebe
Flareon
Fletchinder
Fletchling
Expand Down Expand Up @@ -399,15 +399,15 @@ Mienshao
Mightyena
Milotic
Miltank
Mime Jr.
Mime-Jr
Minccino
Minun
Misdreavus
Mismagius
Moltres
Monferno
Mothim
Mr. Mime
Mr-Mime
Mudkip
Muk
Munchlax
Expand Down
Binary file added media/architecture_sketch.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ var insertPokeInfo = function(err, response) {
var form = document.getElementById('js-pokeForm');
form.addEventListener('submit', function(event) {
event.preventDefault();
var url = 'https://pokeapi.co/api/v2/pokemon/' + domInput.value.toLowerCase();
var url = 'http://pokeapi.co/api/v2/pokemon/' + domInput.value.toLowerCase();
pokeRequest(url, insertPokeInfo);
});
25 changes: 13 additions & 12 deletions src/search.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@

const path = require('path');
const fs = require('fs');
const searchFunction = function(file, query, number, callback) {

const searchFunction = function (file, query, number, callback) {
const fileSplit = file.split('/');
const filePath = path.join(__dirname, '..', ...fileSplit);
fs.readFile(filePath, (error, fileResult) => {
if(error){
if (error) {
console.log(error);
return;
}
const fileString = fileResult.toString();
console.log(typeof fileString);
console.log('end');
//below regex searches for any word following the entered string
const regEx = new RegExp('\\b(' +query+ ')\\w*', 'gi');
const fileString = fileResult.toString();
console.log(typeof fileString);
console.log('end');
// below regex searches for any word following the entered string
const regEx = new RegExp(`\\b(${query}).*\[a-z-2]`, 'gi');// /.*\s*:\s*.*/g
// match takes reg expression and pulls out all the matches from the stringified text file
const pokeMatches = fileString.match(regEx);
const pokeTenMatches = pokeMatches ? pokeMatches.slice(0, number) : '';
callback(null, JSON.stringify({pokeTenMatches}))
})
};
const pokeMatches = fileString.match(regEx);
const pokeTenMatches = pokeMatches ? pokeMatches.slice(0, number) : '';
callback(null, JSON.stringify({ pokeTenMatches }));
});
};

module.exports = searchFunction;

0 comments on commit 9fa9ea7

Please sign in to comment.