Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

domtosource

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

domtosource

This module wraps around Cheerio and magically calculates the line and column numbers where DOM elements appear in the HTML source code.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-40%
Maintainers
1
Weekly downloads
 
Created
Source

DOM to Source

This module wraps around Cheerio and magically calculates the line and column number where DOM elements appear in the HTML source code.

Usage

var fs = require('fs'),
  domtosource = require('domtosource'),
  doc = fs.readFileSync('file.html', 'utf8'),
  results = domtosource.find(doc, '.green', true);

Inputs

In the usage example above, you can see that domtosource.find() takes three parameters.

  1. The HTML source code to search in

  2. The CSS selector to search for

  3. true if you want to calculate the line and column numbers

Return values

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 calculation method return value indicates which method was used to calculate the line and column number. This is used 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.

Keywords

FAQs

Package last updated on 05 Dec 2012

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