-
Notifications
You must be signed in to change notification settings - Fork 0
/
words_processer.js
41 lines (33 loc) · 1.12 KB
/
words_processer.js
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
36
37
38
39
40
//TODO: encrypt this
const token = {
"method": "GET",
"headers": {
"x-rapidapi-host": "wordsapiv1.p.rapidapi.com",
"x-rapidapi-key": "c2704e88abmshc38f6f7d141ce05p1ee4cfjsn103a6e176ef9"
}
}
const methods = ["synonyms"]
let getSynonyms = async function (str, method) {
return new Promise((resolve) => {
const http = new XMLHttpRequest();
http.addEventListener("readystatechange", function () {
if (this.readyState == this.DONE) {
let json = JSON.parse(this.responseText)
resolve(json[method])
}
})
http.open("GET", "https://wordsapiv1.p.rapidapi.com/words/" + str + "/" + method)
http.setRequestHeader("x-rapidapi-host", "wordsapiv1.p.rapidapi.com");
http.setRequestHeader("x-rapidapi-key", "c2704e88abmshc38f6f7d141ce05p1ee4cfjsn103a6e176ef9")
http.send()
})
}
async function search(str) {
let res = []
for (let i = 0; i < methods.length; i++) {
res = res.concat(await getSynonyms(str, methods[i]))
}
return res
}
console.log("123")
console.log(await search("dog"))