Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a823a5
Showing
7 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
env.json | ||
.DS_Store | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# API Documentation | ||
|
||
Welcome to the Pokefusion Connector Example API! | ||
|
||
This file should contain documentation introducing your API to **end-users**. | ||
It will display on your service's [Standard Library](https://stdlib.com/) | ||
documentation page if you choose to publish it. | ||
|
||
Usage examples and additional information around calling your API belong here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# README | ||
[<img src="https://deploy.stdlib.com/static/images/deploy.svg" width="192">](https://deploy.stdlib.com/) | ||
|
||
This is the README for you API. It is intended to guide other developers on | ||
**internal implementation** of your code, like how to set up a workflow project | ||
or connector API. It **will not** be displayed in your | ||
[Standard Library](https://stdlib.com/) documentation. | ||
|
||
You can include an **Deploy to Build on Standard Library** button for GitHub, | ||
as displayed above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const POKEMON = require('../reference/pokemon.json'); | ||
|
||
/** | ||
* Fuse any two Pokemon of the original (some may say only) 151. | ||
* @param {string} headPokemon The name of the first Pokemon to fuse as a head. Will randomize if not provided. | ||
* @param {string} bodyPokemon The name of the second Pokemon to fuse as a body. Will randomize if not provided. | ||
* @returns {object} pokefusion The fused Pokemon | ||
* @ {string} name The name of the fused Pokemon | ||
* @ {string} image_url The URL to an image of the fused Pokemon | ||
* @ {object} fused The Pokemon fusion | ||
* @ {string} head The Pokemon used in the head of the fusion | ||
* @ {string} body The Pokemon used in the body of the fusion | ||
*/ | ||
module.exports = async (headPokemon = null, bodyPokemon = null) => { | ||
|
||
let pokemon = [headPokemon, bodyPokemon] | ||
.map(name => { | ||
name = (name || '') | ||
.toLowerCase() | ||
.replace(/\s*/gi, '') | ||
.replace(/\(m\)/gi, '♂') | ||
.replace(/\(f\)/gi, '♀') | ||
return POKEMON.names.findIndex(n => n.toLowerCase().replace(/\s*/gi, '') === name); | ||
}); | ||
|
||
if (!!headPokemon && pokemon[0] === -1) { | ||
throw new Error(`Invalid headPokemon: "${headPokemon}" not found.`); | ||
} else if (!!bodyPokemon && pokemon[1] === -1) { | ||
throw new Error(`Invalid bodyPokemon: "${bodyPokemon}" not found.`); | ||
} | ||
|
||
pokemon = pokemon.map(n => n > -1 ? n : Math.floor(Math.random() * 151)); | ||
let prefix = POKEMON.prefixes[pokemon[0]]; | ||
let suffix = POKEMON.suffixes[pokemon[1]]; | ||
if (prefix.endsWith(' ')) { | ||
suffix = suffix[0].toUpperCase() + suffix.substr(1); | ||
} | ||
|
||
return { | ||
name: `${prefix}${suffix}`, | ||
image_url: `https://images.alexonsager.net/pokemon/fused/${pokemon[1] + 1}/${pokemon[1] + 1}.${pokemon[0] + 1}.png`, | ||
fused: { | ||
head: POKEMON.names[pokemon[0]], | ||
body: POKEMON.names[pokemon[1]] | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "", | ||
"author": "" | ||
} |
Oops, something went wrong.