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

l3n

v0.1.1

Published

Lagua low-level notation

Downloads

14

Readme

L3N: Flat Trees!

Construct and traverse trees with a coherent set of functions.

L3 trees can express HTML, XML, JSON or functional programs.

The Concept

Many documents can be iterated as a flat sequence of nodes, be it an XML or HTML document, a piece of JSON or even a functional program (see Raddle). The way documents are traversed is in document order, just like a SAX parser: an event is emitted for when a branch opens or closes, or when a (text) leaf is completed.

This library stores all familiar document nodes as plain JSON by using a simple convention. Traversal of documents is exposed as an Observable stream (uses RxJS 6). This ensures that there's no difference between traversing an in-memory tree or connecting to a SAX-style parser: everything is a stream.

Each node that is emitted on the stream is wrapped in a transient container that provides a reference to the parent node (see the VNode class). In addition, the VNode interface exposes more relevant properties, such as its depth relative to the root or its position relative to its parent. These enable traversal across all DOM axes. Furthermore, node names and values may be indexed to increase performance.

This library provides an immutable alternative to plain JSON (via the pnode context) and a native DOM context for the browser. The traversal context may be switched by simply binding each accessor function to another context module.

For native DOM traversal in the browser, the VNode integrates with the canonical TreeWalker API (uses ES6 WeakMap).

Note: you should not create references to VNode instances, or they can't be garbage collected. Transform them functionally instead, by using RxJS or a specialized library (see Frink).

Install / setup

npm i l3n

The easiest way to get started is with the Node.js distribution:

const l3 = require("l3n");

// Direct construction of a document-fragment, no Rx:

const frag = l3.t(
  l3.e("div",
    l3.a("class","greeting"),
    l3.e("p","Hello")
  )
)

console.log(frag.toString());

console.log(frag.toJS());
// Alternatively, you can pass a 'document implementation context' to the faux VNode directly.
// Below example will create a persistent tree
const div = l3.e("div",
  l3.a("class","greeting"),
  l3.e("p","Hello")
).node(l3.pnode);

console.log(div.toString());

console.log(div.toJS());

API documentation (WIP)

Documentation index: index

Examples (ES modules)

import { e, m, a, ensureDoc } from "l3n";

const div = e("div",
  a("class","greeting"),
  e("p","Hello")
);

const map = m(
  a("greeting","Hello")
);

HTML serialization

ensureDoc(div).subscribe(vnode => {
    console.log(vnode.toString());
});

yields

<div class="greeting"><p>Hello</p></div>

while

ensureDoc(map).subscribe(vnode => {
    console.log(vnode.toString());
});

yields

<l3-m><l3-a name="greeting">Hello</l3-a></l3-m>

JS/JSON

ensureDoc(div).subscribe(vnode => {
    console.log(vnode.toJS());
});

yields

{
  "$name":"div",
  "class":"greeting",
  "$children":[{
    "$name":"p",
    "$children":["Hello"]
  }]
}

while

ensureDoc(map).subscribe(vnode => {
    console.log(vnode.toJS());
});

yields

{
  "greeting":"Hello"
}

Serialization rules

L3N serialization rules for JSON:

| Constant | VNode Type | Appearance | | -------- | ------------------------- | ----------- | | 1 | Element | {"$name":"qname","some-attr":"some-value","$children":[]} | | 3 | teXt | "some-text" | | 4 | Reference | {"$ref":"/some/path"} | | 5 | List | [] | | 6 | Map | {} | | 7 | Processing instruction | {"$pi"":"xml-stylesheet "\"type\"=\"text/xsl\" \"href\"=\"some.xsl\""} | | 8 | Comment | {"$comment":"some-comment"}| | 12 | teXt | 123, true or null | | 10 | doctype | {"$doctype":"serialized-doctype"} | | 14 | Function call | {"$name":"some-function","$args":[]} | | 15 | Quotation (AKA lambda) | {"$args":[]}


L3N serialization rules for XML:

| Constant | VNode Type | Appearance | | -------- | ------------------------- | ----------- | | 1 | Element | <some-element some-attr="some-value"></some-element> | | 3 | teXt | some-text | | 4 | Reference | <include xmlns="http://www.w3.org/2001/XInclude" href="/some/path" parse="xml"/> | | 5 | List | <l3:l xmlns:l3="http://l3n.org"></l3:l> | | 6 | Map | <l3:m xmlns:l3="http://l3n.org"><l3:a name="my-xml-tuple"><some-element /></l3:a></l3:m> | | 7 | Processing instruction | <?xml-stylesheet type="text/xsl" href="some.xsl" ?> | | 8 | Comment | <!-- some-comment -->| | 10 | doctype | | | 12 | teXt | <l3:x xmlns:l3="http://l3n.org">123</l3:x> | | 14 | Function call | <l3:f xmlns:l3="http://l3n.org" name="some-function"></l3:f> | | 15 | Quotation | <l3:q xmlns:l3="http://l3n.org"></l3:q>


L3N serialization rules for HTML:

| Constant | VNode Type | Appearance | | -------- | ------------------------- | ----------- | | 1 | Element | <some-element some-attr="some-value"></some-element> | | 2 | Key-value pair | v | 3 | teXt | some-text | | 4 | Reference | <link rel="import" href="/some/path"> | | 5 | List | <l3-l></l3-l> | | 6 | Map | <l3-m><l3-a name="key">value</l3-a></l3-m> | | 7 | Processing instruction | N/A | | 8 | Comment | <!-- some-comment -->| | 10 | doctype | | | 12 | teXt | <l3-x>123</l3-x> | | 14 | Function call | <l3-f name="some-function"></l3-f> | | 15 | Quotation | <l3-q></l3-q>