7.2.0 • Published 11 months ago
@swissfederalrailways/dom-component-path v7.2.0
dom-component-path
Get the component path of a DOM element.
Install
npm install @swissfederalrailways/dom-component-path
Example
Running the following code:
import domComponentPath from '@swissfederalrailways/dom-component-path'
const h1 = document.querySelector('h1')
const path = domComponentPath(h1)
With the following HTML:
<html lang="en">
<body data-sit-component="detail page">
<div id="main">
<div class="module">
<h1>Hello World</h1>
</div>
</div>
</body>
</html>
Yields the following result:
[
{
"name": "Tag: html",
"position": 1
},
{
"name": "Component: detail page",
"position": 1
},
{
"name": "ID: main",
"position": 1
},
{
"name": "Class: module",
"position": 1
},
{
"name": "Tag: h1",
"position": 1
}
]
Running Tests
Tests can be easily run locally as follows:
npm install
npm test