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

meryt

v0.6.1

Published

Lightweight and readable client-side JS templating with event handling and useful shorthands.

Downloads

4

Readme

GitHub NPM

CodeSandbox

GitHub license made-with-javascript Maintenance Maintainer

meryt.js

Render your client-side HTML with ease using this snappy little 2.18 kB module!

Have your cake and eat it, too. Intuitively write your markup and have all the native functions you need right at your fingertips. With meryt.js, you never leave JavaScript & you never depend on computationally expensive evals. It's all pure JavaScript, free from any distracting quirks or IDE-breaking syntax parsing issues.

npm i meryt

"Buy Me A Coffee"

Usage

Import it into the 'template file' and then simply call $.MOUNT(...) on an object generated by it.

import $ from '/js/meryt.js'

// Generate a basic paragraph element displaying 'Hello World' in large red letters, and then mount it.
const template = $.p('.text-red', [ 'Hello World' ], { style: 'font-size: 72px;' })
const targetElement = document.querySelector('body')
$.MOUNT ( template, targetElement )

That's all there is to it. The library isn't fussy about the order you pass arguments in, so there's nothing to memorise there. The proxy object parses itself recursively, and it uses the property name as the element. What does this mean? $.div('Hello World') will generate <div>Hello World</div>.

Also, if you include an underscore you can insert the id at the same time, like this: $.div_introElement('Hello World'), which will generate <div id='introElement'>Hello World</div>.

That's not always useful, since your IDs may be dynamically generated in more complex pages. We'll come to that in just a moment.

If you omit the div prefix, $._introElement('Hello World') will still generate a <div id='introElement'>Hello World</div> since div is presumed to be the default. $._('Hello World') will also work, but if you are going to omit both the element and the id, be sure to pass an underscore as the property of $ or you'll receive an error about it not being a function.

Now, regarding dynamic IDs; if you pass an object as one of the arguments, the properties of that object will set the attributes of the element concerned.

$._({ id: 'introElement', style: 'font-size: 72px;' }, 'Hello World')

Event Handlers

Since the elements don't exist until it's rendered to the DOM, the workarounds for binding events to those elements are already in place for you. If you pass an object (or array of objects) as the value for the events key in same object you use to set attributes, event listeners are mapped to those elements upon mounting.

⚠️ DON'T MINDLESSLY USE ARROW FUNCTIONS. YOU WILL LOSE THE BENEFIT OF 'THIS' KEYWORD.

import $ from '/js/meryt.js'

// Generate the original example element, but also pop-up a window alert containing the text value.
const template = $.p('.text-red', [ 'Hello World' ], {
    style: 'font-size: 72px;',
    events: {
        on: 'click',
        do: function() {
            alert(this.innerText)
        }
    }
})
const targetElement = document.querySelector('body')
$.MOUNT ( template, targetElement )

You might have noticed the Pug-like class list there. That's pretty much all there is to say about it. Just remember there is no real importance to the order you pass the arguments in, if your string matches the class syntax then it'll be parsed that way, otherwise it'll just be the innerText / innerHTML.

If you pass strings / template objects into an array, however, they will always become the contents of the element. So don't worry, in the unlikely event that you want to display an element showing nothing but a Pug class sample, you can still do that, just wrap it within a single-item array.

Iterators and Looping

It's just JavaScript.

import $ from '/js/meryt.js'

const food = ['halloumi', 'lasagne', 'lahmacun']

// Generate the original example element, but also pop-up a window alert containing the text value.
const template = $._('.container', [
    $.h1('Here are some of the world\'s tastiest foods. Fight me.')
    ...food.map(item => $.p('.text-red', [ 'Hello World' ]))
])
const targetElement = document.querySelector('body')
$.MOUNT ( template, targetElement )