.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / style-search / README.md
1 # style-search [![CircleCI](https://circleci.com/gh/davidtheclark/style-search.svg?style=svg)](https://circleci.com/gh/davidtheclark/style-search)
2
3 Search CSS (and CSS-like) strings, with sensitivity to whether matches occur inside strings, comments, and functions.
4
5 ## Usage
6
7 ```js
8 var styleSearch = require('style-search');
9
10 styleSearch(options, callback);
11 ```
12
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`.
14
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).
16
17 ### Example
18
19 ```css
20 /* Here is some pink */
21 a { color: pink; }
22 a::before { content: "pink" }
23 b { color: shadesOfPink(7); }
24 ```
25
26 ```js
27 styleSearch({
28   source: theCssStringAbove,
29   target: "pink",
30 }, function(match, count) {
31   /* Only the "pink" in `color: pink` will be
32   reported as a match */
33 });
34 ```
35
36 ### Reporting matches
37
38 For every match found your `callback` is invoked. It is passed two arguments:
39
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.
48
49 ### Options
50
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.
52
53 #### source
54
55 String. *Required.*
56
57 The source string to search through.
58
59 #### target
60
61 String or array of strings. *Required.*
62
63 The target of the search. Can be
64 - a single character
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)
67
68 #### once
69
70 Boolean. Default: `false`.
71
72 If `true`, the search will stop after one match is found.
73
74 #### comments
75
76 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
77
78 This includes both standard `/* CSS comments */` and non-standard but widely used `// single line comments`.
79
80 #### strings
81
82 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
83
84 #### functionNames
85
86 `"skip"` | `"check"` | `"only"`. Default: `"skip"`.
87
88 #### functionArguments
89
90 `"skip"` | `"check"` | `"only"`. Default: `"check"`.
91
92 #### parentheticals
93
94 `"skip"` | `"check"` | `"only"`. Default: `"check"`.
95
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`.