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

@dcsv-io/d2-utilities

v0.1.11

Published

<!-- Copyright (c) DCSV. Licensed under the Apache License, Version 2.0. -->

Readme

@dcsv-io/d2-utilities

Helpers for values at a boundary: falsey / truthy checks, string cleaning, parse functions that return undefined on failure, indexed environment-variable array parsing, and the regex constants shared across the TypeScript packages. Mirrors DcsvIo.D2.Utilities (.NET).

Install

pnpm add @dcsv-io/d2-utilities

Public API

| Export | Purpose | | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | falsey(value) | True when the value is null, undefined, an empty or whitespace string, or an empty collection. | | truthy(value) | Inverse of falsey. | | toUndefIfEmpty(s) | Returns the trimmed string, or undefined when the input is empty or whitespace. | | cleanStr(s) | Trims, collapses each whitespace run to one space, and returns undefined when the result is empty. | | cleanDisplayStr(s) | Strips characters outside the display-name allowlist, then applies cleanStr. | | tryParseTruthyUndefUuid(s) | Returns the canonical lowercase UUID on success and undefined otherwise (the empty UUID gives undefined). | | tryParseTruthyUndefInt(s) | Returns the parsed integer on success and undefined otherwise. | | tryParseTruthyUndefEnum(enumObj, s) | Returns the canonical key on a case-insensitive match and undefined otherwise. | | chunk(arr, size) | Splits arr into consecutive chunks of size; throws when size < 1. | | clean(items, cleaner, opts?) | Applies a per-element cleaner to any Iterable<T>. opts selects the null and empty handling; the defaults match the .NET version. | | parseEnvArray(prefix, env) | Reads indexed environment-variable arrays such as PREFIX__0=a, PREFIX__1=b, ...; stops at the first gap. | | uuidv7(now?) | Generates a time-ordered RFC 9562 UUIDv7: a 48-bit millisecond timestamp prefix followed by random bits. The optional now argument injects a clock for tests. | | WHITESPACE_RE / DISPLAY_NAME_INVALID_RE / EMAIL_RE / UUID_RE / EMPTY_UUID | Pre-built regular expressions and the canonical empty-UUID constant. |

Dependencies

None. The package has no runtime dependencies.

Usage example

import { falsey, tryParseTruthyUndefUuid, parseEnvArray } from "@dcsv-io/d2-utilities";

if (falsey(input)) return undefined;

const id = tryParseTruthyUndefUuid(headers["x-org-id"]);
if (id === undefined) throw new Error("missing org id");

// Reads AUTH_AUDIENCES__0, AUTH_AUDIENCES__1, ... and stops at the first gap.
const audiences = parseEnvArray("AUTH_AUDIENCES", process.env);

Parity with .NET

Mirrors DcsvIo.D2.Utilities extensions:

  • falsey / truthy -> Falsey() / Truthy() extensions on string / collection / Guid
  • toUndefIfEmpty -> ToNullIfEmpty() on string (same behavior; TS returns undefined and .NET returns null; see Naming divergence from .NET)
  • cleanStr / cleanDisplayStr -> CleanStr() / CleanDisplayStr() on string
  • tryParseTruthyUndefUuid / tryParseTruthyUndefInt / tryParseTruthyUndefEnum -> TryParseTruthyNull(out ...) extensions (same behavior; TS returns undefined and .NET returns null)
  • clean(items, cleaner, opts) -> IEnumerable<T>.Clean(cleaner, enumEmptyBehavior, valueNullBehavior) extension. It has the same default behaviors (ReturnNull / RemoveNulls) and the same throw conditions on each side.
  • parseEnvArray -> matches IConfiguration array binding (PREFIX__INDEX keys)

Naming divergence from .NET

TS helpers use *Undef* names where the .NET equivalent uses *Null*. Each name follows the language's convention for an absent value: undefined in TS, and null in .NET per BCL convention. The behavior is functionally equivalent.

Edge cases

  • tryParseTruthyUndefUuid rejects the empty UUID ("00000000-..."), as .NET collapses Guid.Empty.
  • parseEnvArray stops at the first gap, so sparse arrays collapse to the dense prefix, as in .NET IConfiguration.
  • cleanStr keeps a single space between words and never returns a whitespace-only string.
  • tryParseTruthyUndefInt accepts integers only and rejects floats, scientific notation and integers outside Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER.
  • clean accepts any Iterable<T> (arrays, sets, map values, generators). It always materializes its result as an array, except the null that the ReturnNull behavior returns, and it exhausts a generator in one pass.