New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

css-query

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-query

A simple parser that allows querying of CSS values in a stylesheet.

  • 1.0.0-fix
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

css-query NPM version

A simple parser that allows querying of CSS values in a stylesheet.

Why?

I needed to parse values off a CSS stylesheet in a personal project, so I created this because I didn't find anything that did this.

Example

Warning:
Currently it's only possible to query for a selector that's actually present in the CSS since there isn't any matching functionality present yet.

That's why a random selector like html body #foo.active:hover isn't going to work if you don't specifically define a selector like that.


style.css:

#foo {
	color: red;
	font-size: 20px;
}

#foo.active {
	color: green !important;
}

index.js:

const cssQuery = require('css-query');

cssQuery.forFile('style.css')
	.then(query => {
		const color = query.query({
			selector: '#foo.active',
			property: 'color'
		}).value

		console.log(`The element's color is: ${color}`)
	})

Output:

The element's color is: green

To do

I won't be actively working on this, but there's still some stuff that should get added to this over time.

  • Getting this to work with @media queries
  • Generic selector matching, so that it's less like selecting the key from a JSON and more like "I have 'span.foo', which styles do I get for it in this stylesheet?"

Contributing

I'll gladly appreciate any contribution on this package!

Keywords

FAQs

Package last updated on 28 Sep 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc