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

attrs-in-props

v3.14.105

Published

Utilize props as attributes

Readme

attrs-in-props

HTML attributes as props for DOMQL elements. Provides attribute validation, filtering, and automatic resolution for HTML elements.

What it does

  • Validates HTML attributes by tag name (knows which attributes are valid for <img>, <a>, <input>, etc.)
  • Filters props to extract valid HTML attributes and DOM events
  • Provides attribute transform plugins for common patterns (src, href resolution)
  • Supports all standard HTML attributes, ARIA attributes, SVG attributes, and DOM events

API

checkAttributeByTagName(tag, attribute)

Check if an attribute is valid for a specific HTML tag.

import { checkAttributeByTagName } from 'attrs-in-props'

checkAttributeByTagName('img', 'src')     // true
checkAttributeByTagName('img', 'href')    // false
checkAttributeByTagName('div', 'id')      // true (default attribute)

filterAttributesByTagName(tag, props, cssProps?)

Filter component props to extract only valid HTML attributes and DOM events.

import { filterAttributesByTagName } from 'attrs-in-props'

filterAttributesByTagName('img', {
  src: '/photo.jpg',
  alt: 'Photo',
  theme: 'primary',     // filtered out (not an HTML attr)
  padding: '10px'       // filtered out (CSS prop)
})
// -> { src: '/photo.jpg', alt: 'Photo' }

resolvePropValue(el, value)

Resolves a prop value: executes dynamic values and replaces {{template}} literals.

import { resolvePropValue } from 'attrs-in-props'

// In an attr handler:
const src = resolvePropValue(el, el.src)

ATTR_TRANSFORMS

Auto-resolve map for common attributes. Handles exec + template literal replacement for: src, href, action, poster, data.

import { ATTR_TRANSFORMS, applyAttrTransforms } from 'attrs-in-props'

// Apply all valid transforms for an element's tag
const attrs = applyAttrTransforms(element)

Components using standard src/href patterns no longer need custom attr blocks — ATTR_TRANSFORMS handles resolution automatically.

executeAttr(elem, element)

Execute all handler functions in an element's attr block.

import { executeAttr } from 'attrs-in-props'

const resolved = executeAttr(componentDef, element)
// -> { src: '/resolved-path.jpg', alt: 'Photo' }

ARIA Attributes

All aria-* attributes are valid on any element. Three syntax forms are supported:

// 1. Kebab-case (standard HTML)
{ 'aria-label': 'Close', 'aria-expanded': true }

// 2. camelCase (JS-friendly) — auto-converted to kebab-case
{ ariaLabel: 'Close', ariaExpanded: true }

// 3. Object shorthand
{ aria: { label: 'Close', expanded: true, hidden: false } }

All three produce aria-label="Close", aria-expanded="true" in the DOM.

Data Attributes

All data-* attributes are valid on any element, with the same three syntax forms:

{ 'data-testid': 'btn' }         // kebab-case
{ dataTestId: 'btn' }            // camelCase → data-test-id
{ data: { testId: 'btn' } }     // object shorthand → data-test-id

Conditional Attributes

Attributes inside $, ., ! prefix blocks are conditionally applied — same prefixes as css-in-props:

const Button = {
  // $ prefix: global case from context.cases
  '$isSafari': { disabled: true, 'aria-label': 'Safari' },

  // . prefix: truthy (element/state first, then context.cases)
  '.isActive': { aria: { expanded: true }, 'data-state': 'open' },

  // ! prefix: falsy
  '!isActive': { ariaHidden: true }
}

Conditional attribute values are wrapped in functions and re-evaluated on every update() call.

extractConditionalAttrs(props, tag, cssProps?)

Extract HTML attributes from conditional blocks in props.

import { extractConditionalAttrs } from 'attrs-in-props'

const conditionalAttrs = extractConditionalAttrs(props, 'button', cssPropsRegistry)
// Returns attr functions that evaluate conditions on each call

Default attributes

All HTML elements support these attributes by default: id, title, class, style, dir, lang, hidden, tabindex, draggable, contenteditable, spellcheck, translate, role, slot, and more.

All aria-* and data-* attributes are valid on any element. Element-specific attributes are supported for 50+ HTML tags including a, img, input, video, iframe, form, select, textarea, and svg.