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

@pavelpotemkin/utils

v1.1.0

Published

Shared TypeScript utilities: Result type, HTTP client, validation, formatting

Readme

@pavelpotemkin/utils

Shared TypeScript utilities: Result type, HTTP client, validation, formatting.

Install

npm install @pavelpotemkin/utils

API

Result

import { Ok, Err, isOk, isErr, unwrap, type Result } from '@pavelpotemkin/utils'

const result: Result<number> = Ok(42)

if (isOk(result)) {
  console.log(result.value) // 42
}

unwrap(Ok(42))          // 42
unwrap(Err(new Error())) // throws

HttpClient

Axios-обёртка, возвращающая Result вместо исключений. Поддерживает zod-валидацию ответов.

import { HttpClient } from '@pavelpotemkin/utils'
import { z } from 'zod'

const client = new HttpClient({
  baseURL: 'https://api.example.com',
  headers: { Authorization: 'Bearer token' },
  timeout: 5000,
})

const UserSchema = z.object({ id: z.number(), name: z.string() })

const result = await client.get('/users/1', { schema: UserSchema })

if (isOk(result)) {
  console.log(result.value) // { id: 1, name: "..." }
}

Методы: get, post, put, patch, delete.

Request options:

  • params — query params, arrays serialize as comma-separated values
  • schema — zod-compatible schema with safeParse
  • headers — request-level headers
  • signalAbortSignal for request cancellation

Ошибки:

  • ApiError — HTTP ошибки (4xx, 5xx) с полями status, body, endpoint
  • ResponseValidationError — невалидный ответ по zod-схеме
  • NetworkError — сетевые ошибки

Validation

import { validateSchema, mustValue } from '@pavelpotemkin/utils'
import { z } from 'zod'

const data = validateSchema(z.object({ name: z.string() }), input) // throws ValidationError

const user = mustValue(maybeUser, 'User not found') // throws if null/undefined

Format

import { formatFloatLine, formatCount } from '@pavelpotemkin/utils'

formatFloatLine(1234.5678, { accuracy: 2 })  // "1234.57"
formatFloatLine(1.999, { accuracy: 2, rounding: Decimal.ROUND_DOWN }) // "1.99"

formatCount(1500)       // { full: "1.5K", value: "1.5", postfix: "K", raw: Decimal }
formatCount(2_500_000)  // { full: "2.5M", ... }

Nano

import { fromNanoToDecimal, fromDecimalToNano } from '@pavelpotemkin/utils'

fromNanoToDecimal('1500000000') // Decimal(1.5)
fromDecimalToNano(new Decimal(1.5)) // 1500000000

Utils

import {
  awaitMs,
  getRandomInt,
  debounce,
  throttle,
  createDelayedResolver,
  hexToRgba,
} from '@pavelpotemkin/utils'

await awaitMs(100)
getRandomInt(1, 10)

const { debouncedFunction, cancel } = debounce(fn, 300)
const throttled = throttle(fn, 100)

const { promise, resolve } = createDelayedResolver<string>()

hexToRgba('#ff0000', 0.5) // "rgba(255, 0, 0, 0.5)"

Types

import type { Optional, Brand } from '@pavelpotemkin/utils'

type UserId = Brand<string, 'UserId'>
const name: Optional<string> = null // string | null | undefined