Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Build dom structure easy way with plain JavaScript. Can be used on both client and server side.
$ npm install domjs
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack
What would be the easiest, most intuitive way to build html5 DOM tree with plain JavaScript ?
var mytemplate = function () {
header(
h1('Heading'),
h2('Subheading'));
nav(
ul({ 'class': 'breadcrumbs' },
li(a({ href: '/' }, 'Home')),
li(a({ href: '/section/'}, 'Section')),
li(a('Subject'))));
article(
p('Lorem ipsum...'));
footer('Footer stuff');
};
This is how templates for domjs can be written.
Plain domjs
usage example:
var domjs = require('domjs')(document);
var ns = domjs.ns;
var dom = domjs.collect(function () {
ns.header(
ns.h1('Heading'),
ns.h2('Subheading'));
ns.nav(
ns.ul({ 'class': 'breadcrumbs' },
ns.li(a({ href: '/' }, 'Home')),
ns.li(a({ href: '/section/'}, 'Section')),
ns.li(a('Subject'))));
ns.article(
ns.p('Lorem ipsum...'));
ns.footer('Footer stuff');
});
document.body.appendChild(dom); // Insert generated DOM into document body
To use domjs functions literally as in first example, you will need to prepare dedicated function wrapper (either programmatically or manually) as e.g. following:
var myTemplate = (function () {}
var { article, footer, h1, h2, header, li, nav, p, ul } = ns;
return function () {
header(
h1('Heading'),
h2('Subheading'));
nav(
ul({ 'class': 'breadcrumbs' },
li(a({ href: '/' }, 'Home')),
li(a({ href: '/section/'}, 'Section')),
li(a('Subject'))));
article(
p('Lorem ipsum...'));
footer('Footer stuff');
};
}());
var dom = domjs.collect(myTemplate);
You can create custom elements:
var myCustomElement = domjs.ns.myCustomElement = domjs.ns.element.bind(domjs, 'my-custom-element');
Optionally you may also provide some custom constructor or methods for that element:
// This has to be defined before any `my-custom-element` is created by domjs
require('domjs/ext')['my-custom-element'] = {
_construct: function (/* constuctor args */) {},
methodA: function () { ... }
};
You can save references to elements and operate on them later:
var myul = ul(li('one'), li('two'), li('three'));
// ... some code ...
// add extra items to myul
myul(li('four'), li('five'));
// append myul into other element
div(myul);
You can access DOM elements directly, just invoke returned function with no arguments
(myul() instanceof DOMElement) === true
Comment type nodes:
comment('my comment');
CDATA type nodes
cdata('cdata text');
Text nodes in main scope:
text('my text');
Elements with names that are reserved keywords in JavaScript language, like 'var', should be created with preceding underscore added to its name:
_var('var content');
$ npm test
FAQs
DOM template engine for client and server
The npm package domjs receives a total of 125 weekly downloads. As such, domjs popularity was classified as not popular.
We found that domjs 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.