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

als-layout

v7.2.0

Published

HTML layout constructor with dynamic meta, styles, and scripts

Readme

als-layout

als-layout is a small, dependency‑light library for building and manipulating an HTML document in memory — title, meta tags, Open Graph / Twitter cards, styles, scripts, links, favicon and viewport — with a fluent, chainable API. It works the same in Node (SSR / static generation) and in the browser.

It is built on top of als-document and is a pure document builder: it has no global state and no site‑level concerns (collections, sitemaps, robots). For multi‑page sites built on top of it, see als-site.


Installation

npm i als-layout

ESM (named export)

import { Layout } from 'als-layout'

Node (CommonJS)

const Layout = require('als-layout')

Browser bundle (global Layout, als-document inlined)

<script src="layout.js"></script>
<script>const layout = new Layout()</script>

Quick start

import { Layout } from 'als-layout'

const layout = new Layout(undefined, 'https://example.com')
   .lang('en')
   .noindex()                                    // adds <meta name="robots" content="noindex">
   .viewport()                                   // width=device-width, initial-scale=1.0
   .title('Home')                                // <title> + og:title
   .description('A cool site')                   // description + og/twitter description
   .keywords(['stats', 'sheets'])
   .favicon('/favicon.png')
   .image('/cover.png')                          // og:image, twitter:image, twitter:card
   .link('/styles.css')                          // <link rel=stylesheet> (deduped)
   .style('body{margin:0}')                      // appends to <style>
   .script({ src: '/app.js' })                   // <script> in <head>
   .script({}, 'console.log("hi")', false)       // inline <script> in <body>
   .url('/')                                      // canonical + og:url, resolved vs host

layout.body.innerHTML = '<h1>Home</h1>'
console.log(layout.rawHtml)                       // full HTML string

A Layout is an offline DOM

This is the core idea: a Layout extends an als-document document, so the instance is a real, in‑memory DOM tree you can query and mutate almost exactly like the browser DOM — no jsdom, no browser, works in plain Node. The chainable title()/meta()/link()/… helpers are just convenience on top of it; for anything else you manipulate nodes directly.

const layout = new Layout(/*html*/`<html><head></head><body><main></main></body></html>`)

// Query like the DOM ($ / $$ are aliases for querySelector / querySelectorAll)
const main = layout.$('main')              // === layout.querySelector('main')
const items = layout.$$('.item')           // === querySelectorAll, returns an array

// Build and insert nodes
main.innerHTML = '<h1>Hello</h1>'
main.insert(2, '<p class="lead">Intro</p>')          // append parsed HTML
main.insertAdjacentHTML('beforeend', '<hr>')

// Mutate elements with the familiar API
const h1 = layout.$('h1')
h1.setAttribute('id', 'top')
h1.classList.add('title')
h1.dataset.role = 'heading'
h1.textContent = 'Welcome'
console.log(h1.outerHTML)                   // <h1 id="top" class="title" data-role="heading">Welcome</h1>

// Traverse
h1.parent          // parent node
h1.nextElementSibling
layout.body.children

// Remove
layout.$('hr').remove()

Supported on nodes: querySelector/$, querySelectorAll/$$, getElementById, getAttribute/setAttribute/removeAttribute, classList, dataset, style, innerHTML/outerHTML/textContent, append/insert/insertAdjacentHTML/remove, plus traversal (parent, children, prev/next, …). See als-document for the full node API.

On the client, toDocument() flushes this offline DOM into the live document.


Cloning

layout.clone returns a deep, independent copy — ideal as a template for many pages. Changes to a clone never affect the original.

const base = new Layout(template, 'https://example.com').link('/styles.css')
const about = base.clone.title('About').url('/about')

API

Constructor

new Layout(html?: string, host?: string)
  • html — optional HTML string to start from.
  • host — base URL used to resolve relative URLs in url().

Properties

  • rawHtml — current document as an HTML string.
  • clone — a deep, independent copy.
  • urlObj — the parsed URL of the last url() call (set after url()).
  • head / body / html — element accessors (from als-document).

Methods (all chainable, return this)

  • lang(lang) — sets <html lang>.
  • title(title) — sets <title> and og:title.
  • description(text) — sets description, og:description, twitter:description.
  • keywords(list) — sets/merges meta[name=keywords].
  • meta(props) — sets/updates a <meta> tag (keyed by its first attribute).
  • image(src) — sets og:image, twitter:image, twitter:card.
  • favicon(href) — sets/updates the favicon link.
  • viewport(content?) — sets the viewport meta.
  • link(href, attributes?) — adds a stylesheet <link> (skipped if already present).
  • style(css) — appends CSS to a <style> element.
  • script(attrs?, innerHTML?, head = true) — adds a <script> (head or body; src deduped).
  • url(url, host = this.URL) — sets canonical + og:url, stores urlObj.
  • toDocument() — in the browser, renders this layout into the live document (no‑op in Node); returns this.

Changelog

7.2.0 - als-document 1.5 (from 1.4.3)

  • Updated the als-document dependency from ^1.4.3 to ^1.5.0.
  • Improved HTML parsing for attributes, <meta>, <link>, <style>, and <script> elements.
  • Fixed document title/HTML initialization, cloning, inline styles, and CSS selector handling.
  • Fully backward compatible; no als-layout code changes are required, and all 50 tests pass.

7.1.0

  • Added toDocument() — render a layout into the live DOM on the client.
  • Added urlObjurl() now exposes the parsed URL.
  • Added exports map — ESM resolves to the named Layout export, CommonJS to the class.
  • Fixed twitter:description now uses name= (was property=), per the Twitter Cards spec.
  • Fixed clone preserves the document URL/host.
  • Changed url() keeps the canonical trailing slash (URL.href), and stores urlObj.

7.0.0 (breaking)

  • Merged into a single source file; added ESM build (index.mjs) and browser bundle (layout.js).
  • Removed status, end, minified, propsToClone, and JS/CSS uglification.

Notes

  • Pure document builder — no global state, no file I/O.
  • index.mjs and the browser layout.js are generated from src/layout.js by node build.js.
  • Use clone to derive page variants from a base template.