11# Modern JavaScript Snippets ⚡
22
3- > Short and memorable JavaScript & TypeScript snippets for the modern-day developer.
3+ > Short and memorable JavaScript & TypeScript snippets for the modern-day developer.
44
55<br >
66
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+
810
911## Features
10- - Contains over ** 180** snippets
12+ - Over ** 180** carefully crafted snippets
1113- Modern JavaScript syntax
14+ - Modern JavaScript APIs (Intl, URL, Navigator...)
1215- Strategically placed tabstops
16+ - Prefixes created with exact-match in mind
17+ - (Mostly) GitHub Copilot compliant
1318- 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 )
2019
2120## Support
2221Only JavaScript and TypeScript will be supported.
2322Specific frameworks will get their own extensions. No bloat.
2423
25- Supported file extensions:
26- - ` .js `
27- - ` .ts `
28- - ` .jsx `
29- - ` .tsx `
30-
3124## 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.
3326
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:
3528``` jsonc
3629// Tab complete snippets when their prefix match. Works best when 'quickSuggestions' aren't enabled.
3730" editor.tabCompletion" : " onlySnippets"
31+
32+ // Controls whether an active snippet prevents quick suggestions.
33+ // "editor.suggest.snippetsPreventQuickSuggestions": false,
3834```
3935
4036## 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 ( ` ' ` ).
4238
4339It's highly recommended to use these snippets along with Prettier/ESLint to have your code automatically formatted to your preference.
4440
4541## Snippet syntax
4642
4743### Tabstops
48- - With tabstops you can make the editor cursor move inside a snippet
4944- ` $1 ` , ` $2 ` , ` $3 ` specify cursor locations, in order in which tabstops will be visited
5045- ` $0 ` denotes the final cursor position
5146- Multiple occurrences of the same tabstop are linked and updated in sync
5247
5348### 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.
5754
5855<!-- START:docs-gen -->
5956## Snippets
@@ -292,7 +289,7 @@ $1 ? $2 : $3
292289<td >
293290
294291 ``` javascript
295- const $ {1: name } = $2 ? $3 : $4
292+ const $1 = $2 ? $3 : $4
296293 ```
297294
298295</td >
@@ -314,7 +311,7 @@ switch ($1) {
314311</tr >
315312
316313<tr >
317- <td ><code >cas </code ></td >
314+ <td ><code >case </code ></td >
318315<td >case</td >
319316<td >
320317
@@ -1138,6 +1135,18 @@ export const ${1:name} = ($2) => {$0}
11381135<td >Body</td >
11391136</tr >
11401137
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+
11411150<tr >
11421151<td ><code >fe</code ></td >
11431152<td >Array.forEach()</td >
@@ -2126,7 +2135,7 @@ const ${1} = require('${1:module}');
21262135<td>
21272136
21282137 ` ` ` javascript
2129- describe (' ${1:description} ' , () => {
2138+ describe (' $1 ' , () => {
21302139 $0
21312140})
21322141 ` ` `
@@ -2140,7 +2149,7 @@ describe('${1:description}', () => {
21402149<td>
21412150
21422151 ` ` ` javascript
2143- context (' ${1:description} ' , () => {
2152+ context (' $1 ' , () => {
21442153 $0
21452154})
21462155 ` ` `
@@ -2154,7 +2163,7 @@ context('${1:description}', () => {
21542163<td>
21552164
21562165 ` ` ` javascript
2157- it (' ${1:description} ' , () => {
2166+ it (' $1 ' , () => {
21582167 $0
21592168})
21602169 ` ` `
@@ -2168,7 +2177,7 @@ it('${1:description}', () => {
21682177<td>
21692178
21702179 ` ` ` javascript
2171- it (' ${1:description} ' , async () => {
2180+ it (' $1 ' , async () => {
21722181 $0
21732182})
21742183 ` ` `
@@ -2182,7 +2191,7 @@ it('${1:description}', async () => {
21822191<td>
21832192
21842193 ` ` ` javascript
2185- it (' ${1:description} ' , (done ) => {
2194+ it (' $1 ' , (done ) => {
21862195 $0
21872196 done ()
21882197})
@@ -2532,18 +2541,6 @@ Will be sorted into appropriate categories in the future.
25322541<td>Body</td>
25332542</tr>
25342543
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-
25472544<tr>
25482545<td><code>am</code></td>
25492546<td>array merge</td>
@@ -2622,7 +2619,67 @@ parseFloat($1)
26222619<td>
26232620
26242621 ` ` ` 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)
26262683 ` ` `
26272684
26282685</td>
@@ -2631,7 +2688,7 @@ throw new ${1|Error,...|}($0);
26312688
26322689
26332690## TypeScript
2634- Available only in .ts and .tsx files
2691+ Available only where TypeScript is supported
26352692
26362693### Declarations
26372694
@@ -2649,7 +2706,7 @@ Available only in .ts and .tsx files
26492706<td>
26502707
26512708 ` ` ` javascript
2652- const $1: $ {2:string } = $3
2709+ const $1: $ {2:string } = $3;
26532710 ` ` `
26542711
26552712</td>
@@ -2661,7 +2718,7 @@ const $1: ${2:string} = $3
26612718<td>
26622719
26632720 ` ` ` javascript
2664- let $1: ${2 : string} = $3
2721+ let $1: ${2 : string} = $3;
26652722 ` ` `
26662723
26672724</td>
@@ -2673,7 +2730,7 @@ let $1: ${2:string} = $3
26732730<td>
26742731
26752732 ` ` ` javascript
2676- const $1: $ {2:string }[] = [$0]
2733+ const $1: $ {2:string }[] = [$0];
26772734 ` ` `
26782735
26792736</td>
@@ -2685,7 +2742,7 @@ const $1: ${2:string}[] = [$0]
26852742<td>
26862743
26872744 ` ` ` javascript
2688- const $1: $ {2:object } = { $0 }
2745+ const $1: $ {2:object } = { $0 };
26892746 ` ` `
26902747
26912748</td>
@@ -2769,7 +2826,6 @@ type ${1:Model} = $2 & $3
27692826
27702827<!-- END:docs-gen -->
27712828
2772- ---
27732829## Running locally
27742830
27752831` ` ` bash
0 commit comments