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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wikidata-search

v1.0.3

Published

Perform easy entity searches using Wikidata. Supply an entity name, and get back a bunch of structured data about that entity.

Readme

wikidata-search

Perform easy entity searches using Wikidata as a source.

What's an entity search? Basically, just give an entity name (person, place, thing, etc), and we'll run a query against the Wikidata API. We'll match it to the Wikidata entity that most closely matches what you searched, and return a bunch of structured data for that entity. For a better idea of what this means, check out some of the examples below.

Installation

npm install wikidata-search

Overview

wikidata-search provides two major functionalities: the ability to search for entities based on given (possibly incomplete) text, and the ability to get more detailed information about entities from their IDs. All of this is done is a clean way that (mostly) abstracts you from the headache that is Wikidata.

Usage

//First, create a new Wikidata Search object.
var WikidataSearch = require('wikidata-search').WikidataSearch;
var wikidataSearch = new WikidataSearch();

//To search:
wikidataSearch.set('search', <SOMETHING'S NAME>); //set the search term
wikidataSearch.search(function(result, error) {

    //check the 'error' parameter for any errors, and your results are in 'result'.
});


//To get detailed info on one or more entities:
wikidataSearch.getEntities(['id', 'id', ...], true, function(result, error) {
    //check the 'error' parameter for any errors, and your results are in 'result'.
});

Important Functions

WikidataSearch.set(key, value)

Sets an option key to value.

WikidataSearch.search(callback)

Performs a search using the 'search' option (which should be set using WikidataSearch.set(key, value). The data returned has the following format:

results : {   
    id : {String}, the ID of the result entity,
    url : {String}, the Wikidata URL for the entity,
    label : {String}, the string label for the entity (its name),
    description : {String}, the optional description of the entity, if available
}

The description field is only available for entities (i.e. not properties).

WikidataSearch.getEntities(entityIdList, resolveProperties, callback)

Get detailed information for a list of entities who's IDs (strings) are listed in entityIdList. The resolveProperties parameter determines whether the results have their property and value IDs replaced with the corresponding labels (names) of the entities and properties. The result field will look something like this:

[ 
    { 
        label: 'New York Mets',
        description: 'baseball team and Major League Baseball franchise in Queens, New York, United States',
        claims: [ 
            { value: 'New York Mets', type: 'string', property: 'Commons category' },
            { value: 'Citi Field', type: 'string', property: 'home venue' },
            { value: 'Terry Collins', type: 'string', property: 'head coach' },
            { value: 'Major League Baseball', type: 'string', property: 'league' },
            { value: 'baseball team', type: 'string', property: 'instance of' },
            { value: 'Category:New York Mets', type: 'string', property: 'topic\'s main category' },
            { value: '/m/05g76', type: 'string', property: 'Freebase identifier' },
            { value: '134873843', type: 'string', property: 'VIAF identifier' },
            { value: 'baseball', type: 'string', property: 'sport' },
        ] 
    },
]

About the fields: label is a text label, and generally gives the name of the entity. description is a text description of the entity. claims is a list of facts about the entity, given as property/value/type triplets.

A bit about the resolveProperties parameter: say a lookup result has a claim looking like this:

{ 'property' : 'P1234', 'value' : 'Q1234', 'type' : 'wikidata-item' }

If property resolution is disabled (set to false), then that's exactly what you'll get back. If it's enabled, then we'll do a lookup for P1234 and Q1234, and replace those IDs with their labels. So it might look something like this if property resolution is enabled. Notice that the type field is updated:

{ 'property' : 'is parent of', 'value' : 'Jim Bob', 'type' : 'string' }

Unfortunately, property resolution means it'll probably have to do two requests behind the scenes: one to get the entity result, and another to populate the the properties with their labels. There's good news though! We cache these lookups, so once a property ID is resolved to a label, it's saved in memory. To clear the cache, use WikidataSearch.clearPropertyCache();

Examples

See example.js for an example of how to use this.