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

uralsjs-templator

v0.1.1

Published

uralsjs html templator dsl

Downloads

6

Readme

js-uralsjs-templator

uralsjs html templator dsl

Description

Extendable html-templator dsl with full typescript support. May be used for building models of html-trees, easy-comparable, and easy-to-difference-calculatable. May be extended by custom tags.

Example

import * as htmlDsl from "uralsjs-templator"
import * as assert from "assert"

const given = htmlDsl.typecheck(['html', {},
    ['div', {
        'class': 'w-100',
        'style': 'height: 50px;'
        },
        ['input', {
            name: 'test-input',
            val: 'test-val'
            }, 
            ['textarea'] //input is single tag, children "textarea" will be ignored
        ],
        ['button', {
            'class': 'btn btn-success'
        }, "Submit"],
        ['input'],
    ] 
], htmlDsl.html.config)
const result = htmlDsl.tag.render(given, htmlDsl.html.config)
const nominal = '<html>' 
    + '\n  <div class="w-100" style="height: 50px;">' 
    + '\n    <input name="test-input" val="test-val">' 
    + '\n    <button class="btn btn-success">' 
    + '\n      Submit</button>' 
    + '\n    <input></div></html>';
assert.strictEqual(result, nominal)

Extending

For understanding package extension possibilities you should understand concept of config:

export type T<Tag extends string> = Record< //config type
    Tag, //Known tags for templator: for example 'div' | 'form' | etc..
    (
        params: Record<string, string|number>, 
        content: string
    ) => string //Known functions for print html by this tags
>

config uses as list of instructions for rendering html by dsl-phrase calls tag:

export type T<Tag extends string> = [ //tag type
        Tag, 
        Record<string, string|number>?, 
        ...T<Tag>[]
    ] | string

default renderer for html tags contains in inner ./html file

Use tags and configs you may compose typechecked phrases and render them into html

//Declaration of inner package's index file:

//Uses for rendering tags composition into html.
export const render = <Tag extends string>(
    t: T<Tag>, //tags composition
    conf: config.T<Tag>,
    deep: number = 0
): string => {...}

//Uses for compiler's typechecking tags composition. Doesn't make sense in runtime.
export const typecheck = <Tag extends string>(
    t: T<Tag>, //tags composition
    conf: config.T<Tag>,
): T<Tag> => t

You may declare your own renderer for your own tags, applies renderer type, and spread it with default renderer or as only one renderer in your project. Default renderer builded by spreading single-tag and double-tag renderers:

//content of "./html/index" file:
import * as singleTag from "./single-tag"
import * as doubleTag from "./double-tag"
import * as c from "../config"

export const config: c.T<
    (typeof singleTag.literals[number])|(typeof doubleTag.literals[number])
> = {
    ...singleTag.config, 
    ...doubleTag.config
}
//For details or default renderers realization look "./dsl/single-tag.ts"
//and "./dsl/double-tag.ts" files

License

MIT

Contacts

Anatoly Starodubtsev [email protected]