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

cinco

v0.1.6

Published

cinco ===

Downloads

24

Readme

cinco

HTML5 as ES6 objects - easy to manipulate and render. Handy for rapid prototyping. Is isomorphic.

Overview

Example on how to create a HTML5 document and then render it to string


import { Document, Element } from cinco;

// Create a new HTML5 document

let document = new Document()

    .add(
        new Element('title').text('Good morning')
    );

// Update DOM

if ( new Date().getHours > 12 ) {
    document.find('title').get(0).text('Good evening');
}

// Render to string

document.render(); // see results below
<!doctype html>
<meta charset="utf-8" />
<title>Good morning</title>

ES5 support

var cinco = require('cinco/dist'),
    Element = cinco.Element,
    Document = cinco.Document;

Element

new Element(
    { String | Function } selector,
    { Object | Function }? attributes,
    { [Element] | Elements | Function | [Function] }? children
)
// Create a h1 element
let myElement = new Element('h1');

// Get HTML source as string
myElement.render() // <h1></h1>

You can declare attributes in the selector as well:

new Element('h1#foo.bar.barz'); // <h1 id="foo" class="bar barz"></h1>

Attributes

Attributes are passed as an object:

new Element('a', { 'href': '/' }); // <a href="/"></a>

// You can also use the `attr` method
new Element('a').attr('href', '/'); // <a href="/"></a>

// Pass a function

You can also pass functions:

var props = {
    signedIn: true,
    user: {
        id: 123
    }
}

new Element('a', { href: () => '/' }); // <a href="/"></a>
new Element('a', { href: async() => await async() }); // You can use async functions

Manipulate text

let p = new Element('p');

// Setter
p.text('Hello world!') // <p>Hello world!</p>

// Gettter
p.text(); // Hello world!

Conditional rendering

The conditions, if one evaluated to false, will skip the rendering of the element.

new Element('p').condition(true); // <p></p>

new Element('p').condition(false); // 

// You can use functions

let element = new Element('p').condition(async() => await async());

// Whether or not all conditions return to true

element.satisfies(); // true|false

Append children

new Element('foo').add(new Element('bar')); // <foo><bar></bar></foo>

Clearing all children

new Element('foo').add(new Element('bar')).empty(); // <foo></foo>

Remove a child

let form = new Element('form');
let fieldset = new Element('fieldset');

form.add(fieldset);

form.render(); // <form><fieldset></fieldset></form>

// Act like an array filter() => true gets removed
form.remove(child => child.is('fieldset'));

form.render(); // <form></form>

Find

Utility to find and manipulate elements. Returns Elements

let form = new Element('form').add(
    new Element('fieldset').add(
        new Element('legend').text('Legend'),
        new Element('section.form-group').add(
            new Element('button')
        )
    )
);

// Find button and add text to it

form.find('button').each(button => button.text('Click me!'));

// Find an element by text

form.findByText('Click me!');

// Find an element by text using a regex

form.findByText(/click/i);

Classes

let elem = new Element('.c1', { className: 'c2 c3' }); // <div class="c1 c2 c3"></div>
let elem = new Element('.c1', { className: ['c2', 'c3'] }); // <div class="c1 c2 c3"></div>
let elem = new Element('.c1').addClass('c2', 'c3'); // <div class="c1 c2 c3"></div>
elem.removeClass('c3'); // <div class="c1 c2"></div>

elem.hasClass('c3'); // false