Socket
Socket
Sign inDemoInstall

@ryanmorr/parselector

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ryanmorr/parselector

Parse a CSS selector string


Version published
Weekly downloads
11
decreased by-31.25%
Maintainers
1
Install size
9.23 kB
Created
Weekly downloads
 

Readme

Source

parselector

Version Badge License Build Status

Parse a CSS selector string

Install

Download the CJS, ESM, UMD versions or install via NPM:

npm install @ryanmorr/parselector

Usage

Provide a selector string and get a two-dimensional array composed of each selector group in the first array and the tokens for a selector sequence in the second array.

import parselector from '@ryanmorr/parselector';

parselector('#foo[attr$="value" i] > div:not(.bar), .baz span::before');

Generates the following AST structure:

[
    [
        {
            nodeName: null,
            attributes: [
                {
                    name: 'id',
                    operator: '=',
                    value: 'foo',
                    ignoreCase: false
                },
                {
                    name: 'attr',
                    operator: '$=',
                    value: 'value',
                    ignoreCase: true
                }
            ],
            pseudoClasses: [],
            pseudoElement: null
        },
        '>',
        {
            nodeName: 'div',
            attributes: [],
            pseudoClasses: [
                {
                    name: 'not',
                    value: '.bar'
                }
            ],
            pseudoElement: null
        }
    ],
    [
        {
            nodeName: null,
            attributes: [
                {
                    name: 'class',
                    operator: '~=',
                    value: 'baz',
                    ignoreCase: false
                }
            ],
            pseudoClasses: [],
            pseudoElement: null
        },
        ' ',
        {
            nodeName: 'span',
            attributes: [],
            pseudoClasses: [],
            pseudoElement: 'before'
        }
    ]
]

License

This project is dedicated to the public domain as described by the Unlicense.

Keywords

FAQs

Last updated on 18 Mar 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc