
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
domtosource
Advanced tools
This module wraps around Cheerio and magically calculates the line and column numbers where DOM elements appear in the HTML source code.
This module wraps around Cheerio and magically calculates the line and column number where DOM elements appear in the HTML source code.
var fs = require('fs'),
domtosource = require('domtosource'),
doc = fs.readFileSync('file.html', 'utf8'),
results = domtosource.find(doc, '.green');
In the usage example above, you can see that domtosource.find() takes two parameters.
The HTML source code to search in
The CSS selector to search for
domtosource returns an array containing the elements that matched your selector, and their line and column numbers in the HTML source:
[
{
el: { '0': [Object], length: 1 },
html: '<li class="green">Green <span class="green">test</span></li>',
line: 12,
column: 5,
calculationMethod: 'methodA'
},
{
el: { '0': [Object], length: 1 },
html: '<span class="green">test</span>',
line: 12,
column: 29,
calculationMethod: 'methodA'
},
{
el: { '0': [Object], length: 1 },
html: '<li class="green">Green</li>',
line: 16,
column: 5,
calculationMethod: 'methodB'
},
{
el: { '0': [Object], length: 1 },
html: '<li class="green">Green</li>',
line: 17,
column: 5,
calculationMethod: 'methodB'
}
]
The calculationMethod return value indicates which method was used to calculate the line and column number. This is returned for unit test purposes because some methods are faster than others, but only work in certain situations. It is not something you need to worry about as a user.
FAQs
This module wraps around Cheerio and magically calculates the line and column numbers where DOM elements appear in the HTML source code.
The npm package domtosource receives a total of 21 weekly downloads. As such, domtosource popularity was classified as not popular.
We found that domtosource demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.