
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
ebuilder-js
Advanced tools
Highly configurable and easily manipulable elements in a single declaration, with a functionnal touch.
Highly configurable and manipulable elements in a single declaration, with a functionnal touch.
README in progress!
npm i ebuilder-js
import EBuilder from 'ebuilder-js'
// test
EBuilder('div').into(document.body)
<script src="./path/to/ebuilder.min.js">
EBuilder('div').into(document.body)
el
, element
: the generated HTML element.htmlContent()
: returns the current element's innerHTMLcount()
: returns the current element's amount of child nodes (might change to child element nodes instead)toString()
: returns the current element's outerHTML. It can be handy to add it to the DOM quite quicklyconst elButton = EBuilder('button').set({ ... })
someElement.innerHTML += elButton
Signature:
EBuilder(myElement).set({}: {
attributes?: { [attributeName: string]: string },
properties?: { [propertyName: string]: any },
listeners?: EventTuple | EventTuple[]
children?: ValidChild | ValidChild[],
})
Any value can be replaced with a function to be executed in the process (provided that function returns an appropriate value). This can be useful in many situations:
this
, it allows auto-reference
This can be useful when you want to render a non-static result. Consider the following:EBuilder(myElement).setProperties({
'innerHTML@on:click': myElement.el.htmlContent() + `<p>I have ${myElement.el.count()} children.</p>`
})
This won't work as expected as the length
value is calculated once and will always output the value at the moment of declaration.
Instead, use the following:
EBuilder(myElement).setProperties({
'innerHTML@on:click': () => myElement.el.htmlContent() + `<p>I have ${myElement.el.count()} children.</p>`
})
Note that function expressions are called with this
value as the current EBuilder instance, so you can do instead :
EBuilder(myElement).setProperties({
'innerHTML@on:click': function() { return this.htmlContent() + `<p>I have ${this.count()} children.</p>` }
})
Expects an array of / a single value of :
Added at the end of a key string, @-rules allow conditionnal evaluation of the corresponding value in an object. Such rules are available in every object argument of a setting method (.setStyles(), .setChildren()...), including the set() method at both levels:
const elButton = EBuilder('button').set({
'properties@on:mouseover': {
'textContent@interval:1000': () => new Date().getSeconds()
}
}).into(document.body)
@on
, @once
The corresponding value will be set when an :eventName
event is emitted by the current element.
{ 'key@on:eventName': 'value' }
would basically translate to
this.addEventListener('eventName', () => element.key = 'value')
With @on
the value will be updated each time the event occurs, and only the first time with @once
:eventName
The event name can be any string value:
click
, keydown
...EBuilderinsert
, EBuilderset
'faisons comme ça!'
Note that EBuilder allows to dispatch such events easily with the dispatch()
method, which allows to do such things:
Considering const elList = EBuilder('ul').into(document.body)
,
elList.set({
properties: {
'innerHTML@once:hi-there': () => elList.htmlContent() + '<li>2</li>'
}
}).setChildren('<li>1</li>').dispatch('hi-there')
will output:
#event-emitter
By default, the listener is set on the current element. But what if I want my element to react to an external event, like a click on a button?
To achieve this you can designate a specific target using #
in the string key after the event name. But there's a catch: for EBuilder to recover the right object from that string, it must have been previously referenced with the given()
method, as in the example below:
const myButton = EBuilder('button').into(document.body)
EBuilder('p')
.given([ myButton, 'buttonRef' ])
.setProperties({ 'textContent@once:click#buttonRef': 'Hello!' })
.into(document.body)
(More details about given()
below)
The window
object is an exception to this rule, as it doesn't need to be pre-indexed.
@timeout
@interval
'key@timeout:duration'
, 'key@interval:duration'
These methods have the same behaviour as the eponym functions. Example:
EBuilder('div').into(document.body).setStyles({
width: '200px',
height: '200px',
transition: 'background 1s',
'background@interval:1000': () => `hsl(${360 * Math.random()}, 50%, 50%)`
})
@if
'key@if:functionReference: 'value'
The corresponding value is assigned if the specified :functionReference
function returns true
.
See given()
for more info about references.
@for
-- EXPERIMENTAL --
'key@for:arrayReference: 'value'
The corresponding value is assigned a number of times equal to the length of :arrayReference
See given()
for more info about references.
FAQs
Highly configurable and easily manipulable elements in a single declaration, with a functionnal touch.
The npm package ebuilder-js receives a total of 2 weekly downloads. As such, ebuilder-js popularity was classified as not popular.
We found that ebuilder-js 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.