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

@igoforth/ts-utils

v0.1.0

Published

TypeScript utilities - caching, memoization, decorators, async, and more

Readme

@igoforth/ts-utils

TypeScript utilities for modern applications - featuring caching, memoization, decorators, async primitives, and more.

Features

  • Caching: LRU cache, instance cache, callback cache
  • Memoization: Advanced memoization with WeakMap support
  • Async Utilities: Mutex, async queue, pause
  • Decorators: Injectable, Log, ReadOnly, Catch for TypeScript decorators
  • Type Guards: Comprehensive runtime type checking
  • Object Utilities: Deep clone, merge, path operations
  • JSON Utilities: Deep diff, clone, walk, apply
  • Number Utilities: Clamp, rounding, modulus, range checking
  • Hash Utilities: Stable JSON hashing
  • Utility Types: Advanced TypeScript type utilities

Installation

pnpm add @igoforth/ts-utils

Usage

Caching

import { LRUCache, InstanceCache, CallbackCache } from '@igoforth/ts-utils/cache'

// LRU Cache
const cache = new LRUCache<string, number>(5)
cache.set('key', 42)
const value = cache.get('key') // 42

// Instance Cache
class MyClass {
  constructor(public id: string) {}
}
const instanceCache = new InstanceCache(MyClass)
const instance = await instanceCache.getOrCreateInstance('id1')

// Callback Cache
const callbackCache = new CallbackCache()
const result = callbackCache.call(expensiveFunction, arg1, arg2)

Async Utilities

import { Mutex, AsyncAwaitQueue, pause } from '@igoforth/ts-utils/async'

// Mutex for exclusive access
const mutex = new Mutex()
await mutex.acquire(async () => {
  // Critical section
})

// Async queue with timeout
const queue = new AsyncAwaitQueue()
const success = await queue.await(100)
queue.notify()

// Async pause
await pause()

Memoization

import { memo, simpleMemorize } from '@igoforth/ts-utils/memo'

// Memoize function generators
const fn = memo({ key: 'value' }, (params) => () => {
  return computeExpensiveValue(params)
})

// Simple memoization
const memoized = simpleMemorize((a: number, b: number) => a + b)

Decorators

import { Injectable, Log, ReadOnly, Catch, instrument } from '@igoforth/ts-utils/decorators'

@Injectable()
class MyService {
  @Log('info')
  async fetchData() {
    return await fetch('/api/data')
  }

  @Catch('null', true)
  async mayFail() {
    return await riskyOperation()
  }
}

// Function instrumentation
const instrumented = instrument('myFunction', myFunction)

Type Guards

import {
  isDefined,
  isArray,
  isObject,
  isUnknownRecord,
  isString,
  isNumber,
} from '@igoforth/ts-utils/guards'

if (isDefined(value)) {
  // value is not null or undefined
}

if (isUnknownRecord(obj)) {
  // obj is a plain object
}

Object Utilities

import {
  objectsEqual,
  mergeDefaults,
  deepFreeze,
  getPath,
  setPath,
} from '@igoforth/ts-utils/object'

// Deep equality check
const equal = objectsEqual(obj1, obj2)

// Merge with defaults
const config = mergeDefaults(userConfig, defaultConfig)

// Deep freeze
const frozen = deepFreeze(obj)

// Path operations
const value = getPath(obj, 'a.b.c')
setPath(obj, 'a.b.c', newValue)

JSON Utilities

import {
  jsonDiff,
  deepClone,
  shallowClone,
  jsonWalk,
} from '@igoforth/ts-utils/json'

// JSON diff
const diff = jsonDiff(oldData, newData)

// Deep clone
const clone = deepClone(originalObject)

// Walk JSON tree
jsonWalk(data, (node) => {
  console.log(node)
  return acc
})

Number Utilities

import {
  clamp,
  round,
  mod,
  isNumberEqual,
  findMinMax,
} from '@igoforth/ts-utils/number'

// Clamp value
const clamped = clamp(0, value, 100)

// Round to decimals
const rounded = round(3.14159, 2) // 3.14

// True modulus (not remainder)
const modulo = mod(-5, 3) // 1

// Epsilon equality
const equal = isNumberEqual(0.1 + 0.2, 0.3) // true

Hash Utilities

import { calculateHash } from '@igoforth/ts-utils/hash'

const hash = calculateHash({ key: 'value', nested: { data: 123 } })
// Produces stable SHA-256 hash

License

MIT