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

@webfeet/webidl

v0.1.0

Published

Functions and decorators implementing the WebIDL type coercion rules

Readme

@webfeet/webidl

This package implements the WebIDL type coercion rules, with exceptions for some edge cases to keep the library lightweight.

Deviations from WebIDL

  • integer types that are clamped to their value range use Math.round() rules for rounding rather than rounding to the closest even number for halfway values (such that 0.5 rounds to 1 rather than 0 for instance).

TODO

Currently, scalar values (boolean, integer and floating-point numbers, bigint, strings, and symbol) as well as object, callback functions, arrays (sequence and FrozenArray), interface types, enumeration types, records, and Promise are implemented; This means that only unions and buffer sources (typed arrays and array views) are missing.

API

This package exports functions whose name starts with coerceTo, that take a value as their single argument, and return that value coerced to the according IDL type. IDL integer types come with variants prefixed with Clamped and Enforced corresponding to the [Clamp] and [EnforceRange] extended attributes respectively. The callback function type has a Legacy variant corresponding to the [LegacyTreatNonObjectAsNull] extended attribute.

const coerced = coerceToLong("-12.3"); // ← -12 as a JavaScript number

A few exported functions, for complex types, take additional arguments. Those always come first, and the value to coerce as the last argument, to make it easier to curry them. Those functions are listed in a separate table below.

const coerced = coerceToSequence(coerceToLong, ["-12.3"]);

The package also exports as @webfeet/webidl/decorators.js a set of ECMAScript decorators to coerce a setter's or auto-accessor property setter's value. The decorators follow the same naming rule as the coercion functions they wrap but without the coerceTo prefix.

class Foo {
  @long accessor bar;

  #baz;
  get baz() {
    return this.#baz;
  }
  @long set baz(value) {
    // `value` has been coerced to a `long`
    this.#baz = value;
  }
}

The coercion functions that take additional arguments have corresponding decorator factories taking those same arguments and returning a decorator.

class Foo {
  @sequence(coerceToLong) accessor bar;
}

| IDL Type | Function | Decorator | | :----------------------------------------------------------------------------------------------------------------- | :--------------------------------- | :------------------------- | | any | coerceToAny | any | | undefined | coerceToUndefined | undefined | | boolean | coerceToBoolean | boolean | | byte | coerceToByte | byte | | [Clamp] byte | coerceToClampedByte | clampedByte | | [EnforceRange] byte | coerceToEnforcedByte | enforcedByte | | octet | coerceToOctet | octet | | [Clamp] octet | coerceToClampedOctet | clampedOctet | | [EnforceRange] octet | coerceToEnforcedOctet | enforcedOctet | | short | coerceToShort | short | | [Clamp] short | coerceToClampedShort | clampedShort | | [EnforceRange] short | coerceToEnforcedShort | enforcedShort | | unsigned short | coerceToUnsignedShort | unsignedShort | | [Clamp] unsigned short | coerceToClampedUnsignedShort | clampedUnsignedShort | | [EnforceRange] unsigned short | coerceToEnforcedUnsignedShort | enforcedUnsignedShort | | long | coerceToLong | long | | [Clamp] long | coerceToClampedLong | clampedLong | | [EnforceRange] long | coerceToEnforcedLong | enforcedLong | | unsigned long | coerceToUnsignedLong | unsignedLong | | [Clamp] unsigned long | coerceToClampedUnsignedLong | clampedUnsignedLong | | [EnforceRange] unsigned long | coerceToEnforcedUnsignedLong | enforcedUnsignedLong | | long long | coerceToLongLong | longLong | | [Clamp] long long | coerceToClampedLongLong | clampedLongLong | | [EnforceRange] long long | coerceToEnforcedLongLong | enforcedLongLong | | unsigned long long | coerceToUnsignedLongLong | unsignedLonglong | | [Clamp] unsigned long long | coerceToClampedUnsignedLongLong | clampedUnsignedLongLong | | [EnforceRange] unsigned long long | coerceToEnforcedUnsignedLongLong | enforcedUnsignedLongLong | | float | coerceToFloat | float | | unrestricted float | coerceToUnrestrictedFloat | unrestrictedFloat | | double | coerceToDouble | double | | unrestricted double | coerceToUnrestrictedDouble | unrestrictedDouble | | bigint | coerceToBigInt | bigInt | | DOMString | coerceToDOMString | domString | | ByteString | coerceToByteString | byteString | | USVString | coerceToUSVString | usvString | | object | coerceToObject | object | | symbol | coerceToSymbol | symbol | | callback function | coerceToCallbackFunction | callbackFunction | | [LegacyTreatNonObjectAsNull] callback function | coerceToLegacyCallbackFunction | legacyCallbackFunction |

| IDL Type | Function | Decorator | Additional arguments | | :--------------------------------------------------------------------------- | :---------------------------- | :-------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | numeric type or bigint | coerceToBigIntOrNumericType | bigIntOrNumericType | Another coercion function to be applied to a numeric value, defaults to coerceToUnrestrictedDouble | | interface type | coerceToInterface | interfaceType | An interface type, such as HTMLElement | | enumeration type | coerceToEnumeration | enumeration | An array (or rest arguments for the decorator) of allowed string values | | sequence<T> | coerceToSequence | sequence | Another coercion function to be applied to each sequence member, defaults to coerceToAny | | record<K,V> | coerceToRecord | record | Two coercion functions to be applied to each record key and value respectively, where the key has to be a string type, default to coerceToDOMString and coerceToAny | | Promise<T> | coerceToPromise | promise | Another coercion function to be applied to the resolved value | | FrozenArray<T> | coerceToFrozenArray | frozenArray | Another coercion function to be applied to each sequence member, defaults to coerceToAny |