Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ez-elements
Advanced tools
[![Build Status](https://travis-ci.org/ez-elements/ez-elements.svg?branch=master)](https://travis-ci.org/ez-elements/ez-elements) [![Coverage Status](https://coveralls.io/repos/github/ez-elements/ez-elements/badge.svg?branch=master)](https://coveralls.io
ez-elements
is a thin wrapper for the built-in HTMLElement
class that aims to simplify writing imperative element creation and manipulation approachable in TypeScript.
If you find yourself writing a lot of document.createElement
and dealing with the low-level built-in HTMLElement
class then ez-elements
can simplify a lot of the boilerplate code you're writing.
As an example, lets look at using document.createElement
directly to create a div
with two spans
inside that is then appended to document.body
:
const someDiv = document.createElement('div');
someDiv.classList.add('some-div');
const spanOne = document.createElement('span');
spanOne.classList.add('some-span');
spanOne.textContent = 'Hello ';
const spanTwo = document.createElement('span');
spanTwo.classList.add('some-span');
spanTwo.textContent = 'World';
someDiv.append(spanOne, spanTwo);
document.body.appendChild(someDiv);
By using the ez
function from ez-elements
we can simplify this to the following:
import { ez } from 'ez-elements';
let spanOne, spanTwo; // variables not required, but you can assign them inside the append
const someDiv = ez('div', 'some-div').append(
spanOne = ez('span', 'some-span').setTextContent('Hello '),
spanTwo = ez('span', 'some-span').setTextContent('World'),
).appendTo(document.body);
npm install ez-elements --save
Alternatively, you can install just the parts of the package that you want:
@ez-elements/core
contains ez
, EZElement
, EZDiv
and EZSpan
.@ez-elements/inputs
contains EZTextInput
and EZButton
.@ez-elements/jsx
contains JSX
.@ez-elements/shadow
contains EZShadowElement
and extractStyleContents
.Check out the Examples page.
The ez
function has the following interface:
EZElement
instance.function ez<T extends keyof HTMLElementTagNameMap>(
arg: T | HTMLElementTagNameMap[T] | EZElement<T>,
classes?: string | Array<string> | { [key: string]: boolean },
): EZElement<T>
You can also construct EZElement
instances directly using:
const element = new EZElement('div');
Or extend EZElement
to create components:
class SomeComponent extends EZElement<'div'> {
constructor(text: string) {
super('div');
this.addClass('some-component').append(
ez('span').setTextContent(text),
);
}
}
const instance = new SomeComponent('Hello World');
instance.appendTo(document.body);
The EZElement
instance is a wrapper for a HTMLElement
and provides a builder pattern interface to allow chaining, including appending/prepending children, appending to parents, adding classes, adding styles etc.
The reason you should care about what is happening under-the-hood is so that you can:
The intent of the wrapper is to be thin and as close to stateless as possible whilst remaining useful.
The priorities of the package are to enable your code to be (in descending priority order):
This repository uses lerna to manage the multiple packages contained within it.
# Installs dependencies *and links the packages together using lerna*
npm install
# In one terminal - watch and rebuild the packages upon changes
npm run watch
# In another terminal - start a parcel server that serves a single page app with some examples
cd examples
npm start
FAQs
[![Build Status](https://travis-ci.org/ez-elements/ez-elements.svg?branch=master)](https://travis-ci.org/ez-elements/ez-elements) [![Coverage Status](https://coveralls.io/repos/github/ez-elements/ez-elements/badge.svg?branch=master)](https://coveralls.io
The npm package ez-elements receives a total of 10 weekly downloads. As such, ez-elements popularity was classified as not popular.
We found that ez-elements 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.