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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@noshot/utils

v1.0.1

Published

Helpful utility functions for node projects

Readme

A handful of helpful utility functions.

Quick Links

Installation

Utility Functions

ESM Support

Installation

# with npm
npm install @noshot/utils react react-dom

# or with yarn
yarn add @noshot/utils react react-dom

Utility Functions

A list of functions that are exported from this package.

compressFiles

This asynchronous function utilizes terser to compress an array of files with optional minify options.

Dependencies: terser

Arguments (2):

files: Array<string>,
opts?: MinifyOptions

Example:

import { compressFiles } from "@noshot/utils";
// import compressFiles from "@noshot/utils/compressFiles";

(async(): Promise<void> => {
  const dirs = [
      "folder1",
      "folder2",
      "folder3"
    ].map(file => `${file ? `${file}/` : ""}index.js`);

  await compressFiles(dirs);
  process.exit(0);
})();

fileExists

This synchronous function utilizes node's fs API to check if a file exists.

Dependencies: (none if using node v12+)

Arguments (1):

file: string

Example:

import { getFilePath, fileExists } from "@noshot/utils";
// import getFilePath from "@noshot/utils/getFilePath";
// import fileExists from "@noshot/utils/fileExists";

((): void => {
  const path = getFilePath("hello.js") // process.cwd() + hello.js
  const result = fileExists(path);
  console.log(typeof result, result) // boolean, true/false
  process.exit(0);
})();

getFilePath

This synchronous function utilizes node's path API to join a directory path with a file name.

Dependencies: (none if using node v12+)

Arguments (2):

file: string,
dir?: string

Example:

import { getFilePath } from "@noshot/utils";
// import getFilePath from "@noshot/utils/getFilePath";

((): void => {
  const path = getFilePath("hello.js") // process.cwd() + hello.js
  console.log(typeof path, path) // string, "path/to/project/hello.js"

  const customPath = getFilePath("hello.js", "src"); // src + hello.js (path starts from project directory)
  console.log(typeof customPath, customPath) // string, "path/to/project/src/hello.js"
  process.exit(0);
})();

removeFiles

This asynchronous function utilizes rimraf to remove an array of files with optional rimraf options.

Dependencies: rimraf

Arguments (2):

files: Array<string>,
opts?: rimraf.Options

Example:

import { removeFiles } from "@noshot/utils";
// import removeFiles from "@noshot/utils/removeFiles";

(async(): Promise<void> => {
  const dirs = [
      "folder1",
      "folder2",
      "folder3"
    ].map(file => `${file ? `${file}/` : ""}index.js`);

  await removeFiles(dirs);
  process.exit(0);
})();

waitFor

This asynchronous function waits for promisified expectations to resolve. It works by trying to resolve the callback every 50ms within the specified timeout; otherwise, it rejects the promise by throwing an error. Useful for tests that may take an unknown amount of time to resolve.

Dependencies: (none if using node v12+)

Arguments (2):

callback: Function,
timeout?: string // default 1000ms

Example:

import { waitFor } from "@noshot/utils";
// import waitFor from "@noshot/utils/waitFor";

it("waits for an asynchronous expectation to succeed", async () => {
  await waitFor(() => {
    expect(result).toEqual("hi");
  });
});

waitForAct

This asynchronous function utilizes ReactDOM to wait for promisified expectations wrapped in act to resolve. It works by trying to resolve the callback every 50ms within the specified timeout; otherwise, it rejects the promise by throwing an error. Useful for React tests where expectations may take an unknown amount of time to resolve. This function should work with any testing suite, as long as it supports resolving promises.

Dependencies: React, ReactDOM

Arguments (2):

callback: Function,
timeout?: string // default 1000ms

Example:

import * as React from "react";
import { waitForAct } from "@noshot/utils";
// import waitForAct from "@noshot/utils/waitForAct";
import { mount } from "enzyme"
import Example from "../index";

const wrapper = mount(<Example />);

it("waits for an asynchronous expectation to succeed", async () => {
  await waitForAct(() => {
    expect(wrapper.find(".example").exists()).toBeTruthy();
  });
});

ESM Support

As of Node v12.17.0+, node removed the experimental flag for ES modules. Unfortunately, most of development world has yet to adopt ESM as the standard. Therefore, until there's more widespread support, this documentation will caution against using ESM and instead opt for CJS. In addition, node doesn't support preloading ESM, since preloading utilizes Node's require function. That said, this package offers experimental support for ESM. You can try it out by importing from the esm directory of the package:

import utils from "@noshot/utils/esm";
// import { compressFiles, fileExists, getFilePath, ...etc } from "@noshot/utils/esm";
// import compressFiles from "@noshot/utils/esm/compressFiles";

Contributing Guide

See CONTRIBUTING.md