Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@blue-hood/velement
Advanced tools
A minimal DOM renderer for legacy browsers
With JavaScript:
import VirtualElement, { appendChildren, createElement } from 'velement';
class JSDiv extends VirtualElement {
constructor(element) {
super(element || 'div');
this.element.innerHTML = 'VirtualDivElement';
}
}
const container = document.createElement('div');
const htmlElement = createElement('div', null);
htmlElement.innerHTML = `HTMLDivElement`;
const virtualElement = createElement(JSDiv, {});
appendChildren(container, 'TextNode', htmlElement, virtualElement);
Then with TypeScript:
import VirtualElement, { appendChildren, createElement } from 'velement';
class TSDiv extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
this.element.innerHTML = 'VirtualDivElement';
}
}
declare module 'velement' {
function createElement(type: typeof TSDiv, props: {}, ...children: Child[]): TSDiv;
}
const container = document.createElement('div');
const htmlElement = createElement('div', null);
htmlElement.innerHTML = `HTMLDivElement`;
const virtualElement = createElement(TSDiv, {});
appendChildren(container, 'TextNode', htmlElement, virtualElement);
Container element will be rendered like:
<div>
TextNode
<div>
HTMLDivElement
</div>
<div>
VirtualDivElement
</div>
</div>
Just run npm install @blue-hood/velement
or yarn add @blue-hood/velement
.
The transpiled code for ES3 target ES2015 Modules is located at dist/.
VirtualElements are wrapper elements of HTML elements. Typically, a minimum VirtualElement with HTMLDivElement is defined as:
import VirtualElement from 'velement';
class TSDiv extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
this.element.innerHTML = 'VirtualDivElement';
}
}
new TSDiv(null);
Then, the constructor can have properties.
The inner HTML element can be accessed through this.element
.
import VirtualElement from 'velement';
interface TextDivProps {
text: string;
}
class TextDiv extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null, props: TextDivProps) {
super(element || 'div');
this.element.innerHTML = props.text;
}
}
new TextDiv(null, {
text: 'VirtualDivElement. '
});
VirtualElement also can be rendered to existing element.
const div = document.createElement('div');
new TextDiv(div, {
text: 'VirtualDivElement. '
});
interface Attributes {
[name: string]: any;
}
type Child = HTMLElement | VirtualElement | string;
export function createElement<HElement extends HTMLElement>(
type: keyof HTMLElementTagNameMap,
props: Attributes | null,
...children: Child[]
): HElement;
export function createElement<VElement extends VirtualElement, Props>(
type: { new (element: null, props: Props): VElement },
props: Props,
...children: Child[]
): VElement;
Create HTML element or VirtualElement with properties.
And render children to the inner element, this is equal to appendChildren
function.
ex. HTMLDivElement
import { createElement } from 'velement';
createElement(
'div',
{
style: `
color: red;
`
},
'HTMLDivElement. '
);
ex. VirtualElement
import VirtualElement, { createElement } from 'velement';
interface ColorDivProps {
color: string;
}
class ColorDiv extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null, props: ColorDivProps) {
super(element || 'div');
this.element.style.color = props.color;
}
}
declare module 'velement' {
function createElement(type: typeof ColorDiv, props: ColorDivProps, ...children: Child[]): ColorDiv;
}
createElement(
ColorDiv,
{
color: 'red'
},
'VirtualDivElement. '
);
type Child = HTMLElement | VirtualElement | string;
function appendChildren(element: HTMLElement, ...children: Child[]): void;
Append children - HTML element, VirtualElement, text - to HTML element.
ex.
import VirtualElement, { appendChildren, createElement } from 'velement';
class TSDiv extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
this.element.innerHTML = 'VirtualDivElement';
}
}
declare module 'velement' {
function createElement(type: typeof TSDiv, props: {}, ...children: Child[]): TSDiv;
}
const container = document.createElement('div');
const htmlElement = createElement('div', null);
htmlElement.innerHTML = `HTMLDivElement`;
appendChildren(container, createElement(TSDiv, {}), htmlElement, 'TextNode. ');
FAQs
A minimal DOM renderer for legacy browsers.
The npm package @blue-hood/velement receives a total of 0 weekly downloads. As such, @blue-hood/velement popularity was classified as not popular.
We found that @blue-hood/velement 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.