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

@heybrostudio/utils

v0.0.13

Published

Opinionated collection of commonly used JavaScript/TypeScript utilities by @heybrostudio

Readme

Features

  • Tree shaking support for optimizing bundle size and improving performance.
  • Full type support to enhance code reliability and maintainability.
  • Includes type utilities for simplifying type operations, increasing development efficiency and code quality.

Install

# npm
npm i @heybrostudio/utils@latest

# yarn
yarn add @heybrostudio/utils@latest

# pnpm 
pnpm add @heybrostudio/utils@latest

# bun
bun add @heybrostudio/utils@latest

Usage

import { sleep } from '@heybrostudio/utils'

await sleep(1000, () => { console.log(`Hey bro, I'm awake.`) })

Functions

console

green

Print green text.

import { green } from '@heybrostudio/utils'

console.log(green('Hey Bro!'))
// output green text: 'Hey Bro!'

cyan

Print cyan text.

import { cyan } from '@heybrostudio/utils'

console.log(cyan('Hey Bro!'))
// output cyan text: 'Hey Bro!'

red

Print red text.

import { red } from '@heybrostudio/utils'

console.log(red('Hey Bro!'))
// output red text: 'Hey Bro!'

gray

Print red text.

import { gray } from '@heybrostudio/utils'

console.log(gray('Hey Bro!'))
// output gray text: 'Hey Bro!'

promise

sleep

Promised setTimeout.

import { sleep } from '@heybrostudio/utils'

await sleep(1000)
console.log('After 1000 ms, the output')

// with callback
await sleep(1000, () => {
  console.log('After 1000 ms, the output')
})

string

camelToUnderscore

Convert camel to underscore.

import { camelToUnderscore } from '@heybrostudio/utils'

console.log(camelToUnderscore('heyBroStudio'))
// output: 'hey_bro_studio'

generateDiscount

Generate a discount code.

import { generateDiscount } from '@heybrostudio/utils'

console.log(generateDiscount())
// output: A1NDU3MA

console.log(generateDiscount(10))
// output: MJA3NZM3MA

// Max 18 digits 
console.log(generateDiscount(20))
// output: MTCXMJKYMJEZMZMXOQ (length: 18)

url

removeTracking

Remove tracking parameters from url.

import { removeTracking } from '@heybrostudio/utils'

const withTrackingUrl = 'https://example.com/page?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale'

const cleanUrl = removeTracking(withTrackingUrl)
console.log(cleanUrl)
// output: https://example.com/page

dom

downloadXlsx

Download of xlsx documents.

import { downloadXlsx } from '@heybrostudio/utils'

// xlsx data via fetch request 
fetch('path/to/your/example.xlsx', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  },
  responseType: 'blob',
})
.then(response => response.blob())
.then(blob => {
  downloadXlsx(blob, 'HeyBroStudio')
}) 
.catch(error => console.error('Error:', error))

node

The following functions are only supported in node runtime environments.

getRootByPackageName

Get the package path of the specified dependency.

import { getRootByPackageName } from '@heybrostudio/utils'

const packageName = '@heybrostudio/biome-config'
const packagePath = getRootByPackageName(packageName)
console.log(packagePath)
// output: `${process.cwd()}/node_modules/@heybrostudio/biome-config`

types

Flatten

Flatten type.

import type { Flatten } from '@heybrostudio/utils'

type test = {
	a: string
	b: number
	c: boolean,
	d: Record<string, any>
	e: Partial<{ f: string, g: string }>
}
type test2 = Pick<test, 'a'>
type test3 = Pick<test, 'b'>
type test4 = Omit<test, 'c'>

type test5 = test2 & test3 & test4
// Hovering over test5 shows:
// type test5 = test2 & test3 & test4

type flattenTest5 = Flatten<test5>
// Hovering over flattenTest5 shows:
/* 
type flattenTest5 = {
  a: string;
  b: number;
  d: {
    [x: string]: any;
  };
  e: {
    f?: string | undefined;
    g?: string | undefined;
  };
}
*/

MayBePromise

Type T or a promise that resolves to type T

import type { MayBePromise } from '@heybrostudio/utils'

type Callback = (param: string) => MayBePromise<number>
// ToEqual: type Callback = (param: string) => number | Promise<number>

IsAny

Check if it is of type any.

import type { IsAny } from '@heybrostudio/utils'

type test = IsAny<any> extends true ? 'YES' : 'NO'
// Hovering over test shows:
// type test = "YES"

Func

Function types that specify parameter and return value types.

import type { Func } from '@heybrostudio/utils'

// Without parameters
type test1 = Func<void>
// Hovering over test shows:
// type test1 = () => void

// The parameter type is any
type test2 = Func<any>
// Hovering over test shows:
// type test2 = (param: any) => void

// Specify the type of parameter
type test3 = Func<number>
// Hovering over test shows:
// type test3 = (param: number) => void

// Specify the return value type
type test4 = Func<number, string>
// Hovering over test shows:
// type test4 = (param: number) => string

Authors

License

MIT License © 2024-PRESENT Caven

This project was created using bun init in bun v1.1.3. Bun is a fast all-in-one JavaScript runtime.