@tankbar/dom-utils
v1.0.4
Published
This is a set of utilities used for DOM-manipulation.
Downloads
76
Maintainers
Keywords
Readme
@tankbar/dom-utils
This is a set of utilities used for DOM-manipulation.
Installation
npm install --save @tankbar/dom-utils
Usage
The most simple use case is to generate simple HTML which we can then append to the DOM.
import { html } from '@tankbar/dom-utils';
document.body.appendChild(
html`
<p>Hello world</p>
`
);
We can also leverage template strings to add some dynamic data to the result.
import { html } from '@tankbar/dom-utils';
const name = 'John Doe';
document.body.appendChild(
html`
<p>Hello ${name}</p>
`
);
We can also use functions!
import { html } from '@tankbar/dom-utils';
function Component() {
return 'Here comes Johnny!';
}
document.body.appendChild(
html`
<p>${Component}</p>
`
);
And classes!
import { html } from '@tankbar/dom-utils';
class Component {
render() {
return 'Oh my lord!';
}
}
const instance = new Component();
document.body.appendChild(
html`
<p>${instance}</p>
`
);
And we can also use arrays for some simple composition.
import { html } from '@tankbar/dom-utils';
const data = [
html`<p>This is the first paragraph</p>`,
function() {
return '<p>This is the second paragraph</p>';
}
];
document.body.appendChild(
html`
<div>
${data}
</div>
`
);
License
Copyright (c) 2023, Tankbar AB
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.