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

@itrocks/build

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itrocks/build

Permanently apply javascript modifiers to your dynamic DOM

  • 0.0.19
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

npm version npm downloads GitHub issues discord

build

Apply JavaScript code to your dynamic DOM, automatically executed each time a new matching element is added.

Installation

npm i @itrocks/build

Usage

To execute a function each time a new element is added to the DOM:

import build from './node_modules/@itrocks/build/build.js'
build<HTMLAnchorElement>('a', anchor => console.log('DOM + anchor', anchor))

This will display "DOM + anchor" in your console for every anchor already present in the DOM.

If you later add another anchor:

document.body.append(document.createElement('a'))

"DOM + anchor" will appear in your console again.

Demo, Testing and Development

git clone https://github.com/itrocks-ts/build
cd build
npm install
npm run build

To test, serve demo/build.html with a local web server and open your browser's console to see it in action.

API

build

Executes a callback each time a matching element is added to the DOM.

build(callback)
build(event)
build(selector, callback)
build(selector, event, callback)
build(selector, type, callback)
Parameters
  • selector: A string with one or more CSS selectors to match.
    For complex multiple-selectors, you may use a CSS selectors chain.
    Defaults to the ALWAYS constant, triggering the callback for any element added to the DOM.
  • type: A case-sensitive string representing the event type to listen for.
    Defaults to the CALL constant, which calls the callback immediately when an element is added to the DOM.
  • event: A BuildEvent object that configures the build event manager. Properties include selector, type, callback, args, priority.
    • args: Additional arguments to pass to the callback.
    • priority: Defaults to 1000. If multiple build events match the same element, you can prioritize them by setting different values.
    • Other properties correspond to build() parameters.

  • callback: The function to execute.
    callback(element, ...args)
    
    • element: The DOM element that triggered the callback.
    • args: Additional arguments associated with the build event.

Constants

  • ALWAYS: A universal selector that applies to any element added to the DOM.
  • CALL: A special event type that calls a callback immediately upon adding an element to the DOM.

CSS selectors chain

This feature avoids repeating CSS paths within complex CSS selector strings.

Example

This selector string with repeated CSS path body > main:

'body > main > header > h2, body > main > h2'

Is equivalent to:

['body > main', '> header > h2, > h2']

Keywords

FAQs

Package last updated on 20 Dec 2024

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