Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwhor committed Aug 1, 2019
0 parents commit 5a823a5
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
env.json
.DS_Store
node_modules/
9 changes: 9 additions & 0 deletions API.md
@@ -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.
10 changes: 10 additions & 0 deletions README.md
@@ -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.
47 changes: 47 additions & 0 deletions functions/__main__.js
@@ -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]]
}
}
};
4 changes: 4 additions & 0 deletions package.json
@@ -0,0 +1,4 @@
{
"name": "",
"author": ""
}

0 comments on commit 5a823a5

Please sign in to comment.