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

nerds

v1.3.6

Published

The API after every nerd's heart...

Downloads

25

Readme

nerdsJS Logo

Coverage Status Open Source Love MIT Licence Awesome

The API after every nerd's heart...

nerdsJS is an API for easily generating random data from your favorite nerdy movies, tv shows, and hobbies. Pull mock data into your app or presentation from Pokemon, Harry Potter, Star Wars and more (very soon). Effortlessly compose nerdy datasets by chaining methods in succint and intelligible expressions.

Return the datasets in whatever form works best for you. You can get it as a simple Array, wrapped in a Promise, or even get a Generator back.

Installation

NPM

nerdsJS is available on npm. Navigate to your project's folder and run:

npm install nerds

or download the source code directly from Github

Quick Examples

let nerds = require('nerds');

let singleHP = nerds.resolve('Harry Potter').asArray();
console.log(singleHP);
/*
[{
	'first': 'Hermione',
	'last': 'Granger',
	'full': 'Hermione Granger',
	'blood_status': 'Muggle-Born',
	'birthday': '19 September, 1979',
	'gender': 'Female',
	'house': 'Gryffindor',
	'wand': '10¾", Vine Wood - Dragon Heartstring'
}]
*/

let multiPoke = nerds.resolve('Pokemon', 3).include(['name', 'type', 'hp']).asArray();
console.log(multiPoke);
/*
[
	{'name':'Bulbasaur', 'type': 'Grass Poison', 'hp': 45},
	{'name':'Charmander', 'type': 'Fire', 'hp': 39},
	{'name':'Squirtle', 'type': 'Water', 'hp': 44}
]
*/

let genSW = nerds.resolve('Star Wars', 3).include(['name']).asGenerator();
genSW.next().value; // {"name":"Luke Skywalker"}
genSW.next().value; // {"name":"Nute Gunray"}
genSW.next().value; // {"name":"Leia Organa"}
genSW.next().value; // undefined

Methods

nerdsJS exposes an API that lets you chain methods together to get the exact fields and number of results you want. It is designed to be highly discoverable. Where possible, empty setters return valid options as examples. Every method comes standard with type and sanity checks and, if necessary, returns informative error messages.


resolve([topic], [results])

Parameter | Type | Description ---|---|--- topic|String|The topic that the data is based off of. results|Number|Max number of results that will be returned.

Sets the topic and the max number of results to be returned (optionally). If no topic is assigned, returns all valid topics. If the number of results is not specified, nerds returns one random result by default. nerdsJS retrieves random data up to either the results or the size of the collection.

nerds.resolve('Harry Potter');  //sets topic and returns the nerd context

nerds.resolve('Harry Potter', 3);  //sets topic, number of results and returns the nerd context

let topics = nerds.resolve();
console.log(topics);  //['Harry Potter','Star Wars','Pokemon']

When used as a setter, resolve returns the nerds context, meaning you can (and should) continue chaining subsequent methods.


fields()

Convenience getter method for discovering available fields. Topic must be set first. Returns array of all valid fields for the topic.

let fields = nerds.resolve('Pokemon').fields();
console.log(fields);
/*[
	'national_pokedex_number',
	'name',
	'type',
	'height',
	'weight',
	'total',
	'hp',
	'attack',
	'defense',
	'special_attack',
	'special_defense',
	'speed',
	'base_experience',
	'evolves_from'
]*/

include(fields)

Parameter | Type | Description ---|---|--- fields|Array of Strings|The fields to include in the results.

Sets the fields to be included in the results. Accepts an array of strings. Any field not specified will not be included in the results. Topic must be set first.

nerds.resolve('Star Wars').include(['name', 'homeworld'])  //sets fields and returns the nerd context

include returns the nerds context, meaning you can (and should) continue chaining subsequent methods.


exclude(fields)

Parameter | Type | Description ---|---|--- fields|Array of Strings|The fields to exclude from the results.

Sets the fields to be excluded in the results. Accepts an array of strings. Any field not specified will be included in the results. Topic must be set first.

nerds.resolve('Star Wars').exclude(['birth_year', 'eye_color'])  //sets fields and returns the nerd context

exclude returns the nerds context, meaning you can (and should) continue chaining subsequent methods.


Once I've set the topic and fields, how to do I get the data?

Any of the following as methods will resolve the nerd method chain. This is what tells nerdsJS what format you would like to receive the data in.

asArray()

Returns the dataset as a plain ol' JavaScript Array. The Array will contain data objects representing the search results (characters, Pokemon, etc).

let result = nerds.resolve('Harry Potter').asArray();
console.log(result);
/*
[{
	'first':'Albus',
	'last': 'Dumbledore',
	'full': 'Albus Dumbledore',
	'blood_status': 'Half-Blood',
	'birthday': 'Summer 1881',
	'gender': 'Male',
	'house': 'Gryffindor',
	'wand': '15", Elder - Thestral Tail Hair'
}]
*/

asPromise()

Returns the same kind of result as asArray() except wrapped in a Promise. Once the promise is resolved, the resulting Array will contain data objects representing the search results (characters, Pokemon, etc).

let promise = nerds.resolve('Harry Potter').asPromise();
promise.then(function (result) {
	console.log(result);
/*
[{
	'first': 'Neville',
	'last': 'Longbottom',
	'full': 'Neville Longbottom',
	'blood_status': 'Pure-Blood',
	'birthday': '30 July, 1980',
	'gender': 'Male',
	'house': 'Gryffindor',
	'wand': '13", Cherry - Unicorn Hair'
}]
*/
});

asGenerator()

Returns the search results as a Generator. This allows you to iterate over the collection using the next method;

let gen = nerds.resolve('Harry Potter', 3).include(['first']).asGenerator();
gen.next().value;  // {'first':'Harry'}
gen.next().value;  // {'first':'Ron'}
gen.next().value;  // {'first':'Hermione'}
gen.next().value;  // undefined
});

What's Next?

nerdsJS is still under active development. Collecting, cleaning, compiling, and updating datasets are great ways to contribute. Just make sure that the data is consistent (they should all have the same keys and most of the fields should have some kind of data).

Topics Yet To Be Added:

  • Super Mario
  • Sherlock
  • Lord Of The Rings
  • Avengers
  • Doctor Who
  • Star Trek
  • Dragonball Z
  • Zelda