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

a2c

v0.2.0

Published

Lightweight Aria2 JSON-RPC client with full type definition.

Downloads

7

Readme

A2C

npm minified size downloads

Lightweight Aria2 JSON-RPC client with full type definition.

Features

  • Decoupling. A2C is responsible for only the Aria2-specific part, using async-call-rpc to implement the JSON-RPC client.
  • Lightweight. Most of the content of A2C is type definitions, they are generally not bundled.
  • Just Fetch. A2C uses the runtime environment fetch, not node-fetch, isomorphic-fetch or other...

Install

A2C requires async-call-rpc, so you should install them both.

pnpm add a2c async-call-rpc # pnpm
# yarn add a2c async-call-rpc # yarn
# npm i a2c async-call-rpc # npm

Usage

import { createClient } from 'a2c'
// import { notify, batch } from 'async-call-rpc'

const aria2 = createClient({
  url: 'http://localhost:6800/jsonrpc', // defaultValue
  secret: '123e4567-e89b-12d3-a456-426614174000', // --rpc-secret, optional
})

await aria2.getVersion().then(console.log) // { enabledFeatures: [], version: '1.36.0' }

// const notify = notify(createClient())
// const [batch, emit, drop] = batch(createClient())

If you use user/passwd instead of secret:

import { createClient } from 'a2c'

const aria2 = createClient({
  url: 'http://localhost:6800/jsonrpc', // defaultValue
  user: 'username', // --rpc-user
  secret: 'password', // --rpc-passwd
})

Advanced

createClient is a wrapper around AsyncCall. So of course you can use it directly if you want:

import { A2Channel, type Aria2 } from 'a2c'
import { AsyncCall } from 'async-call-rpc'

const aria2 = AsyncCall<Aria2>(
  {},
  {
    channel: new A2Channel({
      url: 'http://localhost:6800/jsonrpc', // defaultValue
      secret: '', // --rpc-secret, optional
    }),
  }
)

A2Channel uses the fetch in the runtime environment.

But for some custom use cases, you can also implement your own EventBasedChannel and reuse the A2C type definition:

import type { Aria2 } from 'a2c'
import { type EventBasedChannel, AsyncCall } from 'async-call-rpc'

class MyChannel implements EventBasedChannel {
  on(listener: (data: unknown) => void) {
    ...
  }
  send(data: unknown): void {
    ...
  }
}

const aria2 = AsyncCall<Aria2>(
  {},
  { channel: new MyChannel() }
)