Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
noodanee committed May 22, 2019
0 parents commit 4a2ea1b
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 0 deletions.
9 changes: 9 additions & 0 deletions data/accessories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = [
'Blank',
'Kurt',
'Prescription01',
'Prescription02',
'Round',
'Sunglasses',
'Wayfarers'
]
12 changes: 12 additions & 0 deletions data/clothes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = [
'BlazerShirt',
'BlazerSweater',
'CollarSweater',
'GraphicShirt',
'Graphics',
'Hoodie',
'Overall',
'ShirtCrewNeck',
'ShirtScoopNeck',
'ShirtVNeck'
]
17 changes: 17 additions & 0 deletions data/clothesColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = [
'Black',
'Blue01',
'Blue02',
'Blue03',
'Gray01',
'Gray02',
'Heather',
'PastelBlue',
'PastelGreen',
'PastelOrange',
'PastelRed',
'PastelYellow',
'Pink',
'Red',
'White'
]
13 changes: 13 additions & 0 deletions data/clothesGraphic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = [
'Skull',
'SkullOutline',
'Bat',
'Cumbia',
'Deer',
'Diamond',
'Hola',
'Selena',
'Pizza',
'Resist',
'Bear'
]
15 changes: 15 additions & 0 deletions data/eyebrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = [
'Angry',
'AngryNatural',
'Default',
'DefaultNatural',
'FlatNatural',
'RaisedExcited',
'RaisedExcitedNatural',
'SadConcerned',
'SadConcernedNatural',
'UnibrowNatural',
'UpDown',
'UpDownNatural',
'FrownNatural'
]
14 changes: 14 additions & 0 deletions data/eyes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = [
'Close',
'Cry',
'Default',
'Dizzy',
'EyeRoll',
'Happy',
'Hearts',
'Side',
'Squint',
'Surprised',
'Wink',
'WinkWacky'
]
8 changes: 8 additions & 0 deletions data/facialHair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
'Blank',
'BeardMedium',
'BeardLight',
'BeardMagestic',
'MoustacheFancy',
'MoustacheMagnum'
]
10 changes: 10 additions & 0 deletions data/facialHairColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
'Auburn',
'Black',
'Blonde',
'BlondeGolden',
'Brown',
'BrownDark',
'Platinum',
'Red'
]
12 changes: 12 additions & 0 deletions data/hairColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = [
'Auburn',
'Black',
'Blonde',
'BlondeGolden',
'Brown',
'BrownDark',
'PastelPink',
'Platinum',
'Red',
'SilverGray'
]
17 changes: 17 additions & 0 deletions data/hatColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = [
'Black',
'Blue01',
'Blue02',
'Blue03',
'Gray01',
'Gray02',
'Heather',
'PastelBlue',
'PastelGreen',
'PastelOrange',
'PastelRed',
'PastelYellow',
'Pink',
'Red',
'White'
]
14 changes: 14 additions & 0 deletions data/mouth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = [
'Concerned',
'Default',
'Disbelief',
'Eating',
'Grimace',
'Sad',
'ScreamOpen',
'Serious',
'Smile',
'Tongue',
'Twinkle',
'Vomit'
]
9 changes: 9 additions & 0 deletions data/skin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = [
'Tanned',
'Yellow',
'Pale',
'Light',
'Brown',
'DarkBrown',
'Black'
]
38 changes: 38 additions & 0 deletions data/top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = [
'NoHair',
'Eyepatch',
'Hat',
'Hijab',
'Turban',
'WinterHat1',
'WinterHat2',
'WinterHat3',
'WinterHat4',
'LongHairBigHair',
'LongHairBob',
'LongHairBun',
'LongHairCurly',
'LongHairCurvy',
'LongHairDreads',
'LongHairFrida',
'LongHairFro',
'LongHairFroBand',
'LongHairNotTooLong',
'LongHairShavedSides',
'LongHairMiaWallace',
'LongHairStraight',
'LongHairStraight2',
'LongHairStraightStrand',
'ShortHairDreads01',
'ShortHairDreads02',
'ShortHairFrizzle',
'ShortHairShaggy',
'ShortHairShaggyMullet',
'ShortHairShortCurly',
'ShortHairShortFlat',
'ShortHairShortRound',
'ShortHairShortWaved',
'ShortHairSides',
'ShortHairTheCaesar',
'ShortHairTheCaesarSidePart'
]
42 changes: 42 additions & 0 deletions generator/generateAvatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const accessories = require('./../data/accessories')
const clothes = require('./../data/clothes')
const clothesColor = require('./../data/clothesColor')
const clothesGraphic = require('./../data/clothesGraphic')
const eyebrows = require('./../data/eyebrow')
const eyes = require('./../data/eyes')
const facialHair = require('./../data/facialHair')
const facialHairColors = require('./../data/facialHairColor')
const hairColors = require('./../data/hairColor')
const hatColors = require('./../data/hatColor')
const mouth = require('./../data/mouth')
const skin = require('./../data/skin')
const top = require('./../data/top')

const getRandom = (length) => {
return Math.floor(Math.random() * length)
}

const generateRandomAvatar = (avatarType) => (fileType = '', width = '') => {
const accessory = accessories[getRandom(accessories.length)]
const facialHairStyle = facialHair[getRandom(facialHair.length)]
const facialHairColor = facialHairColors[getRandom(facialHairColors.length)]
const hatColor = hatColors[getRandom(hatColors.length)]
const hairColor = hairColors[getRandom(hairColors.length)]
const clothingColor = clothesColor[getRandom(clothesColor.length)]
const clothingGraphic = clothesGraphic[getRandom(clothesGraphic.length)]
const clothing = clothes[getRandom(clothes.length)]
const eyebrow = eyebrows[getRandom(eyebrows.length)]
const eyesStyle = eyes[getRandom(eyes.length)]
const mouthStyle = mouth[getRandom(mouth.length)]
const skinStyle = skin[getRandom(skin.length)]
const topStyle = top[getRandom(top.length)]

let avatarStyle = 'Transparent'
if (Math.floor(Math.random() * 2) === 1) {
avatarStyle = 'Circle'
}

return `https://avataaars.io/${fileType}/${width}?avatarStyle=${avatarType || avatarStyle}&topType=${topStyle}&accessoriesType=${accessory}&hairColor=${hairColor}&hatColor=${hatColor}&facialHairType=${facialHairStyle}&facialHairColor=${facialHairColor}&clotheType=${clothing}&clotheColor=${clothingColor}&graphicType=${clothingGraphic}&eyeType=${eyesStyle}&eyebrowType=${eyebrow}&mouthType=${mouthStyle}&skinColor=${skinStyle}`
}

module.exports = { generateRandomAvatar }
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { generateRandomAvatar } = require('./generator/generateAvatar')

module.exports = {
generateRandomAvatar
}


13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "generate-avataaars",
"version": "0.0.1",
"description": "An avataaars generator api base node.",
"main": "index.js",
"author": "Ruby Rose",
"license": "MIT",
"scripts": {
"test": "node test/index.js"
},
"devDependencies": {},
"dependencies": {}
}
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { generateRandomAvatar } = require('../generator/generateAvatar')

const avatar = generateRandomAvatar('Circle')('png', 200)

console.log(avatar)

0 comments on commit 4a2ea1b

Please sign in to comment.