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

jsonml-stringify

v1.0.1

Published

Convert jsonml arrays to html strings

Downloads

49

Readme

jsonml-stringify

build status dependency status coverage report stability index

npm stats

browser support

Convert jsonml arrays to html strings

Example

var Stringify = require("jsonml-stringify/stringify")
var stringify = Stringify([
    require("jsonml-stringify/plugins/loose")
])
var assert = require("assert")

var html = stringify(["html", [
    ["head", [
        ["meta", { charset: "utf-8" }],
        ["title", "Process dashboard"],
        ["link", { rel: "stylesheet", href: "/less/main"}]
    ]],
    ["body", { class: "main" }, [
        ["script", { src: "/browserify/main" }]
    ]]
]])

assert.equal(html,
    "<html>\n" +
    "    <head>\n" +
    "        <meta charset=\"utf-8\"></meta>\n" +
    "        <title>\n" +
    "            Process dashboard\n" +
    "        </title>\n" +
    "        <link rel=\"stylesheet\" href=\"/less/main\"></link>\n" +
    "    </head>\n" +
    "    <body class=\"main\">\n" +
    "        <script src=\"/browserify/main\"></script>\n" +
    "    </body>\n" +
    "</html>")

stringify raw html entities

var Stringify = require("jsonml-stringify/stringify")
var stringify = Stringify([
    require("jsonml-stringify/plugins/loose"),
    require("jsonml-stringify/plugins/raw")
])
var assert = require("assert")

var html = stringify(["div", { raw: "foo&copy;" }])

assert.equal(html, "<div>\n    foo©\n</div>")

stringify fragments

var Stringify = require("jsonml-stringify/stringify")
var stringify = Stringify([
    require("jsonml-stringify/plugins/loose"),
    require("jsonml-stringify/plugins/fragment")
])
var assert = require("assert")

var html = stringify(["div", [
    { fragment: [
        ["div", "one"],
        ["div", "two"]
    ] },
    ["div", "three"]
]])

assert.equal(html, "<div>\n" +
    "    <div>\n" +
    "        one\n" +
    "    </div>\n" +
    "    <div>\n" +
    "        two\n" +
    "    </div>\n\n" +
    "    <div>\n" +
    "       three\n" +
    "</div>\n" +
    "</div>")

Loose JSONML definition

(* 
JsonML is both loosely and strictly defined.

A plugin is an object literal with either a single key / value
    pair or a key 'type' and some properties

Loose:
    - null
    - undefined
    - plugin
    - text content
    - [ tagName ]
    - [ tagName , properties ]
    - [ tagName , text content ]
    - [ tagName , children ]
    - [ tagName , plugin ]
    - [ tagName , properties , text content ]
    - [ tagName , properties , children ]
    - [ tagname , properties , plugin ]
    - [ '#text' , text content ]
    - [ '#text' , properties , text content ]

*)

type JsonMLPlugin := Object | Function
type JsonMLProperties := 
    Object<String, String | Boolean | JsonMLPlugin>

type LooseJsonML := 
    null |
    undefined |
    JsonMLPlugin |
    String |
    [ String ] |
    [ String , JsonMLProperties ] |
    [ String , String ] |
    [ String , Array<LooseJsonML> ] |
    [ String , JsonMLPlugin ] |
    [ "#text" , String ] |
    [ String , JsonMLProperties , String ] | 
    [ String , JsonMLProperties , Array<LooseJsonML> ] |
    [ String , JsonMLProperties , JsonMLPlugin ] |
    [ "#text" , JsonMLProperties , String ]

Plugin definition

type Plugin := {
    stringify: (JsonML, JsonMLOptions) => String,
    dom: (JsonML, JsonMLOptions) => DOMElement,
    merge: (JsonML, JsonMLMergeOptions) => void,
    type: String,
    normalize: (JsonML, JsonMLOptions) => JsonML,
    renderProperty: (DOMElement, value: Any, key: String, JsonMLOptions),
    stringifyProperty: (value: Any, key: String, JsonMLOptions) => String,
    mergeProperty: (DOMElement, value: Any, key: String, JsonMLMergeOptions),
    setProperty: (value: Any, key: String),
    getProperty: (value: Any, key: String) => String
}

Strict definition & functions

(*

Strict:
    - null
    - plugin
    - [ tagName , properties , children ]
    - [ '#text' , properties , text content ]
    - [ '#text' , properties , plugin ]

*)
type JsonMLPlugin := Object | Function
type JsonMLProperties := 
    Object<String, String | Boolean | JsonMLPlugin>

type JsonML :=
    null |
    JsonMLPlugin |
    [ String , JsonMLProperties , Array<JsonML> ] |
    [ "#text" , JsonMLProperties , String | JsonMLPlugin ]

type JsonMLOptions := {
    parent: JsonML,
    parents: Array<JsonML>,
    plugins: Array<Plugin>
}

type JsonMLMergeOptions := JsonMLOptions & {
    elements: Array<DOMElement | DOMTextNode>,
    root: DOMElement
}

stringify-recur := (JsonML, JsonMLOptions) => String

dom-recur := (JsonML, JsonMLOptions) => DOMElement

merge-recur := (JsonML, JsonMLMergeOptions)

Installation

npm install jsonml-stringify

Contributors

  • Raynos

MIT Licenced