{"id":17349312,"url":"https://github.com/co2-git/cinco","last_synced_at":"2025-03-27T11:44:35.517Z","repository":{"id":32156227,"uuid":"35729308","full_name":"co2-git/cinco","owner":"co2-git","description":"HTML5 as es6 objects","archived":false,"fork":false,"pushed_at":"2016-02-12T19:01:00.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T16:23:29.713Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/co2-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-16T15:38:34.000Z","updated_at":"2016-02-12T19:00:48.000Z","dependencies_parsed_at":"2022-09-03T22:11:59.257Z","dependency_job_id":null,"html_url":"https://github.com/co2-git/cinco","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fcinco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fcinco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fcinco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fcinco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co2-git","download_url":"https://codeload.github.com/co2-git/cinco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245841692,"owners_count":20681184,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T16:55:23.994Z","updated_at":"2025-03-27T11:44:35.497Z","avatar_url":"https://github.com/co2-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cinco\n===\n\nHTML5 as ES6 objects - easy to manipulate and render. Handy for rapid prototyping. Is isomorphic.\n\n# Overview\n\nExample on how to create a HTML5 document and then render it to string\n\n```js\n\nimport { Document, Element } from cinco;\n\n// Create a new HTML5 document\n\nlet document = new Document()\n\n    .add(\n        new Element('title').text('Good morning')\n    );\n\n// Update DOM\n\nif ( new Date().getHours \u003e 12 ) {\n    document.find('title').get(0).text('Good evening');\n}\n\n// Render to string\n\ndocument.render(); // see results below\n```\n\n```html\n\u003c!doctype html\u003e\n\u003cmeta charset=\"utf-8\" /\u003e\n\u003ctitle\u003eGood morning\u003c/title\u003e\n```\n\n# ES5 support\n\n```js\nvar cinco = require('cinco/dist'),\n    Element = cinco.Element,\n    Document = cinco.Document;\n```\n\n# Element\n\n    new Element(\n        { String | Function } selector,\n        { Object | Function }? attributes,\n        { [Element] | Elements | Function | [Function] }? children\n    )\n\n\n```js\n// Create a h1 element\nlet myElement = new Element('h1');\n\n// Get HTML source as string\nmyElement.render() // \u003ch1\u003e\u003c/h1\u003e\n```\n\nYou can declare attributes in the selector as well:\n\n```js\nnew Element('h1#foo.bar.barz'); // \u003ch1 id=\"foo\" class=\"bar barz\"\u003e\u003c/h1\u003e\n```\n\n# Attributes\n\nAttributes are passed as an object:\n\n```js\nnew Element('a', { 'href': '/' }); // \u003ca href=\"/\"\u003e\u003c/a\u003e\n\n// You can also use the `attr` method\nnew Element('a').attr('href', '/'); // \u003ca href=\"/\"\u003e\u003c/a\u003e\n\n// Pass a function\n```\n\nYou can also pass functions:\n\n```js\nvar props = {\n    signedIn: true,\n    user: {\n        id: 123\n    }\n}\n\nnew Element('a', { href: () =\u003e '/' }); // \u003ca href=\"/\"\u003e\u003c/a\u003e\nnew Element('a', { href: async() =\u003e await async() }); // You can use async functions\n```\n\n# Manipulate text\n\n```js\nlet p = new Element('p');\n\n// Setter\np.text('Hello world!') // \u003cp\u003eHello world!\u003c/p\u003e\n\n// Gettter\np.text(); // Hello world!\n```\n\n# Conditional rendering\n\nThe conditions, if one evaluated to false, will skip the rendering of the element.\n\n```js\nnew Element('p').condition(true); // \u003cp\u003e\u003c/p\u003e\n\nnew Element('p').condition(false); // \n\n// You can use functions\n\nlet element = new Element('p').condition(async() =\u003e await async());\n\n// Whether or not all conditions return to true\n\nelement.satisfies(); // true|false\n```\n\n# Append children\n\n```js\nnew Element('foo').add(new Element('bar')); // \u003cfoo\u003e\u003cbar\u003e\u003c/bar\u003e\u003c/foo\u003e\n```\n\n# Clearing all children\n\n```js\nnew Element('foo').add(new Element('bar')).empty(); // \u003cfoo\u003e\u003c/foo\u003e\n```\n\n# Remove a child\n\n```js\nlet form = new Element('form');\nlet fieldset = new Element('fieldset');\n\nform.add(fieldset);\n\nform.render(); // \u003cform\u003e\u003cfieldset\u003e\u003c/fieldset\u003e\u003c/form\u003e\n\n// Act like an array filter() =\u003e true gets removed\nform.remove(child =\u003e child.is('fieldset'));\n\nform.render(); // \u003cform\u003e\u003c/form\u003e\n```\n\n# Find\n\nUtility to find and manipulate elements. Returns `Elements`\n\n```js\nlet form = new Element('form').add(\n    new Element('fieldset').add(\n        new Element('legend').text('Legend'),\n        new Element('section.form-group').add(\n            new Element('button')\n        )\n    )\n);\n\n// Find button and add text to it\n\nform.find('button').each(button =\u003e button.text('Click me!'));\n\n// Find an element by text\n\nform.findByText('Click me!');\n\n// Find an element by text using a regex\n\nform.findByText(/click/i);\n```\n\n# Classes\n\n```js\nlet elem = new Element('.c1', { className: 'c2 c3' }); // \u003cdiv class=\"c1 c2 c3\"\u003e\u003c/div\u003e\nlet elem = new Element('.c1', { className: ['c2', 'c3'] }); // \u003cdiv class=\"c1 c2 c3\"\u003e\u003c/div\u003e\nlet elem = new Element('.c1').addClass('c2', 'c3'); // \u003cdiv class=\"c1 c2 c3\"\u003e\u003c/div\u003e\nelem.removeClass('c3'); // \u003cdiv class=\"c1 c2\"\u003e\u003c/div\u003e\n\nelem.hasClass('c3'); // false\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fcinco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco2-git%2Fcinco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fcinco/lists"}