import * as R from 'ramda'

const someSymbolsDelete = R.replace(/[(!?.,)]/g, '')
const fixDoubleSpaces = R.replace(/ {2}/g, ' ')
const someSymbolsToHyphens = R.replace(/[/ ’]/g, '-')

const composeQuery = word => {
    const escapedWord = R.pipe(
        R.toLower,
        someSymbolsDelete,
        R.trim,
        fixDoubleSpaces,
        someSymbolsToHyphens
    )(word)

    const dictionaryUrl = `http://www.ldoceonline.com/dictionary/${escapedWord}`

    const queryUrl = `https://query.yahooapis.com/v1/public/yql?q=${encodeURIComponent(
        `SELECT * FROM htmlstring WHERE url="${dictionaryUrl}"`
    )}&env=${encodeURIComponent('store://datatables.org/alltableswithkeys')}`

    return queryUrl
}

export default composeQuery

@@ -400,16 +400,17 @@
  = %60http
+s
 ://www.l
@@ -486,205 +486,51 @@
 s://
-query.yahooapis.com/v1/public/yql?q=$%7BencodeURIComponent(%0A        %60SELECT * FROM htmlstring WHERE url=%22$%7BdictionaryUrl%7D%22%60%0A    )%7D&env=$%7BencodeURIComponent('store://datatables.org/alltableswithkeys')
+cors-anywhere.herokuapp.com/$%7BdictionaryUrl
 %7D%60%0A%0A

switch from yahooapis to cors-anywhere