Comparing version 2.5.0 to 2.6.0
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392426
28
7816