Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
create-element-x
Advanced tools
Extends document.createElement to conform to the target API of JSX
Extends document.createElement
to conform to the target API of JSX transpilation.
var element = document.createElement(tagName[, attributes[, children]])
This package is useful when frequently creating DOM nodes on the fly, e.g.:
function makeSpinner(id) {
const div = document.createElement('div');
div.id = id;
div.classList.add('sk-folding-cube');
const cube1 = document.createElement('div');
cube1.classList.add('sk-cube1')
cube1.classList.add('sk-cube')
const cube2 = document.createElement('div');
cube2.classList.add('sk-cube2')
cube2.classList.add('sk-cube')
const cube3 = document.createElement('div');
cube3.classList.add('sk-cube3')
cube3.classList.add('sk-cube')
const srOnly = document.createElement('span')
srOnly.classList.add('sr-only');
srOnly.textContent = 'Loading...';
div.appendChild(cube1);
div.appendChild(cube2);
div.appendChild(cube3);
div.appendChild(srOnly);
return div;
}
becomes
import 'create-element-x';
function makeSpinner(id) {
return document.createElement('div', { id, 'class': 'sk-folding-cube' }, [
document.createElement('div', { 'class': 'sk-cube1 sk-cube' }),
document.createElement('div', { 'class': 'sk-cube2 sk-cube' }),
document.createElement('div', { 'class': 'sk-cube3 sk-cube' }),
document.createElement('span', { 'class': 'sr-only' }, 'Loading...'),
]);
}
When using babel and babel-plugin-transform-react-jsx
you can use JSX,
which transpiles to the example above.
/* pragma: document.createElement */
import 'create-element-x';
function makeSpinner(id) {
return (
<div id={id} class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
<span class="sr-only">Loading...</span>
</div>
);
}
Instead of setting pragma
via comment, you can configure babel globally via .babelrc
:
{
"plugins": [
["transform-react-jsx", {
"pragma": "document.createElement"
}]
]
}
Import the library funtion instead:
/* pragma: createElement */
import { createElement } from 'create-element-x/library'
Monkey-patch:
<script src="https://unpkg.com/create-element-x/dist/index.min.js"></script>
Library:
<script src="https://unpkg.com/create-element-x/dist/library.min.js"></script>
<script>
const { createElement } = window.createElementX;
createElement('div', { id, 'class': 'sk-folding-cube' });
// ...
</script>
jsdom
or other DOM implementations?import { JSDOM } from 'jsdom';
import { createCreateElement } from 'create-element-x/factory';
const { window: { document } } = new JSDOM();
const createElement = createCreateElement(
tagName => document.createElement(tagName),
text => document.createTextNode(text),
);
jsx-dom
, jsx-create-element
, nativejsx
, and jsx-foobar
?This package does less. All it does is to create a DOM node.
Courage.
FAQs
Extends document.createElement to conform to the target API of JSX
The npm package create-element-x receives a total of 0 weekly downloads. As such, create-element-x popularity was classified as not popular.
We found that create-element-x 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.