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

howlongtobeat-api

v1.0.3

Published

HowLongToBeat.com scrapper API

Downloads

10

Readme

howlongtobeat-api

Promise based API to get data from HowLongToBeat.com web.

Features

  • Typescript support
  • Search games with filtering options
  • Complete detailed game data (including time tables)

Inspired by @ckatzorke project

Dependencies

  • Axios (requests)
  • Cheerio (HTML scrapper)

Installing

Using npm:

$ npm install howlongtobeat-api

Using yarn:

$ yarn install howlongtobeat-api

API

howlongtobeat.find(query: Query = {}): Promise<{ total: number, data: GameResult[] }>

howlongtobeat.get(id: number): Promise<GameDetail>

Example

import howlongtobeat from 'howlongtobeat-api'

// Find games
howlongtobeat
  .find({ search: 'bayonetta' })
  .then(results => {
    /*
      Receive object with total number and results (max. 20 from total)
      {
        total: 5,
        data: [
          {
            id: 966,
            name: "Bayonetta",
            imageUrl: "...",
            gameplayMain: 11.5,
            gameplayExtended: 15.5,
            gameplayCompletionist: 42.5
          },
          ...
        ]
      }
    */
  })
  .catch(err => {
    // Request failed
  })

// Get game by ID
howlongtobeat
  .get(966)
  .then(game => {
    /*
      Receive object with game properties
      {
        id: 966,
        name: "Bayonetta",
        developers: ["PlatinumGames"],
        platforms: ["Nintendo Switch", ...],
        genres: ["Action", ...],
        publishers: ["Sega", ...],
        description: "...",
        releaseDates: {
          NA: "January 05, 2010",
          ...
        },
        ...
        gameplays: {
          single: [
            {
              type: "Main Story",
              average: "11h 31m",
              median: "11h 10m",
              ...
            },
            ...
          ],
          platforms: [
            {
              platform: "Nintendo Switch",
              main: "11h 42min",
              extended: "16h 42min",
              completionist: "48h 12min",
              ...
            }
          ]
        }
      }
    */
  })
  .catch(err => {
    // Game not found or request failed
  })

Typescript

import { find, GameResult, Query, Platform, SortBy } from 'howlongtobeat-api'

// Write your own code with types
async function findHaloGames (): void {
  try {
    const query: Query = {
      search: 'halo',
      platform: Platform.Xbox360,
      sortBy: SortBy.ReleaseDate
    }
    const results: { total: number; data: GameResult[] } = await find(query)
    console.log(results.data)
  } catch (err) {
    console.log(err)
  }
}

Query format

{
  // Search pattern to find games
  search: '',

  // Pagination (max. 20 results per page)
  page: 1,

  // Gameplay length type to use on min and max
  lengthType: LengthType.Main, // 'main'

  // Min and max values to restrict search data
  lengthMin: '',
  lengthMax: '',

  // Sorting: 'popular', 'rating', ...
  sortBy: SortBy.Popular,
  // '0' for descending, '1' for ascending
  sortOrder: SortOrder.Descending,

  // Filters
  platform: Platforms.All, // default: ''
  perspective: Perspective.All, // default: ''
  flow: Flow.All, // default: ''
  genre: Genre.All, // default: ''
  modifier: Modifier.None, // default: ''

  // Get one random game result
  randomize: false
}