Code Monkey home page Code Monkey logo

elmen's Introduction

elmen

small JS library for creating and nesting HTML elements and other nodes

introduction

This library was developed to streamline the process of defining and modifying HTML elements by enhancing it with function chaining and intuitive nesting. I started this code one day to give me less of a headache.

example

I want to create a ul element with a number of bullets defined by an input. Here’s a custom function that could be written to generate it:

function makeList(...items) {
	return new Elmen("ul").withClasses("item-list").withAttributes({start: 0}).withChildren(
		items.map(item => new Elmen("li").withChildren(item))
	).done();
}

With an input of a few Strings, I can generate this:

<ul class="item-list" start="0">
	<li>potatos</li>
	<li>carrots</li>
	<li>pie</li>
</ul>

Because of how general the function is, I could even pass in elements like so:

makeList(
	new Elmen("i").withChildren("Escherichia Coli"),
	"sea stars",
	new Elmen("a").withAttributes({href: "https://Wikipedia.org/wiki/Simian"}).withChildren(
		"infraorder ",
		new Elmen("i").withChildren("Simiiformes")
	),
	new Elmen("span").withCSS([["text-transform", "uppercase"], ["font-variant-caps", "unicase"]]).withChildren("tardigrade")
);

to generate this HTML:

<ul class="item-list" start="0">
	<li><i>Escherichia Coli</i></li>
	<li>sea stars</li>
	<li><a href="https://Wikipedia.org/wiki/Simian">infraorder <i>Simiiformes</i></a></li>
	<li><span style="text-transform: uppercase; font-variant-caps: unicase;">tardigrade</span></li>
</ul>

This can be expanded to much more complex applications.

contributing

If you have questions, concerns, or ideas for this project, please reach out to me via email or pull request!

elmen's People

Contributors

rmw4269 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.