1
1
# Modern JavaScript Snippets ⚡
2
2
3
- > Short and memorable JavaScript & TypeScript snippets for the modern-day developer.
3
+ > Short and memorable JavaScript & TypeScript snippets for the modern-day developer.
4
4
5
5
<br >
6
6
7
- 🚧 * Still a work in progress. Some snippets may be changed and more will be added.*
7
+ ![ JavaScript] ( https://img.shields.io/badge/javascript-%23F7DF1C.svg?style=for-the-badge&logo=javascript&logoColor=%23323330 )
8
+ ![ TypeScript] ( https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white )
9
+
8
10
9
11
## Features
10
- - Contains over ** 180** snippets
12
+ - Over ** 180** carefully crafted snippets
11
13
- Modern JavaScript syntax
14
+ - Modern JavaScript APIs (Intl, URL, Navigator...)
12
15
- Strategically placed tabstops
16
+ - Prefixes created with exact-match in mind
17
+ - (Mostly) GitHub Copilot compliant
13
18
- Auto-generated documentation
14
- - ...
15
-
16
- <br >
17
-
18
- ![ JavaScript] ( https://img.shields.io/badge/javascript-%23F7DF1C.svg?style=for-the-badge&logo=javascript&logoColor=%23323330 )
19
- ![ TypeScript] ( https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white )
20
19
21
20
## Support
22
21
Only JavaScript and TypeScript will be supported.
23
22
Specific frameworks will get their own extensions. No bloat.
24
23
25
- Supported file extensions:
26
- - ` .js `
27
- - ` .ts `
28
- - ` .jsx `
29
- - ` .tsx `
30
-
31
24
## Setup
32
- The following is not mandatory, but could provide a nicer experience.
25
+ The following is not mandatory, but could provide a nicer experience. Test them out and see what works best for you.
33
26
34
- Search for ` editor.tabCompletion ` in user settings, or edit the settings.json directly:
27
+ Look for it in user settings, or edit the settings.json directly:
35
28
``` jsonc
36
29
// Tab complete snippets when their prefix match. Works best when 'quickSuggestions' aren't enabled.
37
30
" editor.tabCompletion" : " onlySnippets"
31
+
32
+ // Controls whether an active snippet prevents quick suggestions.
33
+ // "editor.suggest.snippetsPreventQuickSuggestions": false,
38
34
```
39
35
40
36
## Style
41
- Most of the code snippets are without semicolons (` ; ` ), except for where it allows for better tabstop management.
37
+ Most of the code snippets are without semicolons (` ; ` ), except for where it allows for better tabstop management. String use single quotes ( ` ' ` ).
42
38
43
39
It's highly recommended to use these snippets along with Prettier/ESLint to have your code automatically formatted to your preference.
44
40
45
41
## Snippet syntax
46
42
47
43
### Tabstops
48
- - With tabstops you can make the editor cursor move inside a snippet
49
44
- ` $1 ` , ` $2 ` , ` $3 ` specify cursor locations, in order in which tabstops will be visited
50
45
- ` $0 ` denotes the final cursor position
51
46
- Multiple occurrences of the same tabstop are linked and updated in sync
52
47
53
48
### Placeholders
54
- - Placeholders are tabstops with values, such as ` ${1:name} `
55
- - Placeholder text will be inserted and selected such that it can be easily changed
56
- - Can be nested, like ` ${1:another ${2:placeholder}} `
49
+ - Tabstops with default values, such as ` ${1:name} `
50
+
51
+ ### Choices
52
+ - Tabstops with multiple values, such as ` ${1|one,two,three|} ` .
53
+ - Truncated in documentation, for easier viewing.
57
54
58
55
<!-- START:docs-gen -->
59
56
## Snippets
@@ -292,7 +289,7 @@ $1 ? $2 : $3
292
289
<td >
293
290
294
291
``` javascript
295
- const $ {1: name } = $2 ? $3 : $4
292
+ const $1 = $2 ? $3 : $4
296
293
```
297
294
298
295
</td >
@@ -314,7 +311,7 @@ switch ($1) {
314
311
</tr >
315
312
316
313
<tr >
317
- <td ><code >cas </code ></td >
314
+ <td ><code >case </code ></td >
318
315
<td >case</td >
319
316
<td >
320
317
@@ -1138,6 +1135,18 @@ export const ${1:name} = ($2) => {$0}
1138
1135
<td >Body</td >
1139
1136
</tr >
1140
1137
1138
+ <tr >
1139
+ <td ><code >aat</code ></td >
1140
+ <td >array.at</td >
1141
+ <td >
1142
+
1143
+ ``` javascript
1144
+ $1 .at (${2 : 0 })
1145
+ ```
1146
+
1147
+ </td >
1148
+ </tr >
1149
+
1141
1150
<tr >
1142
1151
<td ><code >fe</code ></td >
1143
1152
<td >Array.forEach()</td >
@@ -2126,7 +2135,7 @@ const ${1} = require('${1:module}');
2126
2135
<td>
2127
2136
2128
2137
` ` ` javascript
2129
- describe (' ${1:description} ' , () => {
2138
+ describe (' $1 ' , () => {
2130
2139
$0
2131
2140
})
2132
2141
` ` `
@@ -2140,7 +2149,7 @@ describe('${1:description}', () => {
2140
2149
<td>
2141
2150
2142
2151
` ` ` javascript
2143
- context (' ${1:description} ' , () => {
2152
+ context (' $1 ' , () => {
2144
2153
$0
2145
2154
})
2146
2155
` ` `
@@ -2154,7 +2163,7 @@ context('${1:description}', () => {
2154
2163
<td>
2155
2164
2156
2165
` ` ` javascript
2157
- it (' ${1:description} ' , () => {
2166
+ it (' $1 ' , () => {
2158
2167
$0
2159
2168
})
2160
2169
` ` `
@@ -2168,7 +2177,7 @@ it('${1:description}', () => {
2168
2177
<td>
2169
2178
2170
2179
` ` ` javascript
2171
- it (' ${1:description} ' , async () => {
2180
+ it (' $1 ' , async () => {
2172
2181
$0
2173
2182
})
2174
2183
` ` `
@@ -2182,7 +2191,7 @@ it('${1:description}', async () => {
2182
2191
<td>
2183
2192
2184
2193
` ` ` javascript
2185
- it (' ${1:description} ' , (done ) => {
2194
+ it (' $1 ' , (done ) => {
2186
2195
$0
2187
2196
done ()
2188
2197
})
@@ -2532,18 +2541,6 @@ Will be sorted into appropriate categories in the future.
2532
2541
<td>Body</td>
2533
2542
</tr>
2534
2543
2535
- <tr>
2536
- <td><code>aat</code></td>
2537
- <td>array.at</td>
2538
- <td>
2539
-
2540
- ` ` ` javascript
2541
- $1 .at (${2 : 0 })
2542
- ` ` `
2543
-
2544
- </td>
2545
- </tr>
2546
-
2547
2544
<tr>
2548
2545
<td><code>am</code></td>
2549
2546
<td>array merge</td>
@@ -2622,7 +2619,67 @@ parseFloat($1)
2622
2619
<td>
2623
2620
2624
2621
` ` ` javascript
2625
- throw new $ {1 | Error ,... | }($0);
2622
+ throw new $ {1 | Error ,... | }($0)
2623
+ ` ` `
2624
+
2625
+ </td>
2626
+ </tr>
2627
+
2628
+ <tr>
2629
+ <td><code>cp</code></td>
2630
+ <td>copy to clipboard</td>
2631
+ <td>
2632
+
2633
+ ` ` ` javascript
2634
+ navigator .clipboard .writeText ($1);
2635
+ ` ` `
2636
+
2637
+ </td>
2638
+ </tr>
2639
+
2640
+ <tr>
2641
+ <td><code>nur</code></td>
2642
+ <td>new URL</td>
2643
+ <td>
2644
+
2645
+ ` ` ` javascript
2646
+ new URL ($1)
2647
+ ` ` `
2648
+
2649
+ </td>
2650
+ </tr>
2651
+
2652
+ <tr>
2653
+ <td><code>usp</code></td>
2654
+ <td>url search params</td>
2655
+ <td>
2656
+
2657
+ ` ` ` javascript
2658
+ new URL ($1).searchParams
2659
+ ` ` `
2660
+
2661
+ </td>
2662
+ </tr>
2663
+
2664
+ <tr>
2665
+ <td><code>spg</code></td>
2666
+ <td>get search param</td>
2667
+ <td>
2668
+
2669
+ ` ` ` javascript
2670
+ $1 .searchParams .get ($2)
2671
+ ` ` `
2672
+
2673
+ </td>
2674
+ </tr>
2675
+
2676
+ <tr>
2677
+ <td><code>sps</code></td>
2678
+ <td>set search param</td>
2679
+ <td>
2680
+
2681
+ ` ` ` javascript
2682
+ $1 .searchParams .set ($2, $3)
2626
2683
` ` `
2627
2684
2628
2685
</td>
@@ -2631,7 +2688,7 @@ throw new ${1|Error,...|}($0);
2631
2688
2632
2689
2633
2690
## TypeScript
2634
- Available only in .ts and .tsx files
2691
+ Available only where TypeScript is supported
2635
2692
2636
2693
### Declarations
2637
2694
@@ -2649,7 +2706,7 @@ Available only in .ts and .tsx files
2649
2706
<td>
2650
2707
2651
2708
` ` ` javascript
2652
- const $1: $ {2:string } = $3
2709
+ const $1: $ {2:string } = $3;
2653
2710
` ` `
2654
2711
2655
2712
</td>
@@ -2661,7 +2718,7 @@ const $1: ${2:string} = $3
2661
2718
<td>
2662
2719
2663
2720
` ` ` javascript
2664
- let $1: ${2 : string} = $3
2721
+ let $1: ${2 : string} = $3;
2665
2722
` ` `
2666
2723
2667
2724
</td>
@@ -2673,7 +2730,7 @@ let $1: ${2:string} = $3
2673
2730
<td>
2674
2731
2675
2732
` ` ` javascript
2676
- const $1: $ {2:string }[] = [$0]
2733
+ const $1: $ {2:string }[] = [$0];
2677
2734
` ` `
2678
2735
2679
2736
</td>
@@ -2685,7 +2742,7 @@ const $1: ${2:string}[] = [$0]
2685
2742
<td>
2686
2743
2687
2744
` ` ` javascript
2688
- const $1: $ {2:object } = { $0 }
2745
+ const $1: $ {2:object } = { $0 };
2689
2746
` ` `
2690
2747
2691
2748
</td>
@@ -2769,7 +2826,6 @@ type ${1:Model} = $2 & $3
2769
2826
2770
2827
<!-- END:docs-gen -->
2771
2828
2772
- ---
2773
2829
## Running locally
2774
2830
2775
2831
` ` ` bash
0 commit comments