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

undici-shim

v1.5.3

Published

Provides Undici request in Node, native fetch in the browser.

Downloads

88

Readme

undici-shim Codacy Badge GitHub repo size

A small ESM/UMD library providing the fast request function from Undici within Node, otherwise window.fetch is utilized when running in a browser environment.

Why?

Upon trying to distribute a project, I found Undici could not be used on the client-side. As such, this is a drop-in replacement for Undici when using bundlers like webpack/rollup.

Without the overhead of WHATWG Streams, the request method proves much faster than fetch in both latency and throughput.

| Tests | Samples | Results | Tolerance | Difference with slowest | |---------------------|---------|------------------|-----------|-------------------------| | undici - fetch | 20 | 1028.31 req/sec | ± 2.71 % | - | | http - no keepalive | 10 | 3891.51 req/sec | ± 2.00 % | + 278.44 % | | undici - pipeline | 95 | 6034.47 req/sec | ± 2.95 % | + 486.83 % | | http - keepalive | 50 | 6382.57 req/sec | ± 2.98 % | + 520.68 % | | undici - request | 15 | 8528.35 req/sec | ± 2.11 % | + 729.35 % |

Install

npm i undici-shim

Usage

ESM

import request from 'undici-shim'
const res = await request('https://jsonplaceholder.typicode.com/posts/1')

console.log(await res.body.json())

You can also use Undici fetch instead of request for consistency across environments.

import { fetch } from 'undici-shim'
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1')

console.log(await res.json())

CommonJS

const { fetch } = require('undici-shim')

fetch('https://jsonplaceholder.typicode.com/posts/1')
    .then(res => res.json())
    .then(console.log)

Named Exports

Node Starting from v1.3.2, named exports are identical to Undici.

import { request, Dispatcher, Headers, ... } = from 'undici-shim'

Browser

import { fetch, Request, Response, Headers } = from 'undici-shim'