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

sw-api-js

v1.0.1

Published

Star Wars API wrapper for Node and the browser.

Downloads

3

Readme

sw-api-js

Build Status Coverage Status dependencies Status devDependencies Status Simple Star Wars API Javascript wrapper for Node and the browser.

  • Supports search
  • Uses native ES6 Promises
  • Node v4+
  • Includes polyfill for older browsers

Getting started

Node

Install with npm:

// TO-DO: module to be published

Include the module (or import swapi from 'sw-api-js' in ES6):

var swapi = require('sw-api-js');

Browser

Download the browserified script and add with script tag:

 <script src="path/to/file/swapi.browser.js"></script>

Usage

This wrapper is designed to be simple and flexible. All endpoints can be passed through as parameters to swapi() and will return an object or array of objects. Use as promise:

swapi('your-parameter-here').then( function(data) {
        // ... Do the things
    }).catch( function(err) {
        // ... Handle errors
    });

For example, calling the function with a full URL (see other options below):

swapi('http://swapi.co/api/people/11').then(...)

Will return the data object:

{
    "name": "Anakin Skywalker", 
    "height": "188", 
    "mass": "84", 
    "hair_color": "blond", 
    "skin_color": "fair", 
    "eye_color": "blue", 
    "birth_year": "41.9BBY", 
    "gender": "male", 
    "homeworld": "http://swapi.co/api/planets/1/", 
    "films": [
        "http://swapi.co/api/films/5/", 
        "http://swapi.co/api/films/4/", 
        "http://swapi.co/api/films/6/"
    ], 
    "species": [
        "http://swapi.co/api/species/1/"
    ], 
    "vehicles": [
        "http://swapi.co/api/vehicles/44/", 
        "http://swapi.co/api/vehicles/46/"
    ], 
    "starships": [
        "http://swapi.co/api/starships/59/", 
        "http://swapi.co/api/starships/65/", 
        "http://swapi.co/api/starships/39/"
    ], 
    "created": "2014-12-10T16:20:44.310000Z", 
    "edited": "2014-12-20T21:17:50.327000Z", 
    "url": "http://swapi.co/api/people/11/"
}

Options

The parameter options are listed below:

URL

Get resource from full URL:

swapi('http://swapi.co/api/people/11').then(...)

All

Get all entries from a resource (available resources are films, people, planets, species, starships and vehicles) with the resource parameter:

swapi('people').then(...)

Single

Add an ID parameter to get a single entry from a resource:

swapi('people', 1).then(...)

Paged

Add 'paged' parameter to get paginated entries by type. The ID value is the page number to call. The endpoint URLs to the next/previous page will be in the data.next and data.previous fields.

swapi('people', 1, 'paged').then(...)

Search

To get resource entries by name instead of ID (useful!) use a string as the value to call the SWAPI search feature (full documentation here). You can get entries by their full name:

swapi('people', 'Anakin Skywalker').then(...)

Or a partial string to return all matches:

swapi('people', 'anakin').then(...)

Root

Calling the function with no parameters will default to the base URL and return a list of all available resources.

swapi().then(...)

Response:

{
    "films": "http://swapi.co/api/films/",
    "people": "http://swapi.co/api/people/",
    "planets": "http://swapi.co/api/planets/",
    "species": "http://swapi.co/api/species/",
    "starships": "http://swapi.co/api/starships/",
    "vehicles": "http://swapi.co/api/vehicles/"
}

Tests

npm test

To-Do

Additional browser testing