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

@typesugar/contracts-refined

v0.1.0

Published

🧊 Integrate @typesugar/contracts with @typesugar/type-system refinement types — single source of truth for type predicates

Readme

@typesugar/contracts-refined

Refinement type integration for @typesugar/contracts.

Overview

@typesugar/contracts-refined bridges @typesugar/type-system refinement types with @typesugar/contracts compile-time verification. Import this module once to enable the prover to understand and verify refinement type predicates automatically.

Installation

npm install @typesugar/contracts-refined
# or
pnpm add @typesugar/contracts-refined

Usage

// In your entry point or setup file:
import "@typesugar/contracts-refined";

// Now refined types work seamlessly with contracts:
import { Positive, Byte, Port } from "@typesugar/type-system";
import { contract } from "@typesugar/contracts";

@contract
function add(a: Positive, b: Positive): number {
  requires: { a > 0 && b > 0 } // Proven by type, eliminated at compile-time
  ensures: { result > 0 }      // Also provable: sum of positives is positive
  return a + b;
}

What Gets Registered

All built-in refinement types from @typesugar/type-system:

| Category | Types | | ------------- | ------------------------------------------------------------------------------------ | | Numeric | Positive, NonNegative, Negative, Int, Byte, Port, Percentage, Finite | | String | NonEmpty, Trimmed, Lowercase, Uppercase, Email, Url, Uuid | | Array | NonEmptyArray | | Dependent | Vec<N> (length-indexed vectors) |

Subtyping Coercions

The integration registers subtyping rules that enable safe widening:

  • PositiveNonNegative (x > 0 implies x >= 0)
  • ByteNonNegative, Int
  • PortPositive, NonNegative, Int
  • PercentageNonNegative

This allows the prover to verify safe coercions at compile time.

Custom Refinements

Register predicates for custom refinement types:

import { registerRefinementPredicate } from "@typesugar/contracts-refined";

// Register your custom refinement
registerRefinementPredicate("PositiveEven", "$ > 0 && $ % 2 === 0");

// Now the prover knows about your custom type
type PositiveEven = Refined<number, "PositiveEven">;

@contract
function halve(n: PositiveEven): number {
  ensures: { result > 0 }  // Provable: n/2 where n > 0 is positive
  return n / 2;
}

API Reference

Functions

  • registerRefinementPredicate(brand, predicate, decidability?) — Register a custom refinement predicate
  • getRegisteredPredicates() — Get all registered predicates (built-in + custom)
  • hasRefinementPredicate(brand) — Check if a predicate is registered

Re-exports from @typesugar/contracts

  • getRefinementPredicate(), registerSubtypingRule(), canWiden()
  • registerDecidability(), getDecidability(), isCompileTimeDecidable()
  • registerDynamicPredicateGenerator() — For parameterized types like Vec<N>

Re-exports from @typesugar/type-system

  • All refinement types and their utilities
  • Vec, isVec, extractVecLength, generateVecPredicate
  • widen(), widenTo(), isSubtype()

License

MIT