npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

style-search

v0.1.0

Published

Search CSS(-like) strings

Downloads

10,268,717

Readme

style-search CircleCI

Search CSS (and CSS-like) strings, with sensitivity to whether matches occur inside strings, comments, and functions.

Usage

var styleSearch = require('style-search');

styleSearch(options, callback);

By default, the search ignores strings, comments, and function names. You can use the options to change this behavior or introduce other restrictions. That is what makes this module more useful for many searches than indexOf() or a RegExp.

However, if you need more detailed parsing, you should consider using the real parsers PostCSS, postcss-selector-parser, and postcss-value-parser.

Example

/* Here is some pink */
a { color: pink; }
a::before { content: "pink" }
b { color: shadesOfPink(7); }
styleSearch({
  source: theCssStringAbove,
  target: "pink",
}, function(match, count) {
  /* Only the "pink" in `color: pink` will be
  reported as a match */
});

Reporting matches

For every match found your callback is invoked. It is passed two arguments:

  • A match object with the following properties:
    • startIndex: where the match begins
    • endIndex: where the match ends
    • target: what got matched (useful if your target option is an array instead of a single string)
    • insideFunctionArguments: whether the match is inside a function — this includes the parentheses around the arguments
    • insideComment: whether the match is inside a comment
    • insideString: whether the match is inside a string
  • The count of how many matches have been found up to this point.

Options

Below you'll see that syntax feature options all accept three keywords: "skip", "check", "only". An error will be thrown if you use "only" more than once.

source

String. Required.

The source string to search through.

target

String or array of strings. Required.

The target of the search. Can be

  • a single character
  • a string with some length
  • an array of strings, all of which count as matches (the match object passed to the callback will differentiate which string in the array got matched via its target property)

once

Boolean. Default: false.

If true, the search will stop after one match is found.

comments

"skip" | "check" | "only". Default: "skip".

This includes both standard /* CSS comments */ and non-standard but widely used // single line comments.

strings

"skip" | "check" | "only". Default: "skip".

functionNames

"skip" | "check" | "only". Default: "skip".

functionArguments

"skip" | "check" | "only". Default: "check".

parentheticals

"skip" | "check" | "only". Default: "check".

This designates anything inside parentheses, which includes standard functions, but also Sass maps and other non-standard constructs. parentheticals is a broader category than functionArguments.