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

betterhtml.js

v1.0.1

Published

betterhtml is a JS library that allows developers to build html documents as JS objects and then build them to real html

Downloads

8

Readme

betterhtml

betterhtml is a JS library that allows developers to build html documents as JS objects and then build them to real html

Documentation

class Element(name, content, attributes)

Element(name, content, attributes)

Attributes

Element is a betterhtml class. It is built as an html element with opening and closing tags. It has three parameters : name / content / attributes. The name of a betterhtml Element is the name of the html element, for example : h1, p, div ... The content of a betterhtml Element is comparable to the innerHTML attribute of a html element. The content can be either a string in the case of an element that doesn't contain other elements or an array if the element itself contains other elements. The attributes of a betterhtml Element are the attributes that are going to be built with the html, for example : style, src, onclick...

Methods

render()

The render method builds the element to a normal html element, it takes no arguments.

push(element)

The push method of a betterhtml element adds a new element to the content of the element

querySelectorAll(query)

The querySelectorAll method of a betterhtml element returns all of the elements inside of the element's content that respect the query.

querySelector(query)

The querySelector method of a betterhtml element returns the first element inside of the element's content that respect the query.

class Ball(name, attributes)

Ball(name, attributes)

Attributes

Element is a betterhtml class. It is built as an html element with only opening tags. It has two parameters : name / attributes. The name of a betterhtml Ball is the name of the html element, for example : link, br, meta ... The attributes of a betterhtml Ball are the attributes that are going to be built with the html, for example : name, src, content...

Methods

render()

The render method builds the element to a normal html element, it takes no arguments.

Example

const Element = require("betterhtml").Element
const Ball = require("betterhtml").Ball

let html = new Element("html")
html.push(new Element("head"))
html.push(new Element("body"))
html.querySelector("head").push(new Element("title", "This is a test page!"))
html.querySelector("body").push(new Element("h1", "This is a test heading!"))
html.querySelector("body").push(new Element("div", [], {id: "content", class: "contentor"}))
html.querySelector("body").querySelector("#content").push(new Element("h2", "This is a smaller heading inside of a div"))
html.querySelector("body").querySelector("#content").push(new Element("p", "This is a paragraph inside of a div"))
html.querySelector("body").querySelector("#content").push(new Ball("img", {src: "https://upload.wikimedia.org/wikipedia/commons/6/6a/JavaScript-logo.png", width: "250px"}))
console.log(html.render())

Gives the result

<html >
<head >
<title >This is a test page!</title>
</head>
<body >
<h1 >This is a test heading!</h1>
<div id="content" class="contentor" >
<h2 >This is a smaller heading inside of a div</h2>
<p >This is a paragraph inside of a div</p>
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/JavaScript-logo.png" width="250px" >
</div>
</body>
</html>