3
3
🚧 Work in progress
4
4
5
5
6
-
7
6
> Short and memorable JavaScript & TypeScript snippets for the modern-day developer.
8
7
9
8
<br >
@@ -90,19 +89,19 @@ You can use these snippets along with Prettier/ESLint to have your code automati
90
89
91
90
### Promises
92
91
93
- | Prefix | Description | Body |
94
- | ------- | ------------------ | ----------------------------------------------------------------------- |
95
- | ` fet ` | native fetch | ` fetch('$1').then(res => res.json()) ` |
92
+ | Prefix | Description | Body |
93
+ | ------- | ------------------ | ------------------------------------------------------------------------- |
94
+ | ` fet ` | native fetch | ` fetch('$1').then(res => res.json()) ` |
96
95
| ` feta ` | fetch assignment | ` const ${2\|data,{ data }\|} = await fetch('$1').then(res => res.json()) ` |
97
- | ` pr ` | promise | ` new Promise((resolve, reject) => { $0 }) ` |
98
- | ` prs ` | promise resolve | ` Promise.resolve($1)$0 ` |
99
- | ` prj ` | promise reject | ` Promise.reject($1)$0 ` |
100
- | ` then ` | promise.then | ` $1.then((${2:value}) => $0 ` |
101
- | ` catch ` | promise.catch | ` $1.catch((${2:err}) => $0 ` |
102
- | ` thenc ` | promise.then.catch | ` $1.then((${2:value}) => $3.catch((${4:err}) => $5 ` |
103
- | ` pra ` | promise.all | ` Promise.all($1)$0 ` |
104
- | ` prsa ` | promise.allSettled | ` Promise.allSettled($1)$0 ` |
105
- | ` pran ` | promise.any | ` Promise.any($1)$0 ` |
96
+ | ` pr ` | promise | ` new Promise((resolve, reject) => { $0 }) ` |
97
+ | ` prs ` | promise resolve | ` Promise.resolve($1)$0 ` |
98
+ | ` prj ` | promise reject | ` Promise.reject($1)$0 ` |
99
+ | ` then ` | promise.then | ` $1.then((${2:value}) => $0 ` |
100
+ | ` catch ` | promise.catch | ` $1.catch((${2:err}) => $0 ` |
101
+ | ` thenc ` | promise.then.catch | ` $1.then((${2:value}) => $3.catch((${4:err}) => $5 ` |
102
+ | ` pra ` | promise.all | ` Promise.all($1)$0 ` |
103
+ | ` prsa ` | promise.allSettled | ` Promise.allSettled($1)$0 ` |
104
+ | ` pran ` | promise.any | ` Promise.any($1)$0 ` |
106
105
107
106
108
107
### Modules
@@ -123,22 +122,23 @@ You can use these snippets along with Prettier/ESLint to have your code automati
123
122
124
123
125
124
### Array methods
126
- | Prefix | Description | Body |
127
- | -------------- | -------------------------------- | ---------------------------------------------------------------- |
128
- | ` fe ` | Array.forEach() | ` $1.forEach((${2:item}) => { $0 }) ` |
129
- | ` map ` | Array.map() | ` $1.map((${2:item}) => ${3})$0 ` |
130
- | ` reduce ` | Array.reduce() | ` $1.reduce((${2:acc}, ${3:curr}) => { $0 }, ${4:initial}) ` |
131
- | ` reduce-right ` | Array.reduceRight() | ` $1.reduceRight((${2:acc}, ${3:curr}) => { $0 }, ${4:initial}) ` |
132
- | ` filter ` | Array.filter() | ` $1.filter((${2:item}) => ${3})$0 ` |
133
- | ` find ` | Array.find() | ` $1.find((${2:item}) => ${3})$0 ` |
134
- | ` every ` | Array.every() | ` $1.every((${2:item}) => ${3})$0 ` |
135
- | ` some ` | Array.some() | ` $1.some((${2:item}) => ${3})$0 ` |
136
- | ` reverse ` | Array.reverse() | ` $1.reverse()$0 ` |
137
- | ` map-string ` | Array.map() as string | ` $1.map(String)$0 ` |
138
- | ` map-number ` | Array.map() as number | ` $1.map(Number)$0 ` |
139
- | ` filter-true ` | Array.filter() for truthy values | ` $1.filter(Boolean)$0 ` |
140
-
141
- ## Obkects
125
+
126
+ | Prefix | Description | Body |
127
+ | -------------- | -------------------------------- | --------------------------------------------------------------- |
128
+ | ` fe ` | Array.forEach() | ` $1.forEach((${2:item}) => { $0 }) ` |
129
+ | ` map ` | Array.map() | ` $1.map((${2:item}) => ${3})$0 ` |
130
+ | ` reduce ` | Array.reduce() | ` $1.reduce((${2:acc}, ${3:curr}) => { $0 }, ${4:initial}) ` |
131
+ | ` reduce-right ` | Array.reduceRight() | ` $1.reduceRight((${2:acc}, ${3:curr}) => { $0 }, ${4:initial}) ` |
132
+ | ` filter ` | Array.filter() | ` $1.filter((${2:item}) => ${3})$0 ` |
133
+ | ` find ` | Array.find() | ` $1.find((${2:item}) => ${3})$0 ` |
134
+ | ` every ` | Array.every() | ` $1.every((${2:item}) => ${3})$0 ` |
135
+ | ` some ` | Array.some() | ` $1.some((${2:item}) => ${3})$0 ` |
136
+ | ` reverse ` | Array.reverse() | ` $1.reverse()$0 ` |
137
+ | ` map-string ` | Array.map() as string | ` $1.map(String)$0 ` |
138
+ | ` map-number ` | Array.map() as number | ` $1.map(Number)$0 ` |
139
+ | ` filter-true ` | Array.filter() for truthy values | ` $1.filter(Boolean)$0 ` |
140
+
141
+ ## Objects
142
142
143
143
| Prefix | Description | Body |
144
144
| ------ | ------------------ | ------------------------ |
@@ -149,38 +149,40 @@ You can use these snippets along with Prettier/ESLint to have your code automati
149
149
150
150
### Returns
151
151
152
- | Prefix | Description | Body |
153
- | ------ | -------------------- | ---------------- |
154
- | ` re ` | return | ` return $0 ` |
155
- | ` reo ` | return object | ` return { $0 } ` |
156
- | ` rei ` | return object inline | ` return ({$0}) ` |
152
+ | Prefix | Description | Body |
153
+ | ------ | -------------------- | --------------- |
154
+ | ` re ` | return | ` return $0 ` |
155
+ | ` reo ` | return object | ` return { $0 } ` |
156
+ | ` rei ` | return object inline | ` return ({$0}) ` |
157
157
158
158
159
159
### Operators, expressions, literals
160
160
* will be better categorized*
161
161
162
- | Prefix | Description | Body |
163
- | ------ | ----------------------------------- | ---------------------------- |
164
- | ` or ` | OR (\|\| ) | ` \|\| $0 ` |
165
- | ` and ` | AND (&&) | ` && $0 ` |
166
- | ` nc ` | Nullish coalescing (??) | ` ?? $0 ` |
167
- | ` eq ` | strict equality (===) | ` === $0 ` |
162
+ | Prefix | Description | Body |
163
+ | ------ | ----------------------------------- | ------------------------------ |
164
+ | ` or ` | OR (\|\| ) | ` \|\| $0 ` |
165
+ | ` and ` | AND (&&) | ` && $0 ` |
166
+ | ` nc ` | Nullish coalescing (??) | ` ?? $0 ` |
167
+ | ` eq ` | strict equality (===) | ` === $0 ` |
168
168
| ` ore ` | logical OR expression | ` ${1:value} \|\| ${0:value} ` |
169
- | ` ande ` | logical AND expression | ` ${1:value} && ${0:value} ` |
170
- | ` nce ` | Nullish coalescing expression (??) | ` ${1:item} ?? ${0:default} ` |
171
- | ` eqe ` | strict equality expression | ` ${1:value} === ${2:value} ` |
172
- | ` ora ` | Logical OR assignment (\|\| =) | ` ${1:name} \|\|= ${0:default} ` |
173
- | ` nca ` | Nullish coalescing assignment (??=) | ` ${1:name} ??= ${0:default} ` |
174
- | ` inc ` | addition assignment | ` $1 += ${0:1} ` |
175
- | ` sub ` | subtraction assignment | ` $1 -= ${0:1} ` |
176
- | ` mul ` | multiplication assignment | ` $1 *= ${0:1} ` |
177
- | ` div ` | division assignment | ` $1 /= ${0:1} ` |
178
- | ` ol ` | object literal | ` { $1: $0 } ` |
179
- | ` al ` | array literal | ` [$0] ` |
180
- | ` tl ` | template literal | `` $0 `` |
181
- | ` tlo ` | template literal operation | ` ${$1}$0 ` |
182
- | ` tle ` | template literal expression | `` $1${$2}$0 `` |
183
-
169
+ | ` ande ` | logical AND expression | ` ${1:value} && ${0:value} ` |
170
+ | ` nce ` | Nullish coalescing expression (??) | ` ${1:item} ?? ${0:default} ` |
171
+ | ` eqe ` | strict equality expression | ` ${1:value} === ${2:value} ` |
172
+ | ` ora ` | Logical OR assignment (\|\| =) | ` ${1:name} \|\|= ${0:default} ` |
173
+ | ` nca ` | Nullish coalescing assignment (??=) | ` ${1:name} ??= ${0:default} ` |
174
+ | ` inc ` | addition assignment | ` $1 += ${0:1} ` |
175
+ | ` sub ` | subtraction assignment | ` $1 -= ${0:1} ` |
176
+ | ` mul ` | multiplication assignment | ` $1 *= ${0:1} ` |
177
+ | ` div ` | division assignment | ` $1 /= ${0:1} ` |
178
+ | ` ol ` | object literal | ` { $1: $0 } ` |
179
+ | ` al ` | array literal | ` [$0] ` |
180
+ | ` tl ` | template literal | `` $0 `` |
181
+ | ` tlo ` | template literal operation | ` ${$1}$0 ` |
182
+ | ` tle ` | template literal expression | `` $1${$2}$0 `` |
183
+
184
+
185
+ ### Console
184
186
185
187
| Prefix | Description | Body |
186
188
| ------ | -------------------------- | --------------------------------------------- |
@@ -199,14 +201,16 @@ You can use these snippets along with Prettier/ESLint to have your code automati
199
201
| ` cel ` | console.error labeled | ` console.error('$1 ->', $1$2) ` |
200
202
| ` cwl ` | console.warn labeled | ` console.warn('$1 ->', ${2:$1}) ` |
201
203
204
+ ### Timers
202
205
203
- | Prefix | Description | Body |
204
- | ------ | ---------------- | ---------------------------------------- |
205
- | ` si ` | setInterval | ` setInterval(() => { $0 }, ${1:delay}) ` |
206
- | ` st ` | setTimeout | ` setTimeout(() => { $0 }, ${1:delay}) ` |
207
- | ` sim ` | setImmediate | ` setImmediate(() => { $0 }) ` |
208
- | ` nt ` | process nextTick | ` process.nextTick(() => { $0 }) ` |
206
+ | Prefix | Description | Body |
207
+ | ------ | ---------------- | --------------------------------------- |
208
+ | ` si ` | setInterval | ` setInterval(() => { $0 }, ${1:delay}) ` |
209
+ | ` st ` | setTimeout | ` setTimeout(() => { $0 }, ${1:delay}) ` |
210
+ | ` sim ` | setImmediate | ` setImmediate(() => { $0 }) ` |
211
+ | ` nt ` | process nextTick | ` process.nextTick(() => { $0 }) ` |
209
212
213
+ ### JSON
210
214
211
215
| Prefix | Description | Body |
212
216
| ------ | ---------------------------- | ------------------------------------------------------------- |
@@ -215,6 +219,7 @@ You can use these snippets along with Prettier/ESLint to have your code automati
215
219
| ` jsp ` | JSON.stringify pretty | ` JSON.stringify(${1:value}, null, 2) ` |
216
220
| ` jss ` | JSON.stringify if not string | ` typeof ${1:value} === 'string' ? value : JSON.stringify($1) ` |
217
221
222
+ ### DOM
218
223
219
224
| Prefix | Description | Body |
220
225
| ------ | ----------------------------- | -------------------------------------------------------------------------------- |
@@ -226,15 +231,17 @@ You can use these snippets along with Prettier/ESLint to have your code automati
226
231
| ` gid ` | get element by id | ` ${1:document}.getElementById('$2') ` |
227
232
| ` on ` | event handler | ` ${1:emitter}.on('${2:event}', (${3:arguments}) => { $0 }) ` |
228
233
234
+ ### Dates
229
235
230
236
| Prefix | Description | Body |
231
237
| ------ | ----------- | ---------------- |
232
238
| ` nd ` | new date | ` new Date($1)$0 ` |
233
239
| ` now ` | Date.now() | ` Date.now() ` |
234
240
241
+ ### Testing
235
242
236
- | Prefix | Description | Body |
237
- | ------ | ------------------- | --------------------------------------------------- |
243
+ | Prefix | Description | Body |
244
+ | ------ | ------------------- | -------------------------------------------------- |
238
245
| ` desc ` | describe | ` describe('${1:description}', () => { $0 }) ` |
239
246
| ` cont ` | context | ` context('${1:description}', () => { $0 }) ` |
240
247
| ` it ` | test (synchronous) | ` it('${1:description}', () => { $0 }) ` |
@@ -248,15 +255,15 @@ You can use these snippets along with Prettier/ESLint to have your code automati
248
255
249
256
### Types
250
257
251
- | Prefix | Description | Body |
252
- | ------- | ----------- | ---------------------------------------------------------------------------------------- |
253
- | ` aia ` | is array | ` Array.isArray($0) ` |
254
- | ` tof ` | typeof | ` typeof ${1:value} === '${1}'$0 ` |
255
- | ` iof ` | instanceof | ` ${1:object} instanceof ${0:Class ` |
256
- | ` isnil ` | is nil | ` ${1:value} == null ` |
257
- | ` nnil ` | is not nil | ` ${1:value} != null ` |
258
- | ` isnan ` | is NaN | ` isNan($0) ` |
259
- | ` nnan ` | is not NaN | ` !isNan($0) ` |
258
+ | Prefix | Description | Body |
259
+ | ------- | ----------- | ---------------------------------- |
260
+ | ` aia ` | is array | ` Array.isArray($0) ` |
261
+ | ` tof ` | typeof | ` typeof ${1:value} === '${1}'$0 ` |
262
+ | ` iof ` | instanceof | ` ${1:object} instanceof ${0:Class ` |
263
+ | ` isnil ` | is nil | ` ${1:value} == null ` |
264
+ | ` nnil ` | is not nil | ` ${1:value} != null ` |
265
+ | ` isnan ` | is NaN | ` isNan($0) ` |
266
+ | ` nnan ` | is not NaN | ` !isNan($0) ` |
260
267
261
268
262
269
### Miscellaneous
@@ -273,15 +280,15 @@ You can use these snippets along with Prettier/ESLint to have your code automati
273
280
## Uncategorized
274
281
275
282
⚠️ * working on it*
276
- | Prefix | Description | Body |
277
- | ------ | ---------------- | --------------------------------------- |
278
- | ` uniq ` | uniq | ` [...new Set(${0:array})] ` |
283
+ | Prefix | Description | Body |
284
+ | ------ | ---------------- | ----------------------------------------- |
285
+ | ` uniq ` | uniq | ` [...new Set(${0:array})] ` |
279
286
| ` pi ` | parse int | ` parseInt(${1:value}, ${2\|10,2,8,16\|}) ` |
280
- | ` pf ` | parse float | ` parseFloat(${1:value}) ` |
281
- | ` am ` | array me | ` [...${1:arr}$2]$0 ` |
282
- | ` om ` | object merge | ` [...${1:arr}$2]$0 ` |
283
- | ` aat ` | array at | ` ${1:items}.at(${2:0}) ` |
284
- | ` seq ` | sequence of 0..n | ` [...Array(${1:length}).keys()]$0 ` |
287
+ | ` pf ` | parse float | ` parseFloat(${1:value}) ` |
288
+ | ` am ` | array me | ` [...${1:arr}$2]$0 ` |
289
+ | ` om ` | object merge | ` [...${1:arr}$2]$0 ` |
290
+ | ` aat ` | array at | ` ${1:items}.at(${2:0}) ` |
291
+ | ` seq ` | sequence of 0..n | ` [...Array(${1:length}).keys()]$0 ` |
285
292
286
293
287
294
## TypeScript snippets
@@ -298,13 +305,13 @@ You can use these snippets along with Prettier/ESLint to have your code automati
298
305
299
306
### Types
300
307
301
- | Prefix | Description | Body |
302
- | ------ | ----------------- | ------------------------------------------------ |
303
- | ` int ` | interface | ` interface ${1:Model} { $0 } ` |
304
- | ` inte ` | interface extends | ` interface ${1:Model} extends ${2:Base} { $0 } ` |
305
- | ` tp ` | type | ` type ${1:Model} = $0 ` |
306
- | ` tpu ` | type union | ` type ${1:Model} = ${2:first} \| ${3:second} ` |
307
- | ` tpi ` | type intersection | ` type ${1:Model} = ${2:first} & ${3:second} ` |
308
+ | Prefix | Description | Body |
309
+ | ------ | ----------------- | ----------------------------------------------- |
310
+ | ` int ` | interface | ` interface ${1:Model} { $0 } ` |
311
+ | ` inte ` | interface extends | ` interface ${1:Model} extends ${2:Base} { $0 } ` |
312
+ | ` tp ` | type | ` type ${1:Model} = $0 ` |
313
+ | ` tpu ` | type union | ` type ${1:Model} = ${2:first} \| ${3:second} ` |
314
+ | ` tpi ` | type intersection | ` type ${1:Model} = ${2:first} & ${3:second} ` |
308
315
309
316
* ...and many more (evertyhing will be documented)*
310
317
0 commit comments