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

@therebel/noice-json-rpc

v1.2.0-alpha2

Published

Noice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers

Downloads

14

Readme

Noice Json Rpc

Build Status Coverage Status issues open npm total downloads licence npm version

Client and Server helpers to implement a clean function based Api for Json Rpc.

Noice Json Rpc takes in a websocket like object. It calls send(msg:str) function and expects messages to come from on('message', handler). It works out of the box with WebSockets but it can also work with stdin/stdout, worker threads, iframes or any other mechanism in which strings can be sent or received.

Its only dependency is events.EventEmitter.

Using ES6 proxies it exposes a clean client-server api. Since its written in TypeScript, the api object can be cast to work off an interface specific to the domain. e.g ChromeDevTools/devtools-protocol

Example

import * as WebSocket from 'ws'
import DevToolsProtocol from 'devtools-protocol'
import * as rpc from '../lib/noice-json-rpc'

async function setupClient() {
    try {
        const rpcClient = new rpc.Client(new WebSocket('ws://localhost:8080'), {logConsole: true})
        const api: DevToolsProtocol.ProtocolApi = rpcClient.api()

        await Promise.all([
            api.Runtime.enable(),
            api.Profiler.enable(),
        ])

        await api.Runtime.run()
        await api.Profiler.start()
        await new Promise(resolve => api.Runtime.on('executionContextDestroyed', resolve)); // Wait for event
        const result = await api.Profiler.stop()

        console.log('Result', result)

    } catch (e) {
        console.error(e)
    }
}

setupClient()

Output

Client > {"id":1,"method":"Runtime.enable"}
Client > {"id":3,"method":"Profiler.enable"}
Client > {"id":4,"method":"Runtime.run"}
Client < {"id":1,"result":{}}
Client < {"id":2,"result":{}}
Client < {"id":3,"result":{}}
Client < {"id":4,"result":{}}
Client > {"id":5,"method":"Profiler.start"}
Client < {"id":5,"result":{}}
Client < {"method":"Runtime.executionContextDestroyed"}
Client > {"id":6,"method":"Profiler.stop"}
Client < {"id":6,"result":{"data":"noice!"}}