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

astq

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astq - npm Package Compare versions

Comparing version 2.5.0 to 2.6.0

src/astq-adapter-cheerio.js

2

package.json
{
"name": "astq",
"version": "2.5.0",
"version": "2.6.0",
"description": "Abstract Syntax Tree (AST) Query Engine",

@@ -5,0 +5,0 @@ "keywords": [ "abstract", "syntax", "tree", "query", "engine", "adaptable" ],

@@ -303,3 +303,3 @@

duck-typed interface. See below for more information.
By default ASTq has built-in adapters for ASTy, XML DOM, Parse5 and Mozilla AST.
By default ASTq has built-in adapters for ASTy, XML DOM, Parse5, Cheerio, JSON and Mozilla AST.
All those "taste" the node passed to `ASTQ#query` and hence are auto-selected.

@@ -306,0 +306,0 @@ Calling `adapter()` causes these to be replaced with a single custom adapter.

@@ -8,3 +8,4 @@ {

"xmldom": "0.1.27",
"less": "3.9.0"
"less": "3.9.0",
"cheerio": "1.0.0-rc.2"
},

@@ -11,0 +12,0 @@ "scripts": {

@@ -106,1 +106,36 @@

/* query HTML source-code */
(() => {
let source = `
<html>
<head>
<title>Foo</title>
</head>
<body>
<h1>Bar <i>Baz</i></h1>
Sample
<h2>Bar</h2>
Sample
<h3>Quux</h3>
Sample
</body>
</html>
`
const cheerio = require("cheerio")
let $ = cheerio.load(source)
let ast = $.root()[0]
let astq = new ASTQ()
astq.adapter("cheerio")
astq.query(ast, `
/* query all headlines */
// * [
type() =~ \`^h[1-9]$\`
&& // "#text"
]
`).forEach((node) => {
let tag = node.tagName
let value = astq.query(node, `// "#text"`).map((node) => node.nodeValue).join("")
console.log(`FOUND PARSE5: tag: ${tag}, value: ${value}`)
})
})();

@@ -35,2 +35,3 @@ /*

import ASTQAdapterJSON from "./astq-adapter-json.js"
import ASTQAdapterCHEERIO from "./astq-adapter-cheerio.js"
import ASTQAdapterASTY from "./astq-adapter-asty.js"

@@ -53,2 +54,3 @@ import ASTQFuncs from "./astq-funcs.js"

.register(ASTQAdapterJSON, false)
.register(ASTQAdapterCHEERIO, false)
.register(ASTQAdapterASTY, false)

@@ -86,2 +88,3 @@

else if (adapter === "json") adapter = ASTQAdapterJSON
else if (adapter === "cheerio") adapter = ASTQAdapterCHEERIO
else if (adapter === "asty") adapter = ASTQAdapterASTY

@@ -88,0 +91,0 @@ else

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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