All files / src utils.js

100% Statements 11/11
75% Branches 3/4
100% Functions 4/4
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x   1x                         1x 8x 8x 64x 64x   8x         1x 1x     1x          
const axios = require('axios')
 
const gitmojiApiClient = axios.create({
  baseURL: 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master',
  timeout: 5000,
  headers: {},
  params: {}
})
 
/**
* @param {Object} cli - The cli object that returns meow()
* @param {Object} cli.flags - The cli flags matched against the input
* @param {Object} options - The mapping for a command to the gitmoji-cli method
* @return {Function}
**/
const findGitmojiCommand = (cli, options) => {
  const flags = cli.flags
  const matchedFlagsWithInput = Object.keys(flags)
    .map((flag) => flags[flag] && flag)
    .filter((flag) => options[flag])
 
  return options[matchedFlagsWithInput]
    ? options[matchedFlagsWithInput]()
    : cli.showHelp()
}
 
const inputCountTransformer = (input, maxLength) => {
  return `[${input.length}/${maxLength}]: ${input}`
}
 
module.exports = {
  findGitmojiCommand,
  gitmojiApiClient,
  inputCountTransformer
}