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

capns

v0.71.13554

Published

JavaScript implementation of Cap URN (Capability Uniform Resource Names) with strict validation and matching

Readme

Cap URN - JavaScript Implementation

JavaScript implementation of Cap URN (Capability Uniform Resource Names), built on Tagged URN.

Features

  • Required Direction Specifiers - in/out tags for input/output media types
  • Media URN Validation - Validates direction spec values are valid Media URNs
  • Special Pattern Values - * (must-have-any), ? (unspecified), ! (must-not-have)
  • Graded Specificity - Exact values score higher than wildcards
  • Cross-Language Compatible - Identical behavior to Rust, Go, and Objective-C implementations
  • Production Ready - No fallbacks, fails hard on invalid input

Installation

npm install capns

Quick Start

const { CapUrn, CapUrnBuilder, CapMatcher } = require('capns');

// Create from string (with required direction specifiers)
const cap = CapUrn.fromString('cap:in="media:binary";op=extract;out="media:object"');
console.log(cap.toString());

// Use builder pattern
const built = new CapUrnBuilder()
  .inSpec('media:void')
  .outSpec('media:object')
  .tag('op', 'generate')
  .tag('target', 'thumbnail')
  .build();

// Matching
const request = CapUrn.fromString('cap:in="media:binary";op=extract;out="media:object"');
console.log(cap.matches(request)); // true

// Find best match by specificity
const caps = [
  CapUrn.fromString('cap:in=*;op=extract;out=*'),
  CapUrn.fromString('cap:in="media:binary";op=extract;out="media:object"'),
  CapUrn.fromString('cap:ext=pdf;in="media:binary";op=extract;out="media:object"')
];
const best = CapMatcher.findBestMatch(caps, request);
console.log(best.toString()); // Most specific match

API Reference

CapUrn Class

Static Methods

  • CapUrn.fromString(s) - Parse Cap URN from string
    • Throws CapUrnError on invalid format or missing direction specifiers

Instance Methods

  • toString() - Get canonical string representation
  • getTag(key) - Get tag value (case-insensitive)
  • getInSpec() - Get input media type
  • getOutSpec() - Get output media type
  • hasTag(key, value) - Check if tag exists with value
  • withTag(key, value) - Add/update tag (returns new instance)
  • withoutTag(key) - Remove tag (returns new instance)
  • matches(other) - Check if this cap matches another
  • canHandle(request) - Check if this cap can handle a request
  • specificity() - Get specificity score for matching
  • isMoreSpecificThan(other) - Compare specificity
  • equals(other) - Check equality

CapUrnBuilder Class

Fluent builder for constructing Cap URNs:

const cap = new CapUrnBuilder()
  .inSpec('media:binary')
  .outSpec('media:object')
  .tag('op', 'extract')
  .tag('target', 'metadata')
  .build();

CapMatcher Class

Utility for matching sets of caps:

  • CapMatcher.findBestMatch(caps, request) - Find most specific match
  • CapMatcher.findAllMatches(caps, request) - Find all matches (sorted by specificity)

Error Handling

const { CapUrnError, ErrorCodes } = require('capns');

try {
  const cap = CapUrn.fromString('cap:op=extract'); // Missing in/out
} catch (error) {
  if (error instanceof CapUrnError) {
    console.log(`Error code: ${error.code}`); // MISSING_IN_SPEC
  }
}

Cap-specific error codes:

  • ErrorCodes.MISSING_IN_SPEC - Missing required in tag
  • ErrorCodes.MISSING_OUT_SPEC - Missing required out tag
  • ErrorCodes.INVALID_MEDIA_URN - Invalid Media URN in direction spec

For base Tagged URN error codes, see Tagged URN documentation.

Documentation

Testing

npm test

Cross-Language Compatibility

This JavaScript implementation produces identical results to:

All implementations pass the same test cases and follow identical rules.