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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yieldray/json-rpc-ts

v0.2.2

Published

A strictly typed json-rpc(2.0) implementation

Readme

json-rpc-ts

deno.land/x JSR npm codecov ci

A strictly typed json-rpc(2.0) implementation, zero dependency, minimal abstraction, with a simple API.

Specification https://www.jsonrpc.org/specification

Installation

For Node.js

npx jsr add @yieldray/json-rpc-ts # recommended
# or
npm install @yieldray/json-rpc-ts

For Deno

deno add jsr:@yieldray/json-rpc-ts

Examples

Example to use the client:

import { JSONRPCClient } from '@yieldray/json-rpc-ts'

const requestForResponse = (json: string) =>
    fetch('http://localhost:6800/jsonrpc', {
        method: 'POST',
        body: json,
    }).then((res) => res.text())

const client = new JSONRPCClient<{
    'aria2.addUri': (
        urls: string[],
        options?: object,
        position?: number,
    ) => string
    'aria2.remove': (gid: string) => string
    'system.listMethods': () => string[]
}>(requestForResponse)

const resultGid: string = await client.request('aria2.addUri', [
    ['https://example.net/index.html'],
    {},
    0,
])

Example to use the server:

import { JSONRPCServer } from '@yieldray/json-rpc-ts'

const server = new JSONRPCServer({
    upper: (str: string) => str.toUpperCase(),
    lower: (str: string) => str.toLowerCase(),
    plus: ([a, b]: [number, number]) => a + b,
    minus: ([a, b]: [number, number]) => a - b,
})

// or:
server.setMethod('trim', (str: string) => str.trim())
server.setMethod('trimStart', (str: string) => str.trimStart())
server.setMethod('trimEnd', (str: string) => str.trimEnd())

const handler = async (request: Request): Promise<Response> => {
    // server.handleRequest() accept string and returns Promise<string>
    const jsonString = await server.handleRequest(await request.text())

    return new Response(jsonString, {
        headers: { 'content-type': 'application/json' },
    })
}

const httpServer = Deno.serve(handler)

When a server function fails, the server does not throw an exception but instead sends a JSONRPCError to the client, making the error unobservable by default. To handle server errors, you can wrap the server function as follows:

import {
    JSONRPCInvalidParamsError,
    type JSONRPCMethod,
    type JSONRPCMethods,
    JSONRPCServer,
} from '@yieldray/json-rpc-ts'

function wrapMethod<T, U>(fn: JSONRPCMethod<T, U>): JSONRPCMethod<T, U> {
    return async (arg) => {
        try {
            console.log('Request', arg, fn)
            const result = await fn(arg)
            console.log('Response', result)
            return result
        } catch (e) {
            console.error('Error', e)
            throw e
        }
    }
}

function wrapMethods(methods: JSONRPCMethods): JSONRPCMethods {
    return Object.fromEntries(
        Object.entries(methods).map(([name, fn]) => [
            name,
            typeof fn === 'function' ? wrapMethod(fn.bind(methods)) : fn,
        ]),
    )
}

const methods: JSONRPCMethods = {
    upper: (str: string) => {
        if (typeof str !== 'string') {
            throw new JSONRPCInvalidParamsError(
                'Invalid argument type, expected string',
            )
        }
        // if not JSONRPCxxxError, the client will receive an Internal Error
        return str.toUpperCase()
    },
    lower: (str: string) => str.toLowerCase(),
    plus: ([a, b]: [number, number]) => a + b,
    minus: ([a, b]: [number, number]) => a - b,
}

const server = new JSONRPCServer(wrapMethods(methods))

// or:
const setMethod = <T, U>(name: string, method: JSONRPCMethod<T, U>) =>
    server.setMethod(name, wrapMethod(method))

setMethod('trim', (str: string) => str.trim())
setMethod('trimStart', (str: string) => str.trimStart())
setMethod('trimEnd', (str: string) => str.trimEnd())