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

@loama18/eduardolopez-sdk

v1.2.1

Published

The Lord Of The Rings (LOTR) JS Library provides convenient access to the [LOTR API](https://the-one-api.dev/) from applications written in Javascript (or typescript), both server and client side.

Downloads

16

Readme

Lord Of The Rings JS Library

The Lord Of The Rings (LOTR) JS Library provides convenient access to the LOTR API from applications written in Javascript (or typescript), both server and client side.

Installation

Install the package with

npm i @loama18/eduardolopez-sdk

Usage

The package needs to be configured with your account's secret key, which is available in the LOTR API Account Page, sign up for free if you haven't already, to get an API Key. Otherwise you will only be able to access the book endpoints.  


 

Require it with the key's value:

const LOTR = require("@loama18/eduardolopez-sdk");

LOTR.setup("<your-key>"); // replace <your-key> for the key you got

// do the actual call to get info, in this case for books
LOTR.get("book")
  .then((res: any) => {
    console.log(res);
  })
  .catch((e: any) => {
    console.log(e.response.data);
  });

 

Or using ES modules and async/await::

import LOTR from "@loama18/eduardolopez-sdk";

LOTR.setup("<your-key>"); // replace <your-key> for the key you got

(async () => {
  const book = await LOTR.get("book");

  console.log(book);
})();

depending on your environment, you might need to replace LOTR.setup with LOTR.default.setup

 

 

Which routes are available?

All routes that you can find in LOTR API docs are also available here, with the LOTR.get(<endpoint>) method.

Complete List

| Endpoint | Response | Token required | | -------------------- | ---------------------------------------------------------------------------------------- | -------------- | | book | List of all "The Lord of the Rings" books | no | | /book/{id} | Request one specific book | no | | book/{id}/chapter | Request all chapters of one specific book | no | | movie | List of all movies, including the "The Lord of the Rings" and the "The Hobbit" trilogies | yes | | movie/{id} | Request one specific movie | yes | | movie/{id}/quote | Request all movie quotes for one specific movie (only working for the LotR trilogy) | yes | | character | List of characters including metadata like name, gender, realm, race and more | yes | | character/{id} | Request one specific character | yes | | character/{id}/quote | Request all movie quotes of one specific character | yes | | quote | List of all movie quotes | yes | | quote/{id} | Request one specific movie quote | yes | | chapter | List of all book chapters | yes | | chapter/{id} | Request one specific book chapter | yes |

 

GraphQL

You can also use graphQL to query the API, doing something like this

LOTR.graphQL(<query>)

In there, you have access to every single point of data in the API at the same time.

To get all the data in the API at once you would do something like this:

LOTR.graphQL(
  `{
  book {
    _id,
    name,
    chapter {
      _id,
      chapterName
    }
  },
  chapter {
    _id,
    chapterName,
    book
  },
  character {
    _id,
    height,
    race,
    gender,
    birth,
    spouse,
    death,
    realm,
    hair,
    name,
    wikiUrl
  },
  movie {
    _id,
    name,
    runtimeInMinutes,
    budgetInMillions,
    boxOfficeRevenueInMillions,
    academyAwardNominations,
    academyAwardWins,
    rottenTomatoesScore,
    quote {
      _id,
      dialog,
      movie,
      character,
      id
    }
  }
  quote {
    _id,
    dialog,
    movie,
    character,
    id
  }
}`
)
  .then((res) => {
    console.log(res);
  })
  .catch((e) => {
    console.log(e);
  });

This is an extreme case, feel free to remove whatever fields that you don't require, to make the request faster and smaller.

Note that from within movie you are able to request the quotes that belong to that movie, same thing for books, you are able to request their belonging chapters.

LOTR.graphQL(`{
  book {
    _id,
    name,
    chapter {
      _id,
      chapterName
    }
  }
}`);

 

Caching

By default, the SDK will cache the responses of each call made, it is setup to last 1 hour, so you might notice considerably faster responses after the first call within the same hour.

If you are running it from Node, it will use cachios.

If you are running it from the Browser (most likely with something like Vue or React), it will use axios-cache-adapter

 

Test

Run

npm run test

 

Pending To Do for next release:

  • Make character/quotes available directly in GraphQL

  • Add ability to paginate, slice and filter with GraphQL like:

      movies(first:2) {
        _id,
        name
      }
    
      // or
    
      movies(id: "5cd95395de30eff6ebccde57") {
        _id,
        name
      }