Skip to content

Commit b81942a

Browse files
committed
Add more snippets and documentation, bump to 0.0.9
1 parent ec16586 commit b81942a

File tree

4 files changed

+198
-44
lines changed

4 files changed

+198
-44
lines changed

README.md

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Search for `editor.snippetSuggestions` and `editor.snippetSuggestions` in user s
3333
"editor.snippetSuggestions": "top",
3434

3535
// Tab complete will insert the best matching suggestion when pressing tab.
36-
"editor.snippetSuggestions": "on"
36+
"editor.tabCompletion": "on"
3737
```
3838

3939
## Style
@@ -109,21 +109,15 @@ const { $2 } = ${1:object}
109109
const [$2] = ${1:array}
110110
```
111111

112-
### Class
112+
### Classes
113+
113114
#### `cs`   -   class
114115
```js
115116
class ${1:Class} {
116117
$0
117118
}
118119
```
119120

120-
#### `cse`   -   class extends
121-
```js
122-
class ${1:Class} extends ${2:Base} {
123-
$0
124-
}
125-
```
126-
127121
#### `csc`   -   class with constructor
128122
```js
129123
class ${1:Class} {
@@ -133,7 +127,14 @@ class ${1:Class} {
133127
}
134128
```
135129

136-
#### `csce`   -   class with constructor
130+
#### `cse`   -   class extends
131+
```js
132+
class ${1:Class} extends ${2:Base} {
133+
$0
134+
}
135+
```
136+
137+
#### `csce`   -   class extends with constructor
137138
```js
138139
class ${1:Class} extends ${2:Base} {
139140
constructor($3) {
@@ -142,7 +143,15 @@ class ${1:Class} extends ${2:Base} {
142143
}
143144
```
144145

145-
### Function
146+
#### `met`   -   method
147+
```js
148+
${1:name}($2) {
149+
$0
150+
}
151+
```
152+
153+
### Functions
154+
146155
#### `fn`   -   function
147156
```js
148157
function ${1:name}($2) {,
@@ -179,13 +188,6 @@ export const ${1:name} = ($2) => {$0}
179188
}
180189
```
181190

182-
#### `met`   -   method
183-
```js
184-
${1:name}($2) {
185-
$0
186-
}
187-
```
188-
189191
### Console
190192

191193
#### `cl`   -   console.log
@@ -203,6 +205,11 @@ console.log('$0')
203205
console.log({ $0 })
204206
```
205207

208+
#### `clc`   -   console.log from clipboard
209+
```js
210+
console.log({ $CLIPBOARD })
211+
```
212+
206213
#### `ce`   -   console.error
207214
```js
208215
console.error($0)
@@ -233,4 +240,84 @@ console.error('$1 ->', ${2:$1})
233240
console.warn('$1 ->', ${2:$1})
234241
```
235242

243+
### Misc
244+
245+
#### `ce`   -   fetch
246+
```js
247+
fetch('$1').then(res => res.json())
248+
```
249+
250+
#### `fea`   -   const assignment fetch
251+
```js
252+
const ${2|data,{ data }|} = await fetch('$1').then(res => res.json())
253+
```
254+
255+
#### `si`   -   set interval
256+
```js
257+
setInterval(() => {
258+
$0
259+
}, ${1:delay})
260+
```
261+
262+
#### `st`   -   set timeout
263+
```js
264+
setTimeout(() => {
265+
$0
266+
}, ${1:delay})
267+
```
268+
269+
### Imports
270+
271+
#### `im`   -   import
272+
```js
273+
import { $2 } from '$1'
274+
```
275+
276+
#### `imd`   -   import default
277+
```js
278+
import $2 from '$1'
279+
```
280+
281+
#### `imda`   -   import all as
282+
```js
283+
import * as $2 from '$1'
284+
```
285+
286+
#### `ex`   -   export from
287+
```js
288+
export { $2 } from '$1'
289+
```
290+
291+
#### `exa`   -   export all from
292+
```js
293+
export * from '$1'
294+
```
295+
296+
#### `exd`   -   export default
297+
```js
298+
export default $0
299+
```
300+
301+
### Object
302+
303+
#### `oe`   -   Object.entries
304+
```js
305+
Object.entries(${0:iterable})
306+
```
307+
308+
#### `ofe`   -   Object.fromEntries
309+
```js
310+
Object.fromEntries(${0:iterable})
311+
```
312+
313+
#### `ok`   -   Object.keys
314+
```js
315+
Object.keys(${0:iterable})
316+
```
317+
318+
#### `ov`   -   Object.values
319+
```js
320+
Object.values(${0:iterable})
321+
```
322+
236323
*...and many more (evertyhing will be documented)*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "modern-js-snippets",
33
"displayName": "Modern JavaScript Snippets ⚡",
4-
"version": "0.0.8",
4+
"version": "0.0.9",
55
"license": "MIT",
66
"description": "Code snippets for modern JavaScript & TypeScript",
77
"icon": "assets/icon.png",

snippets/js.code-snippets

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,32 +245,32 @@
245245
"console.table ⚡": {
246246
"prefix": "ct",
247247
"body": [
248-
"ckonsole.table($1)"
248+
"console.table($1)"
249249
],
250250
"description": ""
251251
},
252252
"native fetch ⚡": {
253-
"prefix": "fetch",
253+
"prefix": "fe",
254254
"body": [
255255
"fetch('$1').then(res => res.json())"
256256
],
257257
"description": ""
258258
},
259-
"const native fetch ⚡": {
260-
"prefix": "cfetch",
259+
"fetch assignment ⚡": {
260+
"prefix": "fea",
261261
"body": [
262262
"const ${2|data,{ data }|} = await fetch('$1').then(res => res.json())"
263263
],
264264
"description": ""
265265
},
266266
"setInterval ⚡": {
267267
"prefix": "si",
268-
"body": "setInterval(() => {\n\t${2}\n}, ${1:delay})",
268+
"body": "setInterval(() => {\n\t${0}\n}, ${1:delay})",
269269
"description": "Executes the given function at specified intervals in ES6 syntax"
270270
},
271271
"setTimeout ⚡": {
272272
"prefix": "st",
273-
"body": "setTimeout(() => {\n\t${2}\n}, ${1:delay})",
273+
"body": "setTimeout(() => {\n\t${0}\n}, ${1:delay})",
274274
"description": "Executes the given function after the specified delay in ES6 syntax"
275275
},
276276
"import ⚡": {
@@ -288,16 +288,16 @@
288288
"body": "import * as $2 from '$1'",
289289
"description": ""
290290
},
291+
"export from ⚡": {
292+
"prefix": "ex",
293+
"body": "export { $2 } from '$1'",
294+
"description": ""
295+
},
291296
"export all from ⚡": {
292297
"prefix": "exa",
293298
"body": "export * from '$1'",
294299
"description": ""
295300
},
296-
"export from ⚡": {
297-
"prefix": "exfr",
298-
"body": "export { $2 } from '$1'",
299-
"description": ""
300-
},
301301
"export default ⚡": {
302302
"prefix": "exd",
303303
"body": "export default $0",
@@ -542,8 +542,44 @@
542542
],
543543
"description": ""
544544
},
545+
"template literal string ⚡": {
546+
"prefix": "tls",
547+
"body": [
548+
"`$1${$2}$3`"
549+
],
550+
"description": "template literal string"
551+
},
552+
"template literal expression ⚡": {
553+
"prefix": "tl",
554+
"body": [
555+
"${$2}"
556+
],
557+
"description": "template literal"
558+
},
559+
// Type
560+
"is array ⚡": {
561+
"prefix": "aia",
562+
"body": [
563+
"Array.isArray(${1:value})"
564+
],
565+
"description": "is array"
566+
},
567+
"typeof ⚡": {
568+
"prefix": "to",
569+
"body": [
570+
"typeof ${0:operand} === '${1|bigint,boolean,function,number,object,string,symbol,undefined|}'"
571+
],
572+
"description": "is array"
573+
},
574+
"instanceof": {
575+
"prefix": "io",
576+
"body": [
577+
"${1:object} instanceof ${0:constructor}"
578+
],
579+
"description": "instanceof operator"
580+
},
545581
"is nil ⚡": {
546-
"prefix": "nil",
582+
"prefix": "isnil",
547583
"body": [
548584
"${1:value} == null"
549585
],
@@ -556,18 +592,46 @@
556592
],
557593
"description": ""
558594
},
559-
"template literal string ⚡": {
560-
"prefix": "tls",
595+
"return": {
596+
"prefix": "re",
561597
"body": [
562-
"`$1${$2}$3`"
598+
"return $0"
563599
],
564-
"description": "template literal string"
600+
"description": ""
565601
},
566-
"template literal expression ⚡": {
567-
"prefix": "tl",
602+
"return object": {
603+
"prefix": "reo",
568604
"body": [
569-
"${$2}"
605+
"return {\n\t$0\n}"
570606
],
571-
"description": "template literal"
572-
}
607+
"description": ""
608+
},
609+
"return object inline": {
610+
"prefix": "rei",
611+
"body": [
612+
"return ({$0})"
613+
],
614+
"description": ""
615+
},
616+
"uniq": {
617+
"prefix": "uniq",
618+
"body": [
619+
"[...new Set(${0:array})]"
620+
],
621+
"description": ""
622+
},
623+
"parse int": {
624+
"prefix": "pi",
625+
"body": [
626+
"parseInt(${1:value}, ${2|10,2,8,16|})"
627+
],
628+
"description": ""
629+
},
630+
"parse float": {
631+
"prefix": "pf",
632+
"body": [
633+
"parseFloat(${1:value})"
634+
],
635+
"description": ""
636+
},
573637
}

snippets/ts.code-snippets

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,31 @@
3737
"interface extends ⚡": {
3838
"prefix": "inte",
3939
"body": [
40-
"interface ${1:Model} extends {2:Base} {\n\t$0\n}"
40+
"interface ${1:Model} extends ${2:Base} {\n\t$0\n}"
4141
],
4242
"description": ""
4343
},
4444
"type ⚡": {
4545
"prefix": "tp",
4646
"body": [
47-
"type ${1:Model} = $0"
47+
"type ${1:Model} = $0",
48+
""
4849
],
4950
"description": ""
5051
},
5152
"type union ⚡": {
5253
"prefix": "tpu",
5354
"body": [
54-
"type ${1:Model} = $2 | $3"
55+
"type ${1:Model} = ${2:first} | ${3:second}",
56+
""
5557
],
5658
"description": ""
5759
},
5860
"type intersection ⚡": {
5961
"prefix": "tpi",
6062
"body": [
61-
"type ${1:Model} = $2 & $3"
63+
"type ${1:Model} = ${2:first} & ${3:second}",
64+
""
6265
],
6366
"description": ""
6467
},

0 commit comments

Comments
 (0)