New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flyweight-dom

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flyweight-dom

The extremely fast DOM implementation.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Flyweight DOM 🍃 build

The extremely fast DOM implementation.

  • Zero dependencies;
  • Just 3 kB gzipped;
  • DOM can be extended with custom nodes;
  • Low memory consumption.
npm install --save-prod flyweight-dom

Usage

🔎 API documentation is available here.

The implementation provides classes for all DOM nodes:

import { Element } from 'flyweight-dom';

const element = new Element('div').append(
  'Hello, ',
  new Element('strong').append('world!')
);

element.classList.add('red');

element.getAttribute('class');
// ⮕ 'red'

You can create custom nodes by extending Node class or its subclasses:

import { Element, Node } from 'flyweight-dom';

class MyNode extends Node {}

new Element('div').appendChild(new MyNode());

Or extend your already existing classes using a declaration merging:

// Your existing class
class MyClass {}

// Merge declarations
interface MyClass extends Node {}

// Extend the prototype
Node.extend(MyClass);

new Element('div').append(new MyClass());

Performance considerations

For better performance, prefer nextSibling and previousSibling over childNodes and children whenever possible.

for (let child = node.firstChild; child !== null; child = child.nextSibling) {
  // Process the child 
}

When you read the childNodes or children properties for the first time an array of nodes is created and then stored on the node instance. Later when you modify child nodes using appendChild, removeChild or any other method, these arrays are updated.

Keywords

FAQs

Package last updated on 24 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc