npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

word-definition

v2.1.6

Published

Grabs the definition of a word from the wiktionary - supported languages: english, french and german

Downloads

385

Readme

This node.js module provides a single function allowing to grab the definition of a word from the Wiktionary and return it in an object.

For instance the definition of "ride":

{
	"word": "ride",
	"category": "verb",
	"definition": "To transport oneself by sitting on and directing a horse, later also a bicycle etc."
}

It supports three languages: english, french and german.

It retrieves only the topmost definition, for instance in the example above it returns the (first) definition of the verb "to ride" and not of the noun "ride" (because the definition of the verb comes first in the related Wiktionary document).

It is lightweight and basic because I've written it for a multiplayer word game, not for an encyclopedia. A typical use would be: I click on an unknown word in a web page, and a short definition is quickly displayed in a tooltip.

Installation

with npm:

npm install word-definition

Usage

var wd = require("word-definition");

wd.getDef(word, language, options, callback);

Example

var wd = require("word-definition");

wd.getDef("keyboard", "en", null, function(definition) {
	console.log(definition);
});

Output:

{"word":"keyboard","category":"noun","definition":"A set of keys used to operate a typewriter, computer etc."}

See demo.js for further examples.

Arguments

word : the word that you want to define

language: "en" (english), "fr" (french) or "de" (german) - required

options : null or object - see below

callback : callback function (see below)

Options

There are 3 options:

#####exact :

Indicates if the search should be "accent-sensitive". For instance, the word "événement" has two accented characters in french. If exact = false and you search for the definition of "evenement" without accents, it will work and return the definition of "événement". If exact = true, it returns a "not found" error.

true by default.

#####hyperlinks :

Indicates how to handle the hyperlinks to Wiktionary pages in the definition.

Possible values are:

  • "html": the hyperlinks are preserved and converted into standard HTML hyperlinks (<a href=...).
  • "brackets": they are preserved in their original (wikimedia) format, like for instance [[typewriter]].
  • "none": (by default), all hyperlinks are stripped from the definition.

#####formatted :

If this option is set, the text formats (bold or italic) of the original definition are preserved and converted into CSS syles (for instance <span style='font-weight:bold'>some text</span>). Not set by default.

##Callback function

This function is called when the definition is ready (it is of course asynchronous and can in some case require more than 2 or 3 calls to the Wiktionary API).

The definition is passed in the argument. It is an object containing the defined word, its category (verb, noun, adjective...) and the definition itself.

If no definition has been found or for any other error, the object contains only the the word field and the error message in an err field.

##Definitions of inflected words and synonyms

If you request an inflected form of a word, say for instance the plural of a noun like "HOUSES" or the past participle of a verb like "BROKEN", the module returns the definition of the root dictionary entry, ie of the singular "HOUSE" or of the infinitive "BREAK".

For instance, it won't return "Plural of house" (like the search result of "HOUSES" in the Wiktionary) -which would be perfectly true but totally useless- but "A structure built or serving as an abode of human beings".

It's the same for synonyms. For instance, if you request the definition of "GRANDPA", it won't return "Grandpa: grandfather" (like the search result in the Wiktionary) but directly "Grandfather: a father of someone's parent".

##Notes

. I've used many regular expressions in order to isolate and "clean up" the definitions, and also to search for root dictionary entries. There may be errors. Please report them to me and I'll try to refine the code.

. If you use contents of the Wiktionary, you should indicate the source.

. The Wiktionary API is described here.