util-dom

Methods

(static) injectScript(src, positionopt, configopt) → {Promise}

inject Script tag to the document at the specified position
Parameters:
Name Type Attributes Default Description
src string
position string <optional>
head where Script tag needs to be appended
config object <optional>
{} configuration options
Properties
Name Type Attributes Default Description
html object <optional>
innerHTML of the script tag if src is not provided
id object <optional>
StringiedRandomNumber id of the script tag
Since:
  • 0.0.5
Source:
Example
// return Promise
injectScript('https://example.example'. 'body').then(src => console.log(`Appended ${src}`))

// returns Promise
injectScript('https://example.example', '#my-elm-id').then(src => console.log(`Appended ${src}`))
// returns Promise
injectScript(null, '#my-elm-id', {html: `<a href="">Example</a>`}).then(src => console.log(`Appended ${src}`))
Insert link tag to the document at the specified position
Parameters:
Name Type Attributes Default Description
href string
position string <optional>
head where link tag needs to be appended
Since:
  • 0.0.5
Source:
// return Promise
insertLink('https://example.example').then(() => console.log(`Appended`))

// returns Promise
insertLink('https://example.example', 'body').then(() => console.log(`Appended`))

(static) insertStyle(content, positionopt) → {Promise}

Insert style tag to the document at the specified position
Parameters:
Name Type Attributes Default Description
content string
position string <optional>
head where style tag needs to be appended
Since:
  • 0.0.5
Source:
Example
// return Promise
insertStyle(`a{color:red;}`).then(() => console.log(`Appended`))

// returns Promise
insertStyle(`a{color:red;}`, 'body').then(() => console.log(`Appended`))

(inner) getNearestSelectorPath(node) → {string}

Gives the nearest(shorter) selector path for the specified Node element
Parameters:
Name Type Description
node * HTML Node
Source:
Example
// returns my-id
getNearestSelectorPath(document.querySelector('#my-id'));
// returns '.flex-column.mb-2.mb-md-0.mr-0.pr-md-4 > h5:nth-of-type(1)'
getNearestSelectorPath($0); // some arbitary DOM element

(inner) isDynamicClass(identifier) → {boolean}

Checks wthether the input value matches the dynamic id criteria
Parameters:
Name Type Description
identifier string input value
Since:
  • 0.0.2
Source:
Example
// return true
isDynamicClass('myDiv-aaa_1234');

(inner) isDynamicId(identifier) → {boolean}

Checks wthether the input value matches the dynamic id criteria
Parameters:
Name Type Description
identifier string input value
Since:
  • 0.0.2
Source:
Example
// returns true
isDynamicId('myDiv-aaa_1234');

(inner) isSelectorElementPresent(path) → {boolean}

Checks if the element having the specified path exists
Parameters:
Name Type Description
path string selector of an element
Since:
  • 0.0.5
Source:
Example
// returns true
isSelectorElementPresent('body');
// returns false
isSelectorElementPresent('unknown-selector');