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

@nostrwatch/utils

v0.2.0

Published

Shared utility functions used across the nostr-watch monorepo.

Downloads

19

Readme

@nostrwatch/utils

Shared utility functions used across the nostr-watch monorepo.

Scope License Status

Overview

@nostrwatch/utils provides a collection of utility modules shared across the monorepo. It covers key management and conversion (nsec/hex), array helpers, environment file access, event signing, browser/runtime detection, URL parsing and normalization, string helpers, object utilities, control flow helpers, and network utilities. Each module is independently importable — import only what you need. The package builds for both Node.js and browser environments.

Installation

This is an internal monorepo package. Add it as a workspace dependency:

pnpm add @nostrwatch/utils --filter @nostrwatch/your-package

It is not published to npm.

Quick Start

import {nsecToHex, tryNsecToHex} from '@nostrwatch/utils'
import {shuffleArray, chunkArray} from '@nostrwatch/utils'
import {isBrowser} from '@nostrwatch/utils'

// Convert an nsec private key to hex (throws on invalid input)
const hexKey = nsecToHex('nsec1...')

// Safe version — returns empty string on failure
const safeHex = tryNsecToHex(process.env.NOSTR_KEY)

// Shuffle an array in place, then split into chunks of 10
const relays = ['wss://relay.damus.io', 'wss://nos.lol']
chunkArray(relays, 10) // => [['wss://relay.damus.io', 'wss://nos.lol']]

// Detect runtime environment
if (isBrowser()) {
  console.log('running in browser')
}

API

The package exports roughly 15 modules. The most commonly used are:

Keys (keys.ts)

function nsecToBytes(key: string): Uint8Array
function nsecToHex(key: string): string
function tryNsecToHex(key: string | undefined): string

Converts Nostr private keys between formats. Accepts nsec1… bech32 strings or 64-character hex strings. nsecToBytes and nsecToHex throw Error on invalid input; tryNsecToHex returns an empty string instead of throwing — use this when reading from environment variables.

Signing (signing.ts)

interface EventSigner {
  pubkey: string
  sign(event: UnsignedEvent): VerifiedEvent
}

function createSigner(key: string): EventSigner

Creates an EventSigner from an nsec or hex private key. The returned signer holds the derived public key and can sign any unsigned Nostr event (a signed JSON object — the fundamental unit of the Nostr protocol). Internally wraps nostr-tools/pure.

Arrays (array.ts)

function shuffleArray<T>(array: T[]): void
function chunkArray<T>(arr: T[], chunkSize: number): T[][]

shuffleArray shuffles an array in place using Fisher-Yates. chunkArray shuffles the array first, then splits it into chunks of the given size. Throws if chunkSize <= 0.

URL (url.ts)

function parseUrl(url: string): URL | null
function normalizeUrl(url: string): string

parseUrl wraps the URL constructor and returns null on invalid input instead of throwing. normalizeUrl returns the canonical string form of a URL, or the original input if parsing fails.

Browser detection (browser.ts)

function isBrowser(): boolean

Returns true when running in a browser or Web Worker context. Correctly identifies Node.js, Deno, and browser environments. Safe to call in any context.

For the full export list, see src/index.ts.

Known Limitations

No known limitations at this time.

Agent Skills

No agent skills defined yet for this package.

Related Packages

License

MIT