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

@happyvertical/utils

v0.74.10

Published

Foundation utilities for ID generation, date parsing, URL handling, string conversion, error handling, and logging

Readme

@happyvertical/utils

Foundation utilities for the HAVE SDK: ID generation, date parsing, URL handling, string conversion, error classes, logging, code extraction/validation/sandboxing, CLI argument parsing, and environment config loading.

Installation

pnpm add @happyvertical/utils

A browser-safe entry point is available at @happyvertical/utils/browser (excludes Node.js-specific code like node:vm sandbox and node:crypto hashing).

Usage

ID Generation

import { makeId, createId, isCuid } from '@happyvertical/utils';

const id = makeId();         // CUID2 (default)
const uuid = makeId('uuid'); // UUID via crypto.randomUUID()
const cuid = createId();     // CUID2 directly
isCuid(id);                  // true

String & URL Utilities

import { camelCase, snakeCase, keysToCamel, keysToSnake, makeSlug, urlFilename, isUrl } from '@happyvertical/utils';

camelCase('hello-world');      // "helloWorld"
snakeCase('helloWorld');       // "hello_world"
keysToCamel({ user_name: 'j' }); // { userName: 'j' } (recursive)
makeSlug('My Title & Co.');   // "my-title-38-co"
urlFilename('https://example.com/path/file.pdf'); // "file.pdf"
isUrl('https://example.com'); // true

Date Utilities

import { dateInString, formatDate, parseDate, parseAmazonDateString, addInterval } from '@happyvertical/utils';

dateInString('Report_January_15_2023.pdf'); // Date(2023, 0, 15)
formatDate(new Date(), 'yyyy-MM-dd');       // "2023-01-15"
parseDate('2023-01-15');                    // Date object (ISO)
parseDate('01/15/2023', 'MM/dd/yyyy');      // Date object (custom format)
parseAmazonDateString('20220223T215409Z');   // Date object
addInterval(new Date(), { days: 7 });       // Date 7 days from now

Error Classes

All extend BaseError with code, context, and timestamp fields, plus toJSON():

import { ValidationError, ApiError, NetworkError, TimeoutError, ParsingError, FileError, DatabaseError } from '@happyvertical/utils';

throw new ValidationError('Invalid email', { field: 'email', value: input });

Code Extraction & Sandbox

Extract code blocks from markdown/AI responses, validate, and execute in isolated node:vm contexts:

import { extractCodeBlock, extractJSON, validateCode, executeInSandbox } from '@happyvertical/utils';

const code = extractCodeBlock(markdownText, 'javascript');
const data = extractJSON<{ name: string }>(aiResponse);

const result = validateCode(code, { maxLength: 10000 });
if (result.valid) {
  const output = executeInSandbox(code, { globals: { data }, timeout: 5000 });
}

CLI Argument Parsing

import { parseCliArgs } from '@happyvertical/utils';

const parsed = parseCliArgs(process.argv, [
  { name: 'build', description: 'Build project', options: { output: { type: 'string', description: 'Output dir' } } }
]);
// { command: 'build', args: [], options: { output: './dist' } }

Environment Config

import { loadEnvConfig } from '@happyvertical/utils';

// Loads HAVE_AI_* env vars, merged with user options (user options take precedence)
const config = loadEnvConfig({ provider: 'openai' }, {
  packageName: 'ai',
  schema: { provider: 'string', model: 'string', timeout: 'number' }
});

Logging

import { getLogger, setLogger, disableLogging } from '@happyvertical/utils';

const logger = getLogger();
logger.info('Started', { userId: 123 });
disableLogging(); // Switch to no-op logger

API Reference

IDsmakeId(type?), createId(), isCuid(id)

StringscamelCase(str), snakeCase(str), keysToCamel(obj), keysToSnake(obj), domainToCamel(str), makeSlug(str)

URLsurlFilename(url), urlPath(url), isUrl(str), normalizeUrl(url), generateScopeFromUrl(url), hashPageContent(html)

DatesdateInString(str), prettyDate(str), parseAmazonDateString(str), formatDate(date, format?), parseDate(str, format?), isValidDate(date), addInterval(date, duration)

PluralizationpluralizeWord(word), singularize(word), isPlural(word), isSingular(word)

Type GuardsisArray(obj), isPlainObject(obj)

AsyncwaitFor(fn, options?), sleep(ms)

CodeextractCodeBlock(text, lang?), extractAllCodeBlocks(text, lang?), extractJSON<T>(text), extractFunctionDefinition(code, name), validateCode(code, options?), isSafeCode(code), createSandbox(options?), executeCode(code, sandbox, options?), executeCodeAsync(code, sandbox, options?), executeInSandbox(code, options?), executeInSandboxAsync(code, options?)

CLIparseCliArgs(argv, commands, builtInCommands?)

ConfigloadEnvConfig<T>(userOptions?, options?), toCamelCase(str), toScreamingSnakeCase(str), convertType(value, type)

LogginggetLogger(), setLogger(logger), disableLogging(), enableLogging()

MisclogTicker(tick, options?), getTempDirectory(subfolder?)

Error ClassesBaseError, ValidationError, ApiError, FileError, NetworkError, DatabaseError, ParsingError, TimeoutError

TypesLogger, ErrorCode, Command, OptionConfig, ParsedArgs, ConfigOptions<T>, ValidationOptions, ValidationResult, SandboxOptions, ExecuteOptions

License

MIT