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

@edixon/css-battle-api

v0.7.8

Published

First API client to get public information from the CSS Battle page

Downloads

5

Readme

CSS Battle API

code style: prettier

First API client to get public information from the CSS Battle page. Created with NodeJS and Typescript, all types are exposed for use.   + 💗

📃 NOTE: For now can only get the profile information of users, but later methods will be created to obtain: "leader board", "battle targets", etc.

📃 NOTE: To be able to use api from a frontend app, you must use a proxy, the library comes with one by default, it is on a free server so don't expect quick results.

Example: shield to Github ➜

Installation

  • NPM
npm install @edixon/css-battle-api
  • CDN
<!-- Bundle optimized to production -->
<script src="https://cdn.jsdelivr.net/npm/@edixon/[email protected]/dist/bundle/CSSBattleAPI.min.js"></script>

Usage

We require the library and we get the CSSBattleAPI class, then we create an instance to use the query methods.

const { CSSBattleAPI } = require('@edixon/css-battle-api')

const CBA = new CSSBattleAPI()

CBA.profile('USERNAME').then(profile => {
  console.log(profile.ranking.totalScore) // Total score obtained in CSS Battle
})

You can also pass a configuration object to the class to set a proxy and be able to use of the client side api. Can enter a URL or true to use the default proxy.

const CBA = new CSSBattleAPI({
  proxy: /* boolean | string */
})

Using typescript, async/await and try/catch.

When an error occurs a string error is returned, is a friendly message that describe the cause of the error in the query.

import { CSSBattleAPI, TRanking } from '@edixon/css-battle-api'

async function getRanking(username: string): Promise<TRanking> {
  try {
    const { ranking } = await new CSSBattleAPI().profile(username)

    return ranking
  } catch (error) {
    throw new Error(error)
  }
}

Types

type TProfile = {
  avatar: string
  name: string
  username: string
  job: string | null
  country: string | null
  networks: TNetworks
  ranking: TRanking
}

type TNetworks = {
  website: string | null
  github: string | null
  twitter: string | null
  codepen: string | null
} | null

type TRanking = {
  rank: number
  totalPlayers: number
  totalScore: number
  battlesPlayed: number
}

Contributing

See CONTRIBUTING.md

License

MIT © Edixon Piña