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

@tinyweb/core

v2.0.5

Published

A tiny library simplifies building web components using decorators

Downloads

3

Readme

ƚιɳყ

A tiny library (~20kb minified) simplifies building web components using a base class and small set of decorators.

Installation

npm i @tinyweb/core --save

Example

A simple todo app.

import { TinyElement, element, query, handle, input } from 'tiny.element.js';

@element(
  'todo-app',
  `<div class="container">
  <form>
    <input name="todo" placeholder="New Todo" />
    <button type="submit">Add</button>
  </form>
  <div class="list">
  </div>
</div>`
)
class TodoApp extends TinyElement {
  @query('.list')
  todosContainer;

  @query('input')
  input;

  @handle('submit', 'form')
  onSubmit(evt) {
    evt.preventDefault();
    if (!this.input.value) {
      return;
    }

    const todo = this.create('todo-item', {
      props: {
        item: this.input.value
      }
    });

    this.addChildren([todo], this.todosContainer);
    this.input.value = '';
  }
}

@element(
  'todo-item',
  `<div>
  <span class="text"></span>
  <button type="button" style="font-size:10px" class="delete">❌</button>
</div>`
)
class Todo extends TinyElement {
  @input(true)
  item;

  @query('.text')
  spanEl;

  @query('.delete')
  deleteEl;

  onChanges(changes) {
    if (changes.has('item')) {
      this.updateHtml(this.item, this.spanEl);
    }
  }

  @handle('click', '.delete')
  onDelete(evt) {
    evt.preventDefault();
    this.remove();
  }
}

document.addEventListener('DOMContentLoaded', () => {
  const board = document.createElement('todo-app');
  document.body.appendChild(board);
});

API

TinyElement (Base Class)

Contains methods to perform DOM operations.

create(name, options) - Create new element and returns it. $(selector, el = this) - Queries and returns the element that matches the passed CSS selector. $$(selector, el = this) - Queries and returns the elements that matches the passed CSS selector. addClass(classes, el = this) - Adds single or multiple classes. removeClass(classes, el = this) - Removes single or multiple classes. clearClasses(el = this) - Clear all classes. toggleClass(sourceCls, targetCls, el = this) - Toggles source css classes with the target. getAttr(name, el = this) - Returns the attribute value of the element. setAttr(obj, el = this) - Sets attributes for element from the passed object. removeAttr(attrs, el = this) - Removes the passed attributes from the element. getData(name, el = this) - Returns the value of the data attribute. setData(obj, el = this) - Sets object of data attributes. getStyle(name, el = this) - Returns the passed style's value. addStyle(styles, el = this) - Add passed styles. clearStyles(el = this) - Clears the passed styles. removeStyles(styles, el = this) - Removes the passed style(s). getChild(index, parent = this) - Returns the child from the passed index. addChildren(children, parent = this) - Inserts the passed elements as children. removeChildren(el = this) - Removes all the children. updateHtml(html, el = this) - Updates html of the element. show(el = this) - Shows the element. hide(el = this) - Hides the element. on(eventName, handler, el = this) - Subscribes to the event. off(eventName, handler, el = this) - Un-subscribes from the event. onConnected() - Invoked after the element is connected to DOM (life-cycle hook). onDisconnected() - Invoked after the element is dis-connected to DOM (life-cycle hook). onChanges(changes) - Called initially and whenever there is a change in inputs (life-cycle hook).

element(name, tpl, shadow = false) decorator

Decorator that helps to register a class as custom web element.

input(attribute = false, dataType = 'string') decorator

Decorator that marks the applied property as an input.

query(selector) decorator

Decorator that helps to query and return DOM element(s) on accessing the applied property.

queryAll(selector) decorator

Decorator that helps to query and return DOM element(s) on accessing the applied property.

handle(eventName, element = 'self', all = false) decorator

Decorator that helps to bind a DOM event with a function.

License

MIT

Contact

vijay#dot#prideparrot#at#gmail.com