1 # style-search [![CircleCI](https://circleci.com/gh/davidtheclark/style-search.svg?style=svg)](https://circleci.com/gh/davidtheclark/style-search)
3 Search CSS (and CSS-like) strings, with sensitivity to whether matches occur inside strings, comments, and functions.
8 var styleSearch = require('style-search');
10 styleSearch(options, callback);
13 **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`.
15 However, if you need more detailed parsing, you should consider using the real parsers [PostCSS](https://github.com/postcss/postcss), [`postcss-selector-parser`](https://github.com/postcss/postcss-selector-parser), and [`postcss-value-parser`](https://github.com/TrySound/postcss-value-parser).
20 /* Here is some pink */
22 a::before { content: "pink" }
23 b { color: shadesOfPink(7); }
28 source: theCssStringAbove,
30 }, function(match, count) {
31 /* Only the "pink" in `color: pink` will be
32 reported as a match */
38 For every match found your `callback` is invoked. It is passed two arguments:
40 - A `match` object with the following properties:
41 - `startIndex`: where the match begins
42 - `endIndex`: where the match ends
43 - `target`: what got matched (useful if your `target` option is an array instead of a single string)
44 - `insideFunctionArguments`: whether the match is inside a function — *this includes the parentheses around the arguments*
45 - `insideComment`: whether the match is inside a comment
46 - `insideString`: whether the match is inside a string
47 - The count of how many matches have been found up to this point.
51 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.
57 The source string to search through.
61 String or array of strings. *Required.*
63 The target of the search. Can be
65 - a string with some length
66 - 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)
70 Boolean. Default: `false`.
72 If `true`, the search will stop after one match is found.
76 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
78 This includes both standard `/* CSS comments */` and non-standard but widely used `// single line comments`.
82 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
86 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
88 #### functionArguments
90 `"skip"` | `"check"` | `"only"`. Default: `"check"`.
94 `"skip"` | `"check"` | `"only"`. Default: `"check"`.
96 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`.