hast-util-parse-selector
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

hast-util-parse-selector Build Status Coverage Status

Parse a simple CSS selector to a HAST node.

Installation

npm:

npm install hast-util-parse-selector

hast-util-parse-selector is also available as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

Dependencies:

var parseSelector = require('hast-util-parse-selector');

Parse:

var node = parseSelector('.quux#bar.baz.qux');

Yields:

{
  "type": "element",
  "tagName": "div",
  "properties": {
    "id": "bar",
    "className": [
      "quux",
      "baz",
      "qux"
    ]
  },
  "children": []
}

API

parseSelector([selector])

Parse a CSS selector to a HAST node.

selector (string, optional). Can contain a tag-name (foo), classes (.bar), and an ID (#baz). Multiple classes are allowed. Uses the last ID if multiple IDs are found.

Returns: Node — A HAST node.

License

MIT © Titus Wormer

Package Sidebar

Install

npm i hast-util-parse-selector@2.0.0

Version

2.0.0

License

MIT

Last publish

Collaborators

  • wooorm
  • kmck