Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
HTML5 as ES6 objects - easy to manipulate and render. Handy for rapid prototyping. Is isomorphic.
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>
var cinco = require('cinco/dist'),
Element = cinco.Element,
Document = cinco.Document;
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 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
let p = new Element('p');
// Setter
p.text('Hello world!') // <p>Hello world!</p>
// Gettter
p.text(); // Hello world!
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
new Element('foo').add(new Element('bar')); // <foo><bar></bar></foo>
new Element('foo').add(new Element('bar')).empty(); // <foo></foo>
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>
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);
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
FAQs
cinco ===
The npm package cinco receives a total of 1 weekly downloads. As such, cinco popularity was classified as not popular.
We found that cinco demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.