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

@dcos/connections

v0.4.0

Published

Provides different connection types with a unified interface

Downloads

16

Readme

Connections Build Status


👩‍🔬 Please be aware that this package is still experimental — changes to the interface and underlying implementation are likely, and future development or maintenance is not guaranteed.


This package provides different connection types with a unified interface.

Example

The following example will create an XHRConnection, add a complete event listener and open the connection. The complete listener will get called once the JSON file is loaded and the connection is closed.

import { XHRConnection, ConnectionEvent } from "@dcos/connections";

const connection = new XHRConnection("http://example.com/file.json");
connection.addListener(ConnectionEvent.COMPLETE, (event) => console.log(event));
connection.open();

Abstract Connection

The AbstractConnection provides the default properties, methods, states, and event-definitions to implement a custom connection.

Connection Event

The ConnectionEvent provides a common interface for all different event types.

Types

Use the following event types...

  • OPEN when opening the connection
  • DATA every time data is received from the server
  • ERROR when an error occurred
  • COMPLETE when the connection closes without any errors
  • ABORT when the connection was aborted by something

Target

The event target always points to the connection.

XHR Connection

The XHRConnection wraps the native XMLHttpRequest to provide a unified and easy to use interface.

Example

The following example will create an XHRConnection to post "data" to an API server.

const connection = new XHRConnection("http://example.com/api", {
  method: "POST",
  body: "data"
});
connection.open();

Parameters

URL

This defines the resource location that you want to connect to.

Options (Optional)

An optional object containing custom settings that you want to apply to the connection.

  • headers: Any headers you want to add to your request
  • method: The request method (default: "GET")
  • body: Any data you want send with your request
  • responseType: The response type you expect (default: "json") If the server returns data that is not compatible the value of response will be null.
Response Types

Value | Data type of response property -- | -- "arraybuffer" | ArrayBuffer "blob" | Blob "document" | Document "json" | JavaScript object, parsed from a JSON string returned by the server "text" | DOMString