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

@domchristie/composite

v0.5.0

Published

A hybrid client-side/server-side approach to generating dynamic HTML.

Downloads

105

Readme

🦷 Composite

A tiny web template system for the browser.

Compose your HTML in <template> elements. Use placeholders (${…}) to mark dynamic content. Call fill to generate a new HTML string which interpolates the template's content with the given properties.

Usage

npm install @domchristie/composite
/* rendered somewhere in the DOM */
<template id="hello">
  <h1>${greeting}, ${name}!</h1>
</template>
import { fill } from '@domchristie/composite'
const Hello = document.getElementById('hello')
fill(Hello, { greeting: 'Hello', name: 'World' }) // '<h1>Hello, World!</h1>'

API Docs

Table of Contents

fill

composite.js:8-15

Renders a template with given properties.

Parameters

  • template (HTMLTemplateElement | string) The HTML template to be rendered.
  • props Object An object containing properties to be interpolated into the template.

Returns string The rendered HTML string with properties interpolated.

html

composite.js:25-32

A tag function for template literals that escapes HTML special characters in values unless they are marked as raw.

Parameters

  • strings TemplateStringsArray An array of string literals.
  • values ...any The values to be interpolated into the template.

Returns string The final string with values safely interpolated.

escape

composite.js:41-43

Escapes special characters in a string for use in HTML. The characters escaped are: & < > " ' ` = /

Parameters

  • string string The input string to escape.

Returns string The escaped string.

unescape

composite.js:61-65

Unescapes a given HTML-encoded string.

Parameters

  • string string The HTML-encoded string to unescape.

Returns string The unescaped string.

raw

composite.js:74-76

Marks a string as raw HTML to prevent escaping of special characters.

Parameters

  • html string The HTML string to wrap.

Returns RawString The wrapped HTML string as a RawString object.

unsafe-eval

Composite uses new Function to generate HTML from templates. This approach can fail when using strict Content Security Policies (CSPs).

License

Copyright © 2024+ Dom Christie and released under the MIT license.