🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@qc/inject-element

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

@qc/inject-element

A promise-based `Element` injection utility. Great for injecting `img`, `link`, and `script` elements.

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

@qc/inject-element

A promise-based Element injection utility. Great for injecting img, link, and script elements.

The promise resolves successfully after the resource successfully loads. The promise rejects if an error occurs while loading or if the loading times out.

Syntax

type CssSelector = string;

type NodeLike = CssSelector | Node;

type AttachAction = 'after' | 'before' | 'endof' | 'startof';

type AttachableString = AttachAction + '@' + CssSelector;

interface AttachableObject {
  [AttachAction]: NodeLike;
}

type Attachable = AttachableString | AttachableObject;

See @qc/attach-node for examples of uses of Attachables.

Examples

import injectElement from 'inject-element'

injectElement({
  tag: 'script',
  src: 'https://cdn.example.com/foobar.js',
  attach: 'endof@body', // An `Attachable`.
})
  .then((elmt) => {
    // Do what is needed now that the dependency successfully loaded.
  })
  .catch((err) => {
    console.error(err)
    // Maybe notify user that something went wrong and should try refreshing.
  })

injectElement({
  tag: 'link',
  href: 'https://cdn.example.com/foobar.css',
  type: 'stylesheet',
  attach: 'endof@head' // An `Attachable`.
})

Keywords

attach

FAQs

Package last updated on 15 Mar 2020

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