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

luri

v2.8.0

Published

A little javascript UI building library made for fun and science.

Downloads

28

Readme

luri

A simple JavaScript library for creating HTML UI, inspired by ReactJS and created for fun, and science, of course.

Build Coverage Version Dependencies


Quick links

  1. Ideology
  2. Concepts
  3. API
  4. Helpers
  5. Examples
  6. Utility
  7. Made With

Ideology

General
The idea of a UI rendering library is that a client should be responsible for rendering its own UI and the server should not be aware of the presentation logic, transmitting only essential data.

luri
The main goal behind luri is simplicity. It is designed in a way that requires as little learning as possible. If you're familiar with JavaScript and HTML it should literally take you no more than 10 minutes before you can start building. Second but equally as important is the simplicity of the source code. It is ~1.7KB minified and gzipped.

Concepts

There are a few simple concepts you need to understand before you can use luri.

  • Definitions
    A definition is a piece of information that can be used by the library to construct an HTML element. The most common data type for definitions is an object which contains the HTML element's attributes as properties, however other valid definitions are strings, numbers, null, HTMLElements, Promises and Components, which are another concept, explained below. Arrays are also considered a valid definition, however they represent a list of definitions and do not provide information for a single HTML element, so use with caution.

  • Components
    A component is a class that inherits from luri.Component. Every component must implement a props() method, which must return a definition that will tell luri how to construct that particular component. Once constructed, there is a bond created between the Component and the HTMLElement. Components are useful for code separation. They can also listen globally to emitted events and react to each accordingly.

  • Events
    An event in the context of the library is nothing different than a regular event, except it gets broadcasted globally (unless explicitly declared otherwise) in the document to the mounted components.

API

  • luri.construct: constructs an HTMLElement or Text node from the provided input definition.
    luri.construct(definition: definition): HTMLElement | Text
  • luri.emit: emits an event to all currently attached to the document Components
    luri.emit (event: string, ...data: any[]): data: any[]
  • luri.dispatchToClass: emits an event to all currently attached to the document Components matching className
    luri.dispatchToClass(className: string, event: string, ...data: any[]): data: any[]
  • luri.dispatchTo: emits an event to a collection of HTMLElement nodes that reference Components
    luri.dispatchTo(collection: HTMLCollection | NodeList, event: string, ...data: any[]): data: any[]
  • luri.promise: allows for a custom placeholder element until promise is resolved
    luri.promise(def: definition, promise: Promise): def: definition

Helpers

There are helper functions for every standard HTML tag that modify a definition, by adding the node property automatically. Helper functions can be accessed via luri.<ANY_HTML_TAG_IN_UPPERCASE>(<Definition>).

Examples

In the examples below #text means the output is a Text node and html markup represents HTMLElement instances, output is never a string.

  • Simplest usage - live

    luri.construct("Hi");

    #text "Hi"

  • Creating an element - live

    luri.construct({
     node: "span"
    });

    <span></span>

  • With attributes and content - live

    luri.construct({
      node: "h1",
      class: "title",
      html: "Hello"
    });

    <h1 class="title">Hello</h1>

  • Nesting - live

    luri.construct({
      node: "p",
      html: {
        node: "img",
        src: "..."
      }
    })

    <p><img src="..."></p>

  • With multiple children - live

    luri.construct({
      node: "p",
      html: [
        "Hey",
        {
          node: "img",
          src: "..."
        }
      ]
    })

    <p>Hey<img src="..."></p>

  • Event listeners - live

    luri.construct({
      node: "button",
      onclick() { 
        alert("Hello") 
      }
    })

    <button></button>

    Event listeners are assigned to the on* properties of HTMLElement instances so are not visible in the markup.

  • Promises - live

    luri.construct([
      "The time is: ",
      fetch("https://worldtimeapi.org/api/timezone/Europe/London")
        .then(response => response.json())
        .then(time => ({
          node: "strong",
          html: time.datetime
        })).catch(() => "Error fetching time")
    ])

    <div>The time is: <div></div></div>

    By default, luri places an empty div as a placeholder for the Promise result. As soon as the promise gets resolved, the DOM changes:

    <div>The time is: <strong>2020-09-01T08:00:00.000000+01:00</strong></div>

    You can use luri.promise if you need a custom placeholder.

  • Components

    A slightly more complex example using a component can be found here.

You can browse ./examples for more demos but beware. They were added a long time ago, eventually they will get updated if there is interest in the library, but the working principle is the same.

You can check out the spa-quickstart repository that will get you started with building a single page web app in no time.

Utility

You will find a transpiler in ./utils/transpiler/index.html that you can use to convert an HTML string into a definition. You can also access it here, thanks to github pages.

Made With

Projects made using luri.