Socket
Socket
Sign inDemoInstall

mw-dict

Package Overview
Dependencies
5
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

42

lib/dictionary.js

@@ -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 @@ }

2

package.json
{
"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:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc