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

lml

v0.8.1

Published

Light Meta Language. A simple-yet-powerful HTML syntax alternative

Downloads

15

Readme

LML

Light Meta Language - an HTML alternative

Concept

  • Indentation-based hierarchy - obvious hierarchy
  • Enforced one-statement-per-line with reasonable multiline attributes option
  • No <, > character, and no closing tag
  • Simple directives for text (;), comment (#), cdata ($)
  • No templating trickery - as static as HTML
  • Maintained attribute string compatibility with HTML
    • It works well with stuff like Angular event handler attributes (e.g. (click)="x = 'nah'") unlike Pug/Jade

Example

!DOCTYPE html
html
  head
    title ; My Title
    script type="text/javascript" src="ext.js"
    script type="text/javascript"
      alert('Hello');
    style
      body { color: #333; }
  body
    # A comment
    div id="wrapper"
      ; My Site!

Translates to

<!DOCTYPE html>
<html>
  <head>
    <title>
      My Title
    </title>
    <script type="text/javascript" src="ext.js"></script>
    <script type="text/javascript">
      alert('Hello');
    </script>
    <style>
      body { color: #333; }
    </style>
  </head>
  <body>
    <!-- A comment -->
    <div id="wrapper">
      My Site!
    </div>
  </body>
</html>

Programmatical use

Install for your project

npm install lml --save

Parsers produce AST and convert

JavaScript example

// convert LML to HTML
const parseLML = require('lml').parseLML;

parseLML(lmlString).toHTML();

Parsers

Parser functions are exposed with the same signiture, and the returned object has the same interface: parseAST(source: string | ASTModel[], parseConfig?: ParseConfig) => ParserInterface parseJSON(source: string | JSONModel[], parseConfig?: ParseConfig) => ParserInterface parseLML(source: string, parseConfig?: ParseConfig) => ParserInterface

Parsing HTML
  1. install html-lml: npm install html-lml --save
  2. use the the indentical parser from that package: parseHTML(source: string, parseConfig?: ParseConfig) => ParserInterface

Parser interface:

interface ParserInterface {
  errors: ParseError[];
  toAST(config?: OutputConfig): ASTModel[];
  toHTML(config?: OutputConfig): string;
  toJSON(config?: OutputConfig): JSONModel[];
  toLML(config?: OutputConfig): string;
}

Configurations

interface ParseConfig {
  indentation?: string; // for parsing LML, if autodetection is not adequate
  url?: string; // path to source file
}

interface OutputConfig {
  indentation?: string;
  lineWrap?: number;
  minify?: boolean;
  orderAttributes?: 'ascii' | 'natural' | 'angular'; // angular order means: <tag *ngXxx="x" any="x" [other]="x" prop="x" [(banana)]="box" (event)="e()" (handler)="e()" >
}

AST Model

AST model is used by a variety of DOM parsers, like https://astexplorer.net/

interface ASTModel {
  type: 'cdata' | 'comment' | 'directive' | 'script' | 'style' | 'tag' | 'text';
  name?: string; // element (e.g. tag) name
  data?: string; // value of comment, directive, and text
  attribs?: {[name: string]: string};
  children?: ASTModel[];
  startIndex?: number;
  endIndex?: number;
}

JSON Model

The native structure used by these libraries

interface JSONModel {
  type: 'cdata' | 'comment' | 'directive' | 'element' | 'text';
  name?: string; // element name
  data?: string; // value of comment, directive, and text
  attributes?: {name: string; value?: string}[];
  children?: JSONModel[];
}

CLI

There is a dedicated command line tool: lml-cli