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

fetch-unfucked

v1.2.8

Published

You know how you always have to write a wrapper around fetch to have sensible defaults? This is that wrapper.

Downloads

141

Readme

fetch-unfucked

A zero dependencies, sensible defaults HTTP client based on fetch().

You know how you always have to write a wrapper around fetch to have sensible defaults, for every new project? This is that wrapper.

  • Zero dependencies. No unnecessary fetch polyfills.
  • Works on the browser and node 18
  • TypeScript and ESM obviously.
  • Sensible defaults - sets Accept to JSON by default, sets Content-Type header to use JSON by default.
  • get(), post(), maybe other verbs if you or I add them.
  • Returns a plain JS object with headers, body, and status (as text, not magic numbers).
  • Automatically decodes bodies based on HTTP content types, so JSON response bodies are JS objects, HTML and text bodies are strings.
  • Encodes query strings - instead of a url string, provide an object of the format { url: string; params: Record<string, string>; } and the query parameters will be encoded for you.

It's 100 lines of code, but who wants to write or maintain something that should have been baked in to JavaScript, and that we already had in a billion libraries before fetch decided to come along and have the dumbest defaults since querySelectorAll returned NodeLists? God why can't we have nice things? 🤦🏻‍♂️

Usage:

npm i fetch-unfucked

Importing

import * as http from "fetch-unfucked";

get()

  • urlOrURLWithParams - required. Either a string, or a { string: someURL, params: { encode: me } } if you want some URL parameters to be encoded.
  • headers optional. An object of headers. The Accept header will be set to application/json by default.
  • forceResponseContentType optional. Ignores the content type used by the remote server when decoding the response. This only exists because nftstorage.link uses text/plain for JSON.

Returns a Promise of a Response object, with status, headers, and body

Example: basic get()
import * as http from "fetch-unfucked";

const { body } = await http.get(
  `https://someUrl.com/some/endpoint`
);
const dataICareAbout = body?.info?.resolved || null;

post()

  • urlOrURLWithParams - required. Either a string, or a { string: someURL, params: { encode: me } } if you want some URL parameters to be encoded.
  • headers optional. An object of headers. The Accept header will be set to application/json by default.
  • body optional. The JS object you're posting.
  • forceResponseContentType optional. Ignores the content type used by the remote server when decoding the response. This only exists because nftstorage.link uses text/plain for JSON.

Returns a Promise of a Response object, with status, headers, and body

Example: post() ing to a REST API

This example has a POST body but no headers.

const response = await http.post('/api/v1/proposals', null, {
  direction,
  url,
  currentUserWalletAddress,
  githubAccessToken,
});
Example: post() ing to GitHub

This example encodes some parameters for us:

const response = await http.post(
  { 
    url: 'https://github.com/login/oauth/access_token',
    params: {
      client_id: OAUTH_CLIENT_ID,
      client_secret: OAUTH_CLIENT_SECRET,
      code,
    }
  }
);

More info

The UI is fairly intuitive but look at the TS types for more.

Changelog

1.2

  • Provide a { url, params } object instead of a string to encode query params
  • Set default values if Accept header isn't specified
  • Remove CommonJS

1.0

Initial release

Changes welcomed

Send me a PR.