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

fluture-loaders

v3.0.2

Published

fluture-loaders

Downloads

14

Readme

Build Status

Fluture loaders

Wraps various loaders into Fluture primitives.

Includes Xhr, as well as Audio, Blob, and Image helpers.

Typescript definitions are bundled in.

Installation

npm install --save fluture-loaders

Status

Not battle-tested yet, API may change

Usage

The easiest way for most use cases is to use the various fetch* helpers:

import {fetchJson} from "fluture-loaders"

fetchJson("http://httpbin.org/get") ({ 
    data: { hello: "world" }
})
.fork(
    console.error,
    ({args}) => expect(args.hello).toBe("world")
)

API docs

General notes:

  1. If there is a function starting with a capital letter, and lowercase functions following, the lowercase are helpers that implement the capital but with more specific functionality and default values.

  2. Crossorigin values are only those allowed by spec (e.g. "anonymous" or "use-credentials") and this is enforced by the type system

  3. fetch means remote, and load is local.

Audio

loadAudioBuffer :: AudioContext -> ArrayBuffer -> Future DOMException AudioBuffer

Loads an ArrayBuffer into an AudioBuffer via the supplied AudioContext

Blob/File

BlobLoader :: Generic T => ([FileReader,Blob] -> void) -> Blob -> Future ErrorEvent T

Loads a Blob by calling the supplied function, which must accept a FileReader and a Blob

loadBlobAsArrayBuffer :: Blob -> Future ErrorEvent ArrayBuffer

Loads a Blob into an ArrayBuffer

loadBlobAsDataUrl :: Blob -> Future ErrorEvent String

Loads a Blob into a DataUrl

loadblobAsText :: Blob -> Future ErrorEvent String

Loads a Blob into a text string

Image

ImageLoader :: {url: string, crossOrigin?: string} -> Future ErrorEvent HTMLImageElement

Loads an url into an HTMLImageElement. If crossOrigin is a Just then it will be set to the value.

fetchImage :: string -> Future ErrorEvent HTMLImageElement

Calls ImageLoader with automatically detected crossOrigin settings. loadImageFromURL is an alias for fetchImage

loadImageFromArrayBuffer :: {data:ArrayBuffer,mimeType:string} -> Future ErrorEvent HTMLImageElement

Loads an ArrayBuffer into an HTMLImageElement. Mime type must be supplied.

Video

VideoPlayer :: {url:string, crossOrigin?: string} -> Future ErrorEvent HTMLVideoElement

Initializes a video and resolves when playback has started

playVideo :: string -> Future ErrorEvent HTMLVideoElement

Calls VideoPlayer with automatically detected crossOrigin settings.

XHR/Fetch

XhrLoader :: string -> XhrLoaderOptions -> Future XhrError XMLHttpRequest

Loads an XHR request with the given options (see below)

fletch :: Generic T => string -> XhrLoaderOptions -> Future XhrError T

Generic XHR loader that returns the response of the request

fetchUrl :: Generic T => string -> Future XhrError T

Generic XHR loader that only uses an endpoint url and default options

XHR helpers with options

fetchArrayBuffer :: string -> XhrLoaderOptions -> Future XhrError ArrayBuffer Loads XHR request and returns the response as an ArrayBuffer

fetchText :: string -> XhrLoaderOptions -> Future XhrError String Loads XHR request and returns the response as a string

fetchBlob :: string -> XhrLoaderOptions -> Future XhrError Blob Loads XHR request and returns the response as a Blob

fetchXML :: string -> XhrLoaderOptions -> Future XhrError XMLDocument Loads XHR request and returns the response as a XMLDocument (or Document)

fetchJson :: string -> XhrLoaderOptions -> Future XhrError Object Loads XHR request and returns the response as an Object. It will use query as the default requestType in this case (which may be overriden with the supplied options)

XHR helpers with URL only

fetchArrayBufferUrl :: string -> Future XhrError ArrayBuffer Loads XHR request and returns the response as an ArrayBuffer

fetchTextUrl :: string -> Future XhrError String Loads XHR request and returns the response as a string

fetchBlobUrl :: string -> Future XhrError Blob Loads XHR request and returns the response as a Blob

fetchXMLUrl :: string -> Future XhrError XMLDocument Loads XHR request and returns the response as a XMLDocument (or Document)

fetchJsonUrl :: string -> Future XhrError Object Loads XHR request and returns the response as an Object.

XHR Additional Types

The following are the typescript definitions that comprise the options and returns from XHR loaders:

interface XhrError {
    code: number;
    text: string;
}

type XhrResponseType = "blob" | "arraybuffer" | "document" | "json" | "text";
type XhrMethod = "GET" | "POST" | "PUT" | "DELETE";
type XhrRequestType = "query" | "form" | "multipart";
type XhrLoaderOptions = Partial<{
    data: any;
    method: XhrMethod;
    responseType: XhrResponseType;
    requestType: XhrRequestType;
    withCredentials: boolean;
    headers: Array<[string, string]>;
}>