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

ebla

v1.2.0

Published

Manpulate browser DOM

Downloads

5

Readme

ebla

Ebla

Install

npm install ebla

Imports

import { E, generate, spawn } from 'ebla';
E('<p>Hello world!</p>').appendTo(document.body);

Terminology

el stands for the instance created from E() like let el = E();.

value as a parameter stands for whatever E(value) accepts as a value.

...values as a parameter stands for an list of values that are each accepted by E(value).

The Constructor

Use E(value) to capture, or manpulate the DOM using an Ebla instance.

See dom-elementals to find what values the E() constructor takes. E(value, ...values) takes the same input as toElement from dom-elementals.

Methods, and properties not documented here

See dom-properties-mixin to see what properties are on an instance of E(value).

See dom-events-mixin to see about event methods on E.prototype.

Static Properties/Methods

E.fragment()

E.fragment is equivalent to document.createDocumentFragment().

E.plugin(create)

Add to the prototype of Ebla.

E.plugin(proto=>{
    proto.log = function(){
        console.log(this.element);
    };
    //Optionally return an object.
    //init will be run on instantiation.
    return {
        init(){
            console.log(`'E()' is being constructed`);
        }
    }
});

E('#selected').log();

Properties

el.element

el.element is the value passed to E(value), or the literal tag version of E().

E() DOM Manpulation Instance Methods

The value parameter on these methods can be the same as E(value).

el.appendTo(parent)

Append el.element to a parent element.

el.append(...values)

Append child values to el.element.

el.prepend(...values)

Prepend child values to el.element.

el.remove(childNode)

Remove childNode, or childNode.element from el.element. el.remove() returns the removed child.

If childNode is not an element, or doesn't have an element property el.remove() removes el.element.

el.before(...values)

Insert values before el.element.

el.after(...values)

Insert values after el.element.

el.html(something|undefined)

Set, or get the innerHTML of el.element.

el.html() returns this when set.

el.text(something|undefined)

Set, or get the textContent of el.element.

el.text() returns this when set.

el.attr(name|object, attribute value|undefined)

Set attributes like element.setAttribute(name, attribute value).

If the first parameter is an object then the keys, and values will be set as attributes on el.element.

If the last parameter is undefined, and the first parameter is a string then the attribute value with that name will be returned.

el.attr() returns this when set.

el.prop(name|object, property value|undefined)

el.prop() works similar to el.attr() except what you pass to el.prop() is set directly on el.element.

el.prop() returns this when set.

el.css(source)

Set all CSS properties defined on source.

E('.some-class').css({
    //Change the text color to red
    color: 'red'
});

You can't do el.css(name, value). Use el.style.cssProperty to set, or get each style individually.

el.clone(deep)

el.clone(deep) is the same as element.cloneNode(deep). Expect a copy of el.element to returned wrapped in a new instance of E().

el.contains(element)

el.contains() returns true if element is a child of el.element.

el.animate(keyFrames, options)

Use el.element.animate(). You might need to add a polyfill of web animations. A pollyfill isn't included with this library.

el.generate()

Generate a copy (clone) of el.element. el.generate() takes no parameters. See the documentation for generate.

generate()

Asynchronously create DOM elements using generate.

import { generate } from 'ebla';

let paragraph = generate(contents=>`<p>${contents}</p>`);
paragraph.create(`Asynchronous processes do help.`).then(p=>{
    p.appendTo(document.body);
    //<p>Asynchronous processes do help.</p>
});

generate(callback, parent|undefined)

Create an ElementGenerator instance.

Returned values from callback can be anything E(value) accepts as a value. parent can be undefined, or pass another element as parent. The element produced from the value returned form callback will be appended to parent.

The resolved value from the ElementGenerator.prototype.create is a DOM element wrapped in an instance of E().

let paragraph = generate(
    //The function here gets called on paragraph.create()
    contents=>`<p>${contents}</p>`);

select()

Select an element from the DOM. select(selector) returns an array of instances of E() that are wrapped around each selected DOM element.

spawn()

Synchronously create a certain amount of elements in an array using spawn(value, num).

import { spawn } from 'ebla';
let list = spawn('<li></li>', 3);
console.log(list.length); //prints 3

About

Let's get along with the DOM a little better.