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 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-jsx

v1.0.0

Published

Extensible jsx type definitions for standard html interfaces.

Downloads

210

Readme


Install

$ npm i html-jsx

Usage

Because of the way TypeScript and JSX work, we have to insert this piece of code where the createElement (or h) factory lives in order for the types to be picked up correctly by the compiler:

import type * as jsx from 'html-jsx'

// this declaration allows us to augment JSX interfaces
declare module 'html-jsx' {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  interface DOMAttributes<T> extends JSX.IntrinsicAttributes {
    // here we could add attributes specific only to DOM elements (HTML+SVG)
  }
}

// this introduces our JSX definitions into the global scope
declare global {
  namespace JSX {
    /** The type returned by our `createElement` factory. */
    type Element = string

    interface IntrinsicElements extends jsx.IntrinsicElements {
      /** This allows for any tag to be used. */
      [k: string]: unknown
    }

    // here we can add attributes for all the elements
    interface IntrinsicAttributes {
      /** List index key - each item's `key` must be unique. */
      key?: string | number
    }

    /**
     * These are exported to the global JSX namespace to allow
     * declaring custom elements types.
     * @see `playground/app.tsx`
     */
    interface HTMLAttributes<T> extends jsx.HTMLAttributes<T> {}
    interface SVGAttributes<T> extends jsx.SVGAttributes<T> {}
    interface DOMAttributes<T> extends jsx.DOMAttributes<T> {}
  }
}

After this, html JSX tags in our application(or library) plus anything else that depends on it, should be properly picking up the types, with intellisense, documentation and lint working.

See playground for more usage details.

Extras

An eslint configuration based on eslint-plugin-react that only enables JSX rules that would possibly cause problems is available here. No stylistic rules are applied (use Prettier for this). It also sets up the JSX pragma to h and the fragment to Fragment which is probably what you need. All these can be configured again, or you can use the react plugin directly. This is only for convenience for my own projects basically but distributing it to save someone's time potentially.

To use it, just install it and add to your eslint config:

$ npm i eslint-config-html-jsx

eslintrc.js:

...
  extends: ['html-jsx'],
...

Credits

  • markuplint for the html-spec data which are used to generate most of the HTML types and documentation.

  • ko-jsx which this was based on, which was itself based on Surplus and Inferno which were themselves based off React's.

  • CSSType for the rules that are used in the style attributes.

  • Of course, Mozilla MDN which all of the previous are based on.

  • Many thanks to everyone who contributed.

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2021 stagas