mw-dict
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -7,2 +7,4 @@ const axios = require('axios') | ||
const SOUND_URL = 'http://media.merriam-webster.com/soundc11' | ||
const POPULARITY_URL = | ||
'https://stats.merriam-webster.com/pop-score-redesign.php' | ||
@@ -237,2 +239,26 @@ class Sense { | ||
function lookupPopularity(word) { | ||
let url = `${POPULARITY_URL}?word=${word}` | ||
return axios | ||
.get(url) | ||
.then(resp => resp.data) | ||
.then(s => { | ||
let label | ||
for (let line of s.split('\n')) { | ||
line = line.trim() | ||
if (line.startsWith('label')) { | ||
let matches = line.match(/'(.+)'/) | ||
if (matches) { | ||
label = matches[1] | ||
break | ||
} | ||
} | ||
} | ||
if (!label) { | ||
throw new Error('Popularity not found') | ||
} | ||
return label | ||
}) | ||
} | ||
class Dictionary { | ||
@@ -247,3 +273,4 @@ constructor(key) { | ||
const url = `${this.url}${word}?key=${this.key}` | ||
return axios | ||
const $popularity = lookupPopularity(word).catch(err => null) | ||
const $results = axios | ||
.get(url) | ||
@@ -263,3 +290,3 @@ .then(resp => resp.data) | ||
return { | ||
word: wordText.length? wordText: word, | ||
word: wordText.length ? wordText : word, | ||
functional_label: textContent(entry.getElementsByTagName('fl')[0]), | ||
@@ -271,2 +298,13 @@ pronunciation: soundWalker(entry.getElementsByTagName('sound')[0]), | ||
}) | ||
return Promise.all([ | ||
$popularity, | ||
$results | ||
]).then(([popularity, results]) => { | ||
return results.map(result => { | ||
if (result.word === word) { | ||
return Object.assign(result, { popularity }) | ||
} | ||
return result | ||
}) | ||
}) | ||
} | ||
@@ -273,0 +311,0 @@ } |
{ | ||
"name": "mw-dict", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,4 +7,5 @@ # mw-dict | ||
* Exports word senses with hierarchy (sense, subsense...) | ||
* Outputs pronunciation url | ||
* Outputs pronunciation audio url | ||
* Cares about functional label, synonyms, verbal illustrations ... | ||
* Outputs popularity | ||
@@ -11,0 +12,0 @@ Preview: |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
99119
513
74
0