
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@blue-hood/velement
Advanced tools
A minimal DOM renderer.
With JavaScript:
import VirtualElement, {appendChildren, createElement} from 'velement';
class Div 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(Div, {});
appendChildren(container, 'TextNode', htmlElement, virtualElement);
Then with TypeScript:
import VirtualElement, {appendChildren, createElement} from 'velement';
class Div extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
this.element.innerHTML = 'VirtualDivElement';
}
}
const container = document.createElement('div');
const htmlElement = createElement<HTMLDivElement>('div', null);
htmlElement.innerHTML = `HTMLDivElement`;
const virtualElement = createElement<Div, {}>(Div, {});
appendChildren(container, 'TextNode', htmlElement, virtualElement);
Container element will be rendered like:
<div>
TextNode
<div>
HTMLDivElement
</div>
<div>
VirtualDivElement
</div>
</div>
Just run npm install velement
or yarn add velement
.
VirtualElements are wrapper elements of HTML elements. Typically, a minimum VirtualElement with HTMLDivElement is defined as:
import VirtualElement from 'velement';
class Div extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
}
}
new Div(null);
Then, the constructor can have properties.
The inner HTML element can be accessed through this.element
.
import VirtualElement from 'velement';
interface DivProps {
text: string;
}
class Div extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null, props: DivProps) {
super(element || 'div');
this.element.innerHTML = props.text;
}
}
new Div(null, {
text: 'VirtualDivElement. '
});
VirtualElement also can be rendered to existing element.
const div = document.createElement('div');
new Div(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<HTMLDivElement>('div', {
style: `
color: red;
`
}, 'HTMLDivElement. ');
ex. VirtualElement
import VirtualElement, {createElement} from 'velement';
interface DivProps {
color: string
}
class Div extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null, props: DivProps) {
super(element || 'div');
this.element.style.color = props.color;
}
}
createElement<Div, DivProps>(Div, {
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 Div extends VirtualElement<HTMLDivElement> {
public constructor(element: HTMLDivElement | null) {
super(element || 'div');
}
}
const container = document.createElement('div');
appendChildren(container, createElement<Div, {}>(Div, {}), createElement<HTMLDivElement>('div', null), 'TextNode. ');
velement を使うと、React がいかに洗練されているかを体感することができるでしょう。
FAQs
A minimal DOM renderer for legacy browsers.
The npm package @blue-hood/velement receives a total of 1 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.