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

flachejs

v1.0.1

Published

FlacheJS is an npm library for dealing with client-side caching.

Downloads

5

Readme

FlacheJS

FlacheJS is an npm library for dealing with client-side caching.

Installation

npm install flachejs

Loading and configuring the module

ES Modules (ESM)

import flacheClient from 'flachejs';

Usage

Plain text or HTML

import flacheClient from 'flachejs';

const store = new flacheClient();
const response = await store.flacheRequest('https://github.com/');
const body = await response.text();

console.log(body);

JSON

import flacheClient from 'flachejs';

const store = new flacheClient();
const response = await store.flacheRequest('https://api.github.com/users/github');
const data= await response.json();

console.log(data);

Simple Post

import flacheClient from 'flachejs';

const store = new flacheClient();
const response = await store.flacheRequest('https://httpbin.org/post', {method: 'POST', body: 'a=1'});
const data = await response.json();

console.log(data);

Post with JSON

import flacheClient from 'flachejs';

const body = {a: 1};

const store = new flacheClient();
const response = await store.flacheRequest('https://httpbin.org/post', {
	method: 'post',
	body: JSON.stringify(body),
	headers: {'Content-Type': 'application/json'}
});
const data = await response.json();

console.log(data);

Handling Exceptions

Wrapping the fetch function into a try/catch block will catch all exceptions, such as errors originating from node core libraries, like network errors, and operational errors which are instances of FetchError.

import flacheClient from 'flachejs';

const store = new flacheClient();
try {
	await store.flacheRequest('https://domain.invalid/');
} catch (error) {
	console.log(error);
}

API

flacheClient([options])

  • options Options for the cache
  • Returns: flache client

Create a flache client/store.

Options

The default values are shown after each option key.

{
  maxCapacity: null, // this is in development
  ttl: 5000,
  config: {
    name: 'httpCache',
    storeName: 'request_response',
    description: 'A cache for client-side http requests',
    driver: [
			clientCache.MEMORY,        //this is an LRU cache in the local memory
      localforage.INDEXEDDB,
      localforage.LOCALSTORAGE,
    ],
    version: 1.0,
  }
}

flacheRequest(url[, options])

  • url A string representing the URL for fetching
  • options Options for the HTTP(S) request
  • Returns: Promise<Response>

Perform an HTTP(S) fetch.

url should be an absolute URL, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.

Options

The default values are shown after each option key.

{
	// These properties are part of the Fetch Standard
	method: 'GET',
	headers: {},            // Request headers. format is the identical to that accepted by the Headers constructor (see below)
	body: null,             // Request body. can be null, or a Node.js Readable stream
	redirect: 'follow',     // Set to `manual` to extract redirect headers, `error` to reject redirect
	signal: null,           // Pass an instance of AbortSignal to optionally abort requests

	// The following properties are node-fetch extensions
	follow: 20,             // maximum redirect count. 0 to not follow redirect
	compress: true,         // support gzip/deflate content encoding. false to disable
	size: 0,                // maximum response body size in bytes. 0 to disable
	agent: null,            // http(s).Agent instance or function that returns an instance (see below)
	highWaterMark: 16384,   // the maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
	insecureHTTPParser: false	// Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Team

License

FlacheJS is developed under the ISC License