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

hyperjsx

v1.0.12

Published

A "template" language for static hypertext documents (HTML) using JSX

Downloads

6

Readme

A lean "template" engine for producing static hypertext documents (HTML) using JSX.

Supports structured class and style creation, context, form improvements, error handling, stable ID generation, and pretty printed results.

Zero dependencies, minimal source (less than 3KB minified and gzipped), and no reliance on a specific JavaScript version. Use it in any version of node, or any browser.

Getting started

  1. Install this module

    npm install hyperjsx
  2. Configure your JSX environment to use the hyperjsx transforms. For example, for TypeScript, include these two lines in your tsconfig.json

    "jsx": "react-jsx",
    "jsxImportSource": "hyperjsx",

API

render(root: JSX.Element, options?: Options): string

Given a JSX element, render an HTML string.

Options:

  • indent - A string to use as the indentation or false to disable pretty printed results (default " ").
  • xml - Set to true to use XML serialization rules instead of HTML rules (default false).

stream(root: JSX.Element, options?: Options): NodeJS.ReadableStream

Given a JSX element, stream an HTML string.

Because this depends on a Node.js module, import this function from hyperjsx/stream.

createContext<T>(defaultValue: T): ContextComponent<T>

Creates a context component for use by useContext(). Context provides values which can be retrieved by any component within.

const ExampleContext = createContext('default value')

function useContext<T>(context: ContextComponent<T>): T

Get the current value of a context.


function TestUseContext() {
  const example = useContext(ExampleContext)
  return <div>{example}</div>
}

// '<div>test</div>'
render(
  <ExampleContext value="test">
    <TestUseContext />
  </ExampleContext>
)

useId(): string

Returns an opaque unique identifier stable to changes elsewhere. Useful if you need a "random" identifier

This value is stable, so multiple calls to useId() from the same component will return the same result. To get multiple unique values, append some identifer to the end.

function CustomForm() {
  const id = useId()
  return <>
    <input name={id+'-first'} />
    <input name={id+'-last'} />
  </>
}

The id value returned will use only alpha characters.

ErrorBoundary

A component which can catch an error thrown below it and replace the content with a fallback.

Props:

  • fallback - any content or a Component (which may accept an error prop)
  • onError - a function which is provided error (useful for logging)

Note: When streaming, a stream will wait until all content below an ErrorBoundary has completed before sending any bytes. As a result, placing an ErrorBoundary at the top level removes the ability to stream results entirely.

Et cetera

Hyperjsx also exports jsx (modern JSX transform), h (classic JSX transform, or manual hyperscript) and Fragment functions which can be used directly if necessary in leiu of or in additional to use of JSX directly.

Pretty printing

Hyperjsx pretty prints results. However it favors speed of rendering over idealized pretty results. More specifically, it has minimal lookaheads, so decisions about where to place line breaks need to be made before later content has been rendered. As a result some lines may be longer or shorter than you might expect from other pretty printing tools.