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

pnwkit

v2.2.1

Published

An API V3 SDK for PnW with GraphQL Typings

Downloads

8

Readme

Open in Visual Studio Code

PnWKit is here to make interacting with the V3 Politics and War API easy. All you have to do is import the library, add your key, and make a query.

Getting Started

To get started using PnWKit you must first have node and npm installed, or you can use it in a browser. It is recommended you are using TypeScript, as it will give you full advantage of the advanced typings within the library and allow you to be much more productive.

Prerequisites

Install the library using NPM.

  • npm
    npm i --save pnwkit

Future Plans

Baseball queries are coming soon with v2.3.0!

Usage

To use PnWKit just import the library and add your key, then you can make asyncronous queries.

import pnwkit from 'pnwkit';
pnwkit.setKey('xxxxx');

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `nation_name`);

console.log(`Nation name: ${nations[0].nation_name}`);

If you want to paginate your query for more results, just enable pagination after your query.

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, `nation_name`, true);

console.log(`Nation name: ${nations.data[0].nation_name
name}, current page: ${nations.paginatorInfo.currentPage}`);

The queries are written in normal GraphQL, so you can get all the cities in a nation like this

const nations = await pnwkit.nationQuery({id: [100541], first: 1}, 
  `
  nation_name,
  cities {
    name  
  }`);

console.log(`First city of ${nations[0].nation_name}: ${nations[0].cities[0].name}`);

If you want to have multiple copies of PnWKit running at the same time, you can use the Kit class export.

import {Kit} from 'pnwkit';

const pnwkit = new Kit();
pnwkit.setKey('xxxx');

// queries...

Use with require()

PnWKit also supports require() like in vanilla js.

const pnwkit = require('pnwkit');

pnwkit.setKey('xxxx');
// etc..

Caching

PnWKit has caching built right in for your convenience. Just create a cache function with PnWKit.cached and define how long it can be cached for. Then call it like normal.

Different calls return different cached versions too.

const cachableNationQuery = pnwkit.cached(
  pnwkit.nationQuery, // The query you want to cache
  1                   // How long that query can be cached at a time, in minutes
);

const nations = await cachableNationQuery({id: [100541], first: 1}, `nation_name`);

// If you call it again within the age limit you'll get a cached version
const nationsCached = await cachableNationQuery({id: [100541], first: 1}, `nation_name`);

Ratelimit Information

PnwKit stores the following rate limit info for your convenience.

  • pnwkit.rateLimit.limit: The maximum number of requests you can make in a given time period.
  • pnwkit.rateLimit.remaining: The number of requests you have left in the current time period.
  • pnwkit.rateLimit.reset: The unix timestamp at which point the rate limit resets.
  • pnwkit.rateLimit.resetAfterSeconds: The number of seconds until the rate limit resets.

You can also do the following queries in PnWKit:

  • nationQuery
  • allianceQuery
  • tradePricesQuery
  • tradeQuery
  • warQuery
  • treasureQuery
  • colorQuery
  • bountyQuery
  • cityQuery
  • warAttackQuery
  • bankRecordsQuery

You can look at the arguments and possible data to collect here at the docs.

Development

Testing

Setup

Tests won't work right away, you have to specify private information inside the test/testconfig.json file.

It should look like this:

{
  "apiKey": "xxxxx"
}

After that just run npm run test

Generating Docs

To generate documentation use the script: npm run docs.