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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@agusmgarcia/react-essentials-utils

v0.13.0

Published

Set of opinionated utilities for NextJS applications, libraries and Azure functions

Readme

React Essentials Utils

A set of functions and types that can be used in the consumer projects.

Aggregate response

const result = await aggregateResponse(
  (pageIndex, pageSize) =>
    fetch(`/api?page=${pageIndex}&limit=${pageSize}`).then((result) =>
      result.json(),
    ),
  10,
);

Async func

import { type AsyncFunc } from "@agusmgarcia/react-essentials-utils";

type Func1 = AsyncFunc; // => () => Promise<void>
type Func2 = AsyncFunc<number>; // => () => Promise<number>
type Func3 = AsyncFunc<number, [arg0: string]>; // => (arg0: string) => Promise<number>

Cache

import { Cache } from "@agusmgarcia/react-essentials-utils";

const cache = new Cache();
cache
  .getOrCreate("key", () => {
    // Run some exclusive function.
  })
  .then((result) => console.log(result));

Children

import { children } from "@agusmgarcia/react-essentials-utils";

const MyComponent = () => (
  <div>
    <input />
  </div>
);

const children = children.mapOfType(input, MyComponent, (child) => (
  <p>input replaced</p>
)); // => <div><p>input replaced</p></div>

const isMyComponent = children.isOfType(MyComponent, <MyComponent />); // => true;

Dates

import { dates } from "@agusmgarcia/react-essentials-utils";

dates.addDays("1995-06-17", 1); // => "1995-06-18"
dates.addMonths("1995-06-17", 1); // => "1995-07-17"
dates.addYears("1995-06-17", 1); // => "1996-06-17"
dates.clamp("1995-06-17", "1995-06-12", "1995-06-18"); // => "1995-06-17"
dates.differenceInDays("1995-06-17", "1995-05-30"); // => 18
dates.getCurrentDate(); // => the current date considering the timeZone
dates.getDate("1995-06-17"); // => 17
dates.getDayOfTheWeek("1995-06-17"); // => 6
dates.getFirstDateOfMonth("1995-06-17"); // => "1995-06-01"
dates.getLastDateOfMonth("1995-06-17"); // => "1995-06-30"
dates.getMonth("1995-06-17"); // => 6
dates.getYear("1995-06-17"); // => 1995
dates.max("1995-06-17", "1995-06-18", "1995-06-12"); // => "1995-06-18"
dates.min("1995-06-17", "1995-06-18", "1995-06-12"); // => "1995-06-12"
dates.toDateString("1995-06-17", "en-US", { day: "2-digit" }); // => "17"
dates.toString(new Date(1995, 5, 17)); // => "1995-06-17"
dates.validate("1995-06-17"); // => true

Delay

import { delay } from "@agusmgarcia/react-essentials-utils";

delay(2000).then(() => console.log("Done"));

Empty function

import { emptyFunction } from "@agusmgarcia/react-essentials-utils";

const function = emptyFunction;

Equals

import { equals } from "@agusmgarcia/react-essentials-utils";

equals.strict(1, 1); // => true
equals.shallow({ name: "john" }, { name: "john" }); // => true
equals.deep(
  { name: "john", address: { street: "doe" } },
  { name: "john", address: { street: "doe" } },
); // => true

Errors

import { errors } from "@agusmgarcia/react-essentials-utils";

errors.handle(
  () => {
    throw new Error();
  },
  (error) => {
    // Proper error handling
  },
);

errors.getMessage(new Error("My message")); // => "My message"

const result = input.startsWith("a")
  ? true
  : errors.emit("Input should start with 'a'");

Files

import { files } from "@agusmgarcia/react-essentials-utils";

files.isFile("src/index.json"); // => true if the path belongs to a file or throw error if it doesn't exist
files.readFile("src/index.json"); // => a string representing the content of the file
files.readRequiredFile("src/index.json"); // => a string representing the content of the file or throw error if it doesn't exist
files.removeFile("src/index.json"); // => remove the file
files.upsertFile("src/index.json", JSON.stringify({})); // => create or update the file

Filters

import { filters } from "@agusmgarcia/react-essentials-utils";

const array = [17, 6, 95, 6];

array.filter(filters.distinct); // => [17, 6, 95]
array.filter(filters.paginate(1, 2)); // => [17, 6]

Finds

import { finds } from "@agusmgarcia/react-essentials-utils";

const array = [17, 6, 95];

array.find(finds.first); // => 17
array.find(finds.single); // => throws error
array.find(finds.singleOrDefault); // => undefined

Folders

import { folders } from "@agusmgarcia/react-essentials-utils";

folders.readFolder("src"); // => a list of files
folders.removeFolder("src"); // => delete a folder
folders.removeFolderIfEmpty("src"); // => delete a folder if empty
folders.upsertFolder("src"); // => create a folder if it doesn't exist

Func

import { type Func } from "@agusmgarcia/react-essentials-utils";

type Func1 = Func; // => () => void
type Func2 = Func<number>; // => () => number
type Func3 = Func<number, [arg0: string]>; // => (arg0: string) => number

Is method overridden

import { isMethodOverridden } from "@agusmgarcia/react-essentials-utils";

class GrandParent {
  myMethod() {
    // ...
  }

  myOtherMethod() {
    // ...
  }
}

class Parent extends GrandParent {}

class Child extends Parent {
  override myMethod() {
    // ...
  }
}

isMethodOverridden(new Child(), GrandParent.prototype, "myMethod"); // => Child.prototype
isMethodOverridden(new Child(), GrandParent.prototype, "myOtherMethod"); // => undefined

Is SSR

import { isSSR } from "@agusmgarcia/react-essentials-utils";

isSSR(); // => 'true' if server side and 'false' for client

Merges

import { merges } from "@agusmgarcia/react-essentials-utils";

merges.shallow({ name: "John" }, { surname: "Doe" }); // => { name: "John", surname: "Doe" }
merges.deep(
  [{ name: "John" }, { name: "Foo" }],
  [{ surname: "Doe" }, { surname: "Bar" }],
); // => [{ name: "John", surname: "Doe" }, { name: "Foo", surname: "Bar" }];

Properties

import { properties } from "@agusmgarcia/react-essentials-utils";

properties.has({ foo: 123 }, "foo"); // => true
properties.sort({ b: 2, a: { y: 2, x: 1 }, c: 3 }, [
  "a",
  "a.x",
  "a.y",
  "b",
  "c",
]); // => { a: { x: 1, y: 2 }, b: 2, c: 3 }

Strings

import { strings } from "@agusmgarcia/react-essentials-utils";

strings.capitalize("foo"); // => "Foo"
strings.uncapitalize("Foo"); // => "foo"
strings.replace("This is the ${value} test", { value: "third" }); // => "This is the third test"
strings.replace("${nights} ${nights?night:nights}", { nights: 1 }); // => "1 night"
strings.replace("${nights} ${nights?night:nights}", { nights: 2 }); // => "2 nights"

Sorts

import { sorts } from "@agusmgarcia/react-essentials-utils";

[1, 2].sort(sorts.byNumberAsc); // => [1, 2]
[1, 2].sort(sorts.byNumberDesc); // => [2, 1]
["john", "doe"].sort(sorts.byStringAsc); // => ["doe", "john"]
["john", "doe"].sort(sorts.byStringDesc); // => ["john", "doe"]
[false, true].sort(sorts.byBooleanAsc); // => [true, false]
[false, true].sort(sorts.byBooleanDesc); // => [false, true]

Storage cache

import { StorageCache } from "@agusmgarcia/react-essentials-utils";

const cache = new StorageCache("myCache", "session");
cache
  .getOrCreate("key", () => {
    // Run some exclusive function.
  })
  .then((result) => console.log(result));

Tuple

import { type Tuple } from "@agusmgarcia/react-essentials-utils";

type TupleOfThreeStrings = Tuple<string, 3>; // => [string, string, string]

Use device pixel ratio

import { useDevicePixelRatio } from "@agusmgarcia/react-essentials-utils";

function useHook() {
  const devicePixelRatio = useDevicePixelRatio(); // => window.devicePixelRatio
}

Use dimensions

import { useDimensions } from "@agusmgarcia/react-essentials-utils";

function useHook() {
  const ref = useRef<HTMLElement>(null);
  const dimensions = useDimensions(ref); // => The width and height of the element.
}

Use element at bottom

import { useElementAtBottom } from "@agusmgarcia/react-essentials-utils";
import { useRef } from "react";

function useHook() {
  const ref = useRef<HTMLElement>(null);
  const atBottom = useElementAtBottom(ref); // => true if the element has been scrolled at bottom
}

Use element at top

import { useElementAtTop } from "@agusmgarcia/react-essentials-utils";
import { useRef } from "react";

function useHook() {
  const ref = useRef<HTMLElement>(null);
  const atTop = useElementAtTop(ref); // => true if the element has been scrolled at top
}

Use media query

import { useMediaQuery } from "@agusmgarcia/react-essentials-utils";

function useHook() {
  const isTablet = useMediaQuery("(max-width: 767.98px)"); // => boolean
}