UNPKG

6.13 kBMarkdownView Raw
1<div align="center">
2 <br>
3 <img src=".github/vue-grep.png" height="100px">
4</div>
5
6<div align="center">
7 <em>Grep your Vue.js codebase with CSS selectors</em>
8 <br>
9
10 <a href="https://npm.im/vue-grep"><img src="https://badgen.net/npm/v/vue-grep"></a>
11 <a href="https://npm.im/vue-grep"><img src="https://badgen.net/npm/dm/vue-grep"></a>
12 <a href="https://packagephobia.now.sh/result?p=vue-grep"><img src="https://packagephobia.now.sh/badge?p=vue-grep"></a>
13 <a href="https://bundlephobia.com/result?p=vue-grep"><img src="https://badgen.net/bundlephobia/minzip/vue-grep"></a>
14</div>
15
16Have you ever wanted to [grep](https://phoenixnap.com/kb/grep-command-linux-unix-examples) your Vue.js codebase for something specific, like a combination of tags and attributes? Only to realize that you can't because attributes can span multiple lines and be in arbitrary order.
17
18**vue-grep** is a command-line tool that lets you search your Vue.js codebase using CSS selector syntax (like [`querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors) or jQuery) — essential for navigating large codebases! 🔥
19
20<div align="center">
21 <img src=".github/screenshot.png" width="70%">
22</div>
23
24<sub>If you like this project, please star it & [follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub>
25
26## 🚀 Install
27```sh
28$ npm i -g vue-grep
29```
30
31Alternatively, use [npx](https://nodejs.dev/learn/the-npx-nodejs-package-runner) to run it without installation:
32```
33$ npx vue-grep
34```
35
36## 👨‍🏫 Usage
37
38```sh
39$ vue-grep <query> [path/glob ...]
40```
41
42#### Tips
43
44- _Recommended to pass the query in with single-quotes to prevent [accidental interpolation](https://stackoverflow.com/a/6697781)_
45
46 eg. `$ vue-grep '[v-bind="$attrs"]'`
47
48- _If passing in a glob, specify the `.vue` extension. (eg. `**/*.vue`)_
49
50### Options
51#### -l, --files-with-matches
52Only print the paths with at least one match.
53#### -s, --show-children
54Show the children of matching elements. Defaults to being collapsed.
55
56#### --exclude-directory
57Directory names to exclude on non-glob searches. (Default: `node_modules`, `vendor`, `public`, `dist`)
58
59#### --hidden
60Search hidden files and directories.
61
62## 🌟 Query features
63### Standard selectors
64- [`tag-name`](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors) - Type selector
65- [`.class-name`](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) - Class selector
66- [`#identifier`](https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors) - ID selector
67- [Attribute selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors)
68 - `[attribute-name]` - Existence
69 - `[attribute-name="value"]`/`[attribute-name!="value"]` - Equality
70 - `[attribute-name=/pattern/]`/`[attribute-name!=/pattern/]` - Regular expression matching
71
72- Pseudo-classes
73 - [`:empty`](https://developer.mozilla.org/en-US/docs/Web/CSS/:empty) - Elements with no children
74 - [`:first-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child) - First child amongst siblings
75 - [`:last-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child) - Last child amongst siblings
76 - [`:nth-child(n)`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child) - _n_ th child amongst siblings
77 - [`:nth-last-child(n)`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-child) - _n_ th child from bottom amongst siblings
78 - [`:not(query)`](https://developer.mozilla.org/en-US/docs/Web/CSS/:not) - Query negation
79
80- Combinators
81 - [`parent child`](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator) - Descendant
82 - [`parent > immediate-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator) - Immediate child
83 - [`element ~ general-sibling`](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator) - General sibling
84 - [`element + adjacent-sibling`](https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator) - Adjacent sibling
85
86### Non-standard selectors
87- Directive selector
88 - `[v-directive]` - Existence
89 - `[v-directive:argument]` - Existence with argument
90 - `[v-directive:argument.modifier]` - Existence with argument and modifier
91 - `[v-directive="value"]`/`[v-directive!="value"]` - Equality
92 - `[v-directive=/pattern/]`/`[v-directive!=/pattern/]` - Regular expression matching
93 - Directive shorthands
94 - `[:prop]`/`[:prop="value"]`/`[:prop=/pattern/]` - Prop
95 - `[@event]`/`[@event="value"]`/`[@event=/pattern/]` - Event-listener
96 - `[#slot]`/`[#slot="value"]`/`[#slot=/pattern/]` - Slot
97- Pseudo-classes
98 - `:contains("text")` - Element that contains string
99 - `:contains(/pattern/)` - Element that contains string that matches regular expression
100
101## ⚡️ Example queries
102All examples are searching the current working directory.
103
104#### Find elements with class `button` and `primary`
105```sh
106$ vue-grep '.button.primary'
107```
108
109The class selector can parse and test against dynamic classes aslong as it's simple (eg. no run-time evaluations). For matching complex class directives, consider using regular expression matching.
110
111#### Find `button` elements with the `@click.stop` listener
112```sh
113$ vue-grep 'button[@click.stop]'
114```
115
116#### Find radio `input` elements with a `disabled` prop
117```sh
118$ vue-grep 'input[type="radio"][:disabled]'
119```
120
121#### Find `div` elements with `v-if`
122```sh
123$ vue-grep 'div[v-if]'
124```
125
126#### Find empty elements
127```sh
128$ vue-grep ':empty'
129```
130
131#### Find elements that contain strings that match regular expression `/hello world/`
132```sh
133$ vue-grep ':contains(/hello world/)'
134```
135
136### Don't see your favorite use-cases?
137[Add it in](https://github.com/privatenumber/vue-grep/edit/develop/README.md)! We'd love to see how you're using it.
138
139## 🙋‍♀️ Need help?
140If you have a question about usage, [ask on Discussions](https://github.com/privatenumber/vue-grep/discussions).
141
142If you'd like to make a feature request or file a bug report, [open an Issue](https://github.com/privatenumber/vue-grep/issues).