GithubHelp home page GithubHelp logo

css-what's Introduction

css-what Build Status

a CSS selector parser

Example

const CSSwhat = require("css-what")
CSSwhat.parse("foo[bar]:baz")

~> [
    [
        { type: "tag", name: "foo" },
        {
            type: "attribute",
            name: "bar",
            action: "exists",
            value: "",
            ignoreCase: false
        },
        { type: "pseudo", name: "baz", data: null }
    ]
]

API

CSSwhat.parse(str, options) - Parses str, optionally with the passed options.

The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. sub1, sub2), the second contains the relevant tokens for that selector. Possible token types are:

name attributes example output
tag name div { type: 'tag', name: 'div' }
universal - * { type: 'universal' }
pseudo name, data :name(data) { type: 'pseudo', name: 'name', data: 'data' }
pseudo name, data :name { type: 'pseudo', name: 'name', data: null }
pseudo-element name ::name { type: 'pseudo-element', name: 'name' }
attribute name, action, value, ignoreCase [attr] { type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }
attribute name, action, value, ignoreCase [attr=val] { type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr^=val] { type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr$=val] { type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }
child - > { type: 'child' }
parent - < { type: 'parent' }
sibling - ~ { type: 'sibling' }
adjacent - + { type: 'adjacent' }
descendant - { type: 'descendant' }

Options:

  • lowerCaseTags: When false, tag names will not be lowercased. Defaults to true.
  • lowerCaseAttributeNames: When false, attribute names will not be lowercased. Defaults to true.
  • xmlMode: When true, xmlMode implies both lowerCaseTags and lowerCaseAttributeNames are set to false.

CSSwhat.stringify(selector) - Turns selector back into a string.


License: BSD-2-Clause

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

css-what for enterprise

Available as part of the Tidelift Subscription

The maintainers of css-what and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

css-what's People

Contributors

chocolateboy avatar churkin avatar dependabot-preview[bot] avatar dshadrick avatar eightarmcode avatar fb55 avatar ganeshv avatar jspri avatar kevva avatar kpdecker avatar mathew-kurian avatar phated avatar ryuugan avatar shinnn avatar slaks avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.