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

anidb-udp-client

v1.1.1

Published

anidb-udp-client is a library for Node.js that facilitates the use of Anidb's UDP API

Downloads

11

Readme

anidb-udp-client · anidb-udp-client GitHub license Tests Coverage

anidb-udp-client is a library for Node.js that facilitates the use of Anidb's UDP API. It handles the UDP connection, encoding/decoding requests and responses, rate limiting and caching (can be disabled) and provides typescript type definitions for all methods. If you plan to use the library for your project I strongly suggest to add your project to: https://anidb.net/software/add and use your own name for clientid

Docs

https://tsukeero.github.io/anidb-udp-client/

Installation

NPM: npm install anidb-udp-client

Yarn: yarn add anidb-udp-client

Usage

Basic example

import { AnidbUDPClient } from 'anidb-udp-client'

const anidb_client =  new AnidbUDPClient('my-anime-client')

await anidb_client.connect('anidb_username', 'anidb_passowrd')

const anime = await anidb_client.anime(117, [ 'english_name', 'rating' ])

console.log(`${anime.english_name}: rating ${anime.rating}`)

await anidb_client.disconnect()

Custom cache path path

import { AnidbUDPClient, SimplePersistentCache} from 'anidb-udp-client'

const cache = new SimplePersistentCache({save_path: '/tmp/'})
const anidb_client = const myanidb = new AnidbUDPClient('my-anime-client', { cache } )

Example with cache on redis

NOTE: when using custom cache make sure TTL for every anidb-udp-client related key is set to a reasonable amount. Long living cache can become stale.

import { createClient } from 'redis';
import { AnidbUDPClient } from 'anidb-udp-client'


class RedisCache {
    #redisClient
    constructor(){
        this.#redisClient = createClient();
        }
     async connect() {
        await this.#redisClient.connect();
     }

     async get(key) {
        const result = await this.#redisClient.get(key)
        return JSON.parse(result)
     }
    async set(key, value) {
         //can use key.startsWith() to set TTL for different result types: 'ANIME:', 'FILE:', ...
        await this.#redisClient.set(key, JSON.stringify(value), {EX: 2592000 })
     }
}


const cache = new RedisCache()
await cache.connect()

const anidb_client = new AnidbUDPClient('my-anime-client', { cache } )