endpoints/declension/index.js
function getDeclensions(callback, providedParams) {
  const params = Object.assign({}, providedParams)
  request.get(params, (err, res, body) => {
    if (err || res.statusCode !== 200) {
      return res.status(500).json({
        error: 'A request to dev.phpbin.ja.is resulted in a error',
      })
    }

    let $
    const sanitisedBody = body.replace(/<!--[\s\S]*?-->/g, '')

    try {
      $ = cheerio.load(sanitisedBody)
    } catch (error) {
      return res.status(500).json({
        error: 'Parsing the data from dev.phpbin.ja.is resulted in a error',
        moreinfo: error,
      })
    }

    // Links mean results!
    const result = $('a')

    // more than 1 result from request (ex: 'hús')
    if (result.length > 1) {
      // call recursively again with new url
      const id = result[0].attribs.on_click.match(/\d+/)[0]
      baseUrl.query = { id }
      params.url = url.format(baseUrl)
      return getDeclensions(callback, params)
    }

    // else just call func to return data
    return callback($)
  })
}
function getDeclensions(callback, providedParams) {
  const params = Object.assign({}, providedParams)
  request.get(params, (err, res, body) => {
    if (err || res.statusCode !== 200) {
      return res.status(500).json({
        error: 'A request to dev.phpbin.ja.is resulted in a error',
      })
    }

    let $
    const sanitisedBody = body.replace(/<!--[\s\S]*?-->/g, '')

    try {
      $ = cheerio.load(sanitisedBody)
    } catch (error) {
      return res.status(500).json({
        error: 'Parsing the data from dev.phpbin.ja.is resulted in a error',
        moreinfo: error,
      })
    }

    // Links mean results!
    const result = $('a')

    // more than 1 result from request (ex: 'hús')
    if (result.length > 1) {
      // call recursively again with new url
      const id = result[0].attribs.on_click.match(/\d+/)[0]
      baseUrl.query = { id }
      params.url = url.format(baseUrl)
      return getDeclensions(callback, params)
    }

    // else just call func to return data
    return callback($)
  })
}
function getDeclensions ( callback , providedParams ) { const params = Object . assign ( { } , providedParams ) request . get ( params , ( err , res , body ) => { if ( err || res . statusCode !== 200 ) { return res . status ( 500 ) . json ( { error : 'A request to dev.phpbin.ja.is resulted in a error' , } ) } let $ const sanitisedBody = body . replace ( / <!--[\s\S]*?--> / g , '' ) try { $ = cheerio . load ( sanitisedBody ) } catch ( error ) { return res . status ( 500 ) . json ( { error : 'Parsing the data from dev.phpbin.ja.is resulted in a error' , moreinfo : error , } ) } // Links mean results! const result = $ ( 'a' ) // more than 1 result from request (ex: 'hús') if ( result . length > 1 ) { // call recursively again with new url const id = result [ 0 ] . attribs . on_click . match ( / \d+ / ) [ 0 ] baseUrl . query = { id } params . url = url . format ( baseUrl ) return getDeclensions ( callback , params ) } // else just call func to return data return callback ( $ ) } ) }
return permutation of a given word
return permutation of a given word