Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #38 from useparcel/codsen-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
avigoldman authored Dec 10, 2020
2 parents 5677d80 + a378f5b commit 87a9872
Show file tree
Hide file tree
Showing 36 changed files with 2,125 additions and 609 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 2
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"url": "^0.11.0",
"util": "^0.12.3",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0"
"webpack-cli": "^4.1.0",
"webpack-node-externals": "^2.5.2"
},
"eslintConfig": {
"parser": "@babel/eslint-parser",
Expand Down
44 changes: 44 additions & 0 deletions packages/css-select-codsen-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# css-select-codsen-parser

An adapter for [`css-select`](https://www.npmjs.com/package/css-select) to allow querying of [`codsen-parser`](https://www.npmjs.com/package/codsen-parser) generated trees.

## Install

```
$ npm install css-select-codsen-parser
```

## Usage

To use this adapter, first you must run the AST through `prepare`.

```js
const parse = require("codsen-parser");
const CSSselect = require("css-select");
const { prepare, adapter } = require("css-select-codsen-parser");

const ast = prepare(
parse(`
<div id="greeting">
Hello <span class="name">Alice</span>
</div>
`)
);

const nodes = cssSelect("#greeting .name", ast, { adapter });
// => [ { type: 'tag', start: 37, end: 56, value: '<span class="name">'... ]
```

## API

## prepare(ast)

**Note:** This method modifies the AST directly.

Accepts an AST generated by [`codsen-parser`](https://www.npmjs.com/package/codsen-parser).

Returns the same AST.

## adapter

[`css-select`](https://www.npmjs.com/package/css-select) adapter. See [documentation](https://github.com/fb55/css-select#options) on how to use a custom adapter.
Loading

0 comments on commit 87a9872

Please sign in to comment.