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

bgg-boardgames-xml-json

v1.1.4

Published

This is a helper package to scrap data about IDs from BigGameGeek,then get those games from BGG XML API and receive result as XML or transform it to JSON, or mapped JSON

Downloads

3

Readme

BigGameGeek Boardgames XML JSON

This is a simple package only to retrieve boardgames from BigGameGeek.

NPM Version

Scrap IDs from website and go to XML API then transforming it to JSON :)

It works only with ES Modules, hence you need set "type": "module" inside your package.json

It has four different functions which allow you to:

  1. Parse all gameIds from BGG boardgames webpage - parseGameIds(config)
  2. Get boardgames by IDs in XML - getBoardgamesByIdsXML(idsInString)
  3. Get boardgames by IDs in JS object - getOriginalBoardgames(idsInString)
  4. Get mapped JS object by IDs with camelCase (Also removed fields such as poll) - getMappedOriginalBoardgames(idsInString)

Setup

npm install bgg-boardgames-xml-json

package.json

Set type to "module" in package.json

{
  "type": "module"
}

yourfile.js

import { parseGameIds, getBoardgamesByIdsXML, getOriginalBoardgames, getMappedOriginalBoardgames } from 'bgg-boardgames-xml-json'

// use functions

parseGameIds(config)

To get ids of boardgames, it needs to login on the BGG website and set how many pages to parse

Under the hood it opens the browser, hence this operation is long-term

const config = {
  login: 'YourBggLogin',
  password: 'YourBggPassword',
  lastPageToParse: 3 // Three pages will be pared
}

const ids = await parseGameIds(config) // '224517,161936, ...'

Be aware that one page returns 100 boardgames

getBoardGamesByIdsXML(ids)

To get boardgames data from BGG API in XML

We can use parseGameIds with getBoardGamesByIdsXML

const ids = await parseGameIds(config) // '224517,161936'

const xml = await getBoardgamesByIdsXML(ids) // <boardgame>...</boardgame>

Or we can pass the string itself

const xml = await getBoardgamesByIdsXML('224517,161936') // <boardgame>...</boardgame>

getOriginalBoardgames(ids)

To get boardgames data from BGG in original JS object

Same we can use parseGameIds with getOriginalBoardgames

const ids = await parseGameIds(config) // '224517,161936'

const originalBoardgames = await getOriginalBoardgames(ids) // { boardgame: { boardgame: [] } }

Or we can pass the string itself

const originalBoardgames = await getOriginalBoardgames('224517,161936') // { boardgame: { boardgame: [] } }

getMappedOriginalBoardgames(ids)

To get boardgames data from BGG in mapped JS object

Same we can use parseGameIds with getMappedOriginalBoardgames

const ids = await parseGameIds(config) // '224517,161936'

const mappedBoardgames = await getMappedOriginalBoardgames(ids) // { boardgame: [] }

Or we can pass the string itself

const mappedBoardgames = await getMappedOriginalBoardgames('224517,161936') // { boardgame: [] }

Examples

Read boardgames data from first three pages and write it to XML, JSON, mapped JSON

import { parseGameIds, getBoardgamesByIdsXML, getOriginalBoardgames, getMappedOriginalBoardgames } from 'bgg-boardgames-xml-json'
import fs from 'fs/promises'

const config = {
  login: 'YourLogin',
  password: 'YourPassword',
  lastPageToParse: 3
}

// Login to BGG, Run chromium, navigate urls to get IDs
const ids = await parseGameIds(config)

// Get XML and save it to file
const xml = await getBoardgamesByIdsXML(ids)
await fs.writeFile('./boardgames.xml', xml)

// Get AS IS js object converted from XML and save it to file as JSON
const originalBoardgames = await getOriginalBoardgames(ids)
await fs.writeFile('./boardgames-original.json', JSON.stringify(originalBoardgames))

// Get mapped js object converted from XML and save it to file as JSON
const mappedOriginalBoardgames = await getMappedOriginalBoardgames(ids)
await fs.writeFile('./boardgames-mapped.json', JSON.stringify(mappedOriginalBoardgames))