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

blinchik

v1.2.0

Published

WebSocket with Kefir

Downloads

5

Readme

Blinchik

A tiny websocket wrapper that made using Kefir.js. It returns a Kefir stream instance.

NPM

Etymology

Blinchik — diminutive form of Blin. Blini frequently made using Kefir.

Getting started

  1. Installation.
npm i -S blinchik
  1. Look into examples.

You can also scale your code using Blinchik.

That's the client side:

import Blinchik from 'blinchik'

const b = new Blinchik('ws://127.0.0.1:8080')

const stream = b.onMsg({ shouldParseJSON: true })

const chatStream = stream
  .filter(({ data }) => data.type === 'CHAT/INCOMING_MESSAGE')

const notificationStream = stream
  .filter(({ data }) => data.type === 'NOTIFICATION/PAYMENT')

chatStream
  .log('chat stream')
  .map(({ data }) => {
    // your logic goes here
  })

notificationStream
  .log('notification stream')
  .map(({ data }) => {
    // your logic goes here.
    // e.g., you can show a popup with the notification
  })

And that's the server side:

import Blinchik from 'blinchik'

const b = new Blinchik({ port: 8080 })

const connectionsStream = b.onConn()

connectionsStream
  .onValue(({ conn }) => {
    // for demonstration purposes,
    // on each new connection we send
    // two messages to the client.
    // you can implement any custom logic instead.
    b.send({
      type: 'CHAT/INCOMING_MESSAGE',
      text: 'LMAO',
    }, conn)

    b.send({
      type: 'NOTIFICATION/PAYMENT',
      severity: 'error',
      text: 'Could not process scheduled payment. Please, review your billing settings.',
    }, conn)
  })

Using Blinchik, you can use all Kefir stream methods. See Kefir docs for more information.

  1. You're ready to go ;)

API

Blinchik constructor parameters

new Blinchik(ws, settings)

ws must be one of:

  • undefined (for creating mock instance)
  • Blinchik instance (for using mock instance)
  • String (node & browser client only): wss://ws.example.com/connections.
  • Object (server only): WebSocket.Server options from ws library
  • WebSocket or WebSocket.Server from ws library
  • Standard WebSocket object

settings is an optional object with:

  • disableReconnect (node & browser client only, Boolean, default: false): disables automatic failover behaviour, which will try to reconnect to a broken connection each reconnectInterval ms.
  • reconnectInterval (node & browser client only, Number, default: 2000): failover reconnection interval in milliseconds.
  • mock mock Blinchik instance or array mock Blinchik instances

Blinchik instance properties

ws eighter is one of:

Blinchik instance will use this connection.

Blinchik methods for both server and clients

  • onError(callback): sets error handler for current instance. Callback should accept an error. Error type depends on mode.
  • onClose(callback): sets connection close handler for current instance. Callback should accept an error. Error type depends on mode.
  • onMessage(options): returns Kefir stream of connection messages.
    • options is an optional object with shouldParseJSON boolean flag, that enables automatic data parsing.
  • onMsg: alias for onMessage
  • send(msg, ws): sends given message using current instance connection or given ws connection, if passed. This method handles connection state checks and automatic data stringify if given message is an object (which is not a valid WS message).

Blinchick client methods

  • onOpen(callback): sets a handler which executed on successful connection.
  • onPing(callback) (only node client): sets a handler for pings. For details, see ws library docs.

Blinchik server methods

  • onConnection(): returns Kefir stream of new connections.
  • onConn: alias for onConnection
  • onHeaders(): returns Kefir stream which allows set custom headers. This is done by mutating headers property of the value.

Blinchik mock methods

  • connect(): create mock connection

helpers

  • setCookie(cookie)(params): helper for onHeaders stream.

cookie is object with:

  • value?: string;
  • expires?: string | Date;
  • name?: string;
  • isReplace?: boolean;
  • ttl?: number;
  • getValue?: () => string;
  • getExpires?: () => string | Date;

params is object with:

  • req: Request Object;
  • headers: Array;