
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Simple ES6 utilities to manipulate DOM
createElement
method (no react)$ npm install dom-magic --save
$ yarn add dom-magic
File: gulpfile.js
const _rollup_babel = require('rollup-plugin-babel');
const _rollup_resolve = require('@rollup/plugin-node-resolve');
_gulp.task('es6-transpile', async function(){
const bundle = await _rollup.rollup({
input: './src/browser/EnlighterJS.js',
plugins: [
_rollup_resolve(),
_rollup_babel()
]
});
// write the bundle to disk
await bundle.write({
format: 'iife',
name: 'EnlighterJS',
file: './.tmp/enlighterjs.js'
});
});
File: babel.config.json
{
"plugins": [
["@babel/plugin-transform-react-jsx", {
}]
],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": [
"safari >= 7",
"IE >= 9",
"ios >= 9",
"firefox >= 50",
"chrome >= 50",
"edge >= 11"
]
},
"debug": false
}
]
]
}
File: button.jsx
// Internal "ReactDOM"
import * as React from 'dom-magic';
export function Button(props){
// button css classes
const classes = ['enlighter-btn'];
// name set ?
if (props.name){
classes.push('enlighter-btn-' + props.name);
}
// create button
return <div
className={classes.join(' ')}
onClick={props.onClick}
>
{props.text||null}
</div>
}
createElement
is provided by dom-magic
function Button(props) {
// button css classes
var classes = ['enlighter-btn']; // name set ?
if (props.name) {
classes.push('enlighter-btn-' + props.name);
} // create button
return createElement("div", {
className: classes.join(' '),
onClick: props.onClick
}, props.text || null);
}
var domMagic = require('dom-magic');
// get target container
var targetEl = domMagic.getElement('#container-a');
// create element
var buttonEl = Button({
text: "hello world",
name: "test"
});
// inject
domMagic.insertBefore(targetEl, buttonEl);
dom-magic is OpenSource and licensed under the Terms of MPL 2.0 - your're welcome to contribute
1.1.0 ###
logInfo
and logError
for console.log
FAQs
simple ES6 utilities to manipulate browsers DOM
We found that dom-magic 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.