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

@smotaal/pseudom

v0.0.10

Published

Featherweight compositional DOM for document/less runtimes

Downloads

7

Readme

@smotaal/pseu·dom

Featherweight compositional DOM for document/less runtimes.

Why?

Document composition using the standard DOM can be boggled down by unrelated operations and behaviors, which essentially boil down to being able to create and nest Element and Text nodes to generate HTML output.

How?

  • Provide purely compositional APIs independent from the DOM.
    1. Reduced overhead by reusing elements (being explored).
    2. Fast HTML rendering (work in progress).
  • Provide interoperability APIs for operating directly on the DOM.
    1. Reduced overhead by reusing elements (being explored).
    2. Fast HTML rendering (being explored).

Important Note: This package is designed for ECMAScript module supporting runtimes, including all major browsers and Node.js 12 or later.

See Changelog.

Intended Uses

native mode

One use case is when you prefer using the abstract APIs directly on the native DOM. The pseudom.native.… APIs provide the mirrored abstractions, however, it does not automatically clone elements at this time but is planned future releases after addressing the various edge cases.

import {native} from '@smotaal/pseudom';

console.log(native.createElement('div', null, native.createText('Real DIV')));

Manually Creating native API instances

You can also manually create a private instance of the native APIs where you only pass in either a global object or just the specific set of constructors as the endowments argument, which may be used to provide specific document instance and constructors for Object, DocumentFragment, Element, Node, Text.

import {createNativeDOM} from '@smotaal/pseudom/native.js';

const endowments = {Object, document, DocumentFragment, Element, Node, Text};
const native = createNativeDOM(endowments);

console.log(native.createElement('div', null, native.createText('Fake DIV')));

Note: While the API can function without including the specific node constructors, they are always useful to include specifically for type checking when working with multiple APIs instances across frames.


pseudo mode

The more ideal use case is when you want to compose HTML fragments and repeatedly rely on one or more recurring elements. The standard DOM approach would require normally making deep clones of those elements. The pseudom.pseudo.… APIs provide the most basic abstractions to a compose fake elements to generate the HTML output.

import {pseudo} from '@smotaal/pseudom';

console.log(pseudo.createElement('div', null, pseudo.createText('Fake DIV')));

Manually Creating pseudo API instances

You can also manually create a private instance of the pseudo APIs where you only pass in either a global object or just the specific set of constructors as the endowments argument, which may be used to provide specific constructors for Object, Set, String and Symbol.

import {createPseudoDOM} from '@smotaal/pseudom/pseudo.js';

const endowments = {Object, Set, String, Symbol};
const pseudo = createPseudoDOM(endowments);

console.log(pseudo.createElement('div', null, pseudo.createText('Fake DIV')));

Note: While the API can function without including the specific primordial constructors, they are always useful to include specifically for type checking when working with multiple contexts or realms.


default mode

Another ideal use case is when the DOM may not be available, more so if the application needs transparently adapt to its presence or abscense while composing fragments. This pseudom.… automatically expose the right API based on the precense or absence of a valid document in on the global object.

import * as pseudom from '@smotaal/pseudom';

console.log(
  pseudom.createElement(
    'div',
    {className: 'awesome'},
    pseudom.createElement('span', null, pseudom.createText('Awesome')),
    pseudom.createElement('span', null, pseudom.createText('Text')),
  ),
);

Note: If you want to use the default API in multiple contexts or realms, you must directly import from @smotaal/pseudom which will create a new instance of the namespace with the correct bindings.


If you find pseu·dom suitable for your particular case, please don't hesitate to contribute to this project. If not, please let me know why.