/
snippets.json
573 lines (505 loc) · 19.6 KB
/
snippets.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
{
"firebase config":{
"prefix": "fireconfig",
"body":[
"var config = {",
"apiKey: ${1:apiKey},",
"authDomain: ${2:projectId.firebaseapp.com},",
"databaseURL: ${3:https://databaseName.firebaseio.com},",
"storageBucket: ${4:bucket.appspot.com}",
"};",
"firebase.initializeApp(config);"
],
"description":"Configure Firebase"
},
"firebase reference":{
"prefix":"firereference",
"body": "let ${1:database} = firebase.database();",
"description":"Get a reference to the firebase service"
},
"firebase set data":{
"prefix":"fireset",
"body":[
"firebase.database().ref(${0:/* path */}).set({",
"${1: /* attribute: value */}",
"});"
],
"description": "Set data to the firebase database"
},
"firebase retrieve data":{
"prefix":"fireretrieve",
"body":[
"firebase.database().ref(${0:/* path */}).on(${0:eventType},(${1:snapshot})=> {",
"${2: /* handle read data */}",
"console.log(${3: /* log data */})",
" });"
],
"description":"Retrieve data from firebase"
},
"firebase retrieve and loop data":{
"prefix":"fireretrieveloop",
"body":[
"firebase.database().ref(${0:/* path */}).on(${0:eventType},(${1:snapshot})=> {",
"${1:snapshot}.forEach((${2:childSnapshot})=>{",
"${3: /* handle read data */}",
"console.log(${4: /* log data */})",
" });",
" });"
],
"description": "Retrieve data and loop inside the direct children"
},
"firebase val":{
"prefix":"fireval",
"body": ["let ${0:names}=${1:snapshot}.val().${2:name}",
"/* retrieve the name from the database */"
],
"description":"Using val() method to retrieve the data inside a listener"
},
"firebase retrieve once":{
"prefix":"fireretrieveonce",
"body":[
"firebase.database().ref(${0:/* path */}).once(${0:eventType}).then((${1:snapshot})=> {",
"${2: /* handle read data */}",
"console.log(${3: /* log data */})",
"});"
],
"description": "Retrieve data once"
},
"firebase create a key":{
"prefix":"firekey",
"body": "let ${0:newPostKey} = firebase.database().ref().child(${1:/* path */}).push().key;",
"description": "Create a key and simultaneously retrieve the key"
},
"Firebase Update": {
"prefix": "fireupdate",
"body": "${1:ref}.update(${2: value} , ${0:/* onComplete */});",
"description": "Updating specific fields"
},
"Firebase Remove":{
"prefix":"fireremove",
"body":"let ${0:ref} = firebase.database().ref().child(${1:/* path */}).remove();",
"description": "Remove data at a certain location"
},
"Firebase transactions": {
"prefix": "firetransaction",
"body": "firebase.database().ref().transaction(${2: updateFunction}, ${3:/* onComplete */}, ${0:/* do the required*/});",
"description": "firebase transactions"
},
"Firebase OrderByChild":{
"prefix":"fireorderBychild",
"body": "let ${0:retrieveData} = firebase.database().ref(${1:/* path */}).orderByChild(${2: /* child key */});",
"description": "Order results by the value of a specified child key or nested child path."
},
"Firebase OrderByValue":{
"prefix":"fireorderByvalue",
"body": "let ${0:retrieveData} = firebase.database().ref(${1:/* path */}).orderByValue();",
"description": "Order results by child values."
},
"Firebase OrderByKey":{
"prefix":"fireorderBykey",
"body": "let ${0:retrieveData} = firebase.database().ref(${1:/* path */}).orderByKey();",
"description": "Order results by child keys."
},
"Firebase limitToFirst":{
"prefix":"firelimittofirst",
"body":["let ${0:postsRef} = firebase.database().ref(${1:/* path */}).limitToFirst(${2:number});",
"//can be used with one order-by method and multiple limit or range functions"
],
"description": "Sets the maximum number of items to return from the end of the ordered list of results."
},
"Firebase limitToLast":{
"prefix":"firelimittolast",
"body":[ "let ${0:postsRef} = firebase.database().ref(${1:/* path */}).limitToLast(${2:number});",
"//can be used with one order-by method and multiple limit or range functions"
],
"description": "Sets the maximum number of items to return from the beginning of the ordered list of results."
},
"Firebase startAt":{
"prefix":"firestartAt",
"body":[ "let ${0:postsRef} = firebase.database().ref(${1:/* path */}).startAt(${2:number});",
"//can be used with one order-by method and multiple limit or range functions"
],
"description":"Return items greater than or equal to the specified key or value, depending on the order-by method chosen."
},
"firebase endAt":{
"prefix":"fireendat",
"body":[ "let ${0:postsRef} = firebase.database().ref(${1:/* path */}).endAt(${2:number});",
"//can be used with one order-by method and multiple limit or range functions"
],
"description":"Return items less than or equal to the specified key or value, depending on the order-by method chosen."
},
"firebase equalTo":{
"prefix":"fireequalto",
"body":[ "let ${0:postsRef} = firebase.database().ref(${1:/* path */}).orderByChild(${2: /* child key */}).equalTo(${3:value});",
"//can be used with one order-by method and multiple limit or range functions"
],
"description": "Return items equal to the specified key or value, depending on the order-by method chosen."
},
"firebase exists":{
"prefix":"fireexists",
"body": "let ${0:child} = ${1: snapshot}.exists();",
"description": "Returns true if this dataSnapshot contains any data"
},
"firebase hasChild":{
"prefix":"firehaschild",
"body":" let ${0:hasName} = ${1:snapshot}.hasChild(${2:/* name */}); ",
"description":"Returns true if this datasnapshot contains the specified child"
},
"firebase hasChildren":{
"prefix":"firehaschildren",
"body":" let ${0:datas} = ${1:snapshot}.hasChildren(); ",
"description":" Returns true is this datasnapshot contains any children"
},
"firebase numChildren":{
"prefix":"firenumchildren",
"body":" let ${0:numOfChildren} = ${1:snapshot}.numChildren();",
"description":" Returns the number of child properties of this datasnapshot"
},
"firebase detach listener":{
"prefix":"firedetach",
"body":"${0:ref}.off(${1:eventType}, ${2:callback /* optional, callback function that was passed to on */});",
"description":"Removing a listener"
},
"firebase storage reference":{
"prefix":"firestorageref",
"body": "let ${0:storage} = firebase.storage();",
"description":"Get a reference to the storage service, which is used to create references in your storage bucket."
},
"firebase storage child reference":{
"prefix":"firestoragechildref",
"body":[ "var ${0:storage} = firebase.storage();",
"var ${1:storageRef} = ${0:storage}.ref();",
"var ${2:imagesRef} = ${3:storageRef}.child(${4: /* image path */});"
],
"description": "Create a reference to a location lower in the tree, say 'images.jpg."
},
"firebase storage url reference":{
"prefix":"firestorageurlref",
"body":"let ${0:gsReference} = storage.refFromURL(${1: /* gs:// or https:// */});",
"description":"Create a reference from a Google Cloud Storage URI or https url."
},
"firebase download file":{
"prefix":"firestoragedownloadfile",
"body":[ "${0:storageRef}.child(${1:/* path */}).getDownloadURL().then(function(url) {",
"// `url` is the download URL for 'images/stars.jpg'",
"//Download using `XMLHttpRequest()`",
"}).catch(function(error) {",
"// Handle any errors",
"});"
],
"description":"Getting the download file from firebase storage."
},
"firebase delete file":{
"prefix":"firestoragedeletefile",
"body": ["${0:storageRef}.delete().then(function() {",
"// File deleted successfully",
"}).catch(function(error) {",
"//An error occurred!",
" });"
],
"description":"Delete a file"
},
"firebase sign up":{
"prefix":"firesignupemail",
"body":[
"firebase.auth().createUserWithEmailAndPassword(${0:email}, ${1:password}).catch(function(error) {",
"// Handle Errors here.",
"let ${2:errorCode} = error.code;",
"let ${3:errorMessage} = error.message;",
"});"
],
"description":"Authenticate a new user using email and password"
},
"firebase sign in":{
"prefix":"firesigninemail",
"body":[
"firebase.auth().signInWithEmailAndPassword(${0:email}, ${1:password}).catch(function(error) {",
"// Handle Errors here.",
"let ${2:errorCode} = error.code;",
"let ${3:errorMessage} = error.message;",
"});"
],
"description":"Sign in an existing user"
},
"firebase Auth State":{
"prefix":"fireauthstate",
"body":["firebase.auth().onAuthStateChanged(function(${0:user}) {",
"${1: /* user information */}",
"});"
],
"description": "Attach an observer using onAuthStateChanged to retrieve user infomration."
},
"firebase Current User":{
"prefix":"firecurrentuser",
"body":[
"firebase.auth().onAuthStateChanged(function(${0:user}) { //or use firebase.auth().currentUser;",
"if (user) {",
" // User is signed in.",
"} else {",
"// No user is signed in.",
"}",
"});"
],
"description":"Retrieves the currently logged in user"
},
"firebase user profile":{
"prefix":"fireuserprofile",
"body":[
"var ${0:user} = firebase.auth().currentUser;",
"var ${1:name}, ${2:email}, ${3:photoUrl}, ${4:uid}, ${5:emailVerified};",
"if (${0:user} != null) {",
"${4:uid} = user.uid;",
"}"
],
"description": "Retrieves the user information."
},
"firebase Update Profile":{
"prefix":"fireupdateprofile",
"body": "${0:user}.updateProfile({${1:displayName}:${2:name}});",
"description":"Updates the user profile"
},
"firebase provider information":{
"prefix":"fireproviderinfo",
"body":["${0:user}.providerData.forEach(function (${1:profile}) {",
"/* retrieve provider info */",
"});"
],
"description":"Retrieves information from sign in provider."
},
"firebase user email":{
"prefix":"fireupdateemail",
"body":[
"${0:user}.updateEmail(${1:email}).then(function() {",
"// Update successful.",
"}).catch(function(error) {",
"// An error happened.",
" });"
],
"description":"Set a user email address, the user must have signed in recently."
},
"firebase Send Email Verification":{
"prefix":"fireemailverify",
"body":[
"${0:user}.sendEmailVerification().then(function() {",
"// sent email.",
"}).catch(function(error) {",
"// An error happened.",
" });"
],
"description":"Send an email verification to the user."
},
"firebase set password":{
"prefix":"firesetpass",
"body":[
"let ${0:newPassword} = getASecureRandomPassword();",
"${1:user}.updatePassword(${2:newpassword}).then(function() {",
"// Update successful.",
"}).catch(function(error) {",
"// An error happened.",
" });"
],
"description":"Set a user password, the user must have signed in recently"
},
"firebase password reset":{
"prefix":"firepassreset",
"body":[
"${1:auth}.sendPasswordResetEmail(${2:email}).then(function() {",
"// Email Sent.",
"}).catch(function(error) {",
"// An error happened.",
" });"
],
"description":"Send a password reset email to a user"
},
"firebase delete user":{
"prefix":"firedeleteuser",
"body":[
"let ${1:user} = firebase.auth().currentUser;",
"${1:user}.delete().then(function() {",
"// Update Deleted.",
"}).catch(function(error) {",
"// An error happened.",
" });"
],
"description":"Delete a user account with the delete method."
},
"firebase sign out":{
"prefix":"firesignout",
"body":[
"firebase.auth().signOut().then(function() {",
"// Sign-out successful.",
"}).catch(function(error) {",
"// An error happened.",
"});"
],
"description":"Sign out the user."
},
"firebase google instance":{
"prefix":"firegoogleinstance",
"body": "let ${0:provider} = new firebase.auth.GoogleAuthProvider();",
"description":"Get instance of the google provider."
},
"firebase provider Sign in":{
"prefix":"fireprovidersignin",
"body":"firebase.auth().signInWithRedirect(${0:provider}); //for google,facebook,twitter, and github",
"description":"Sign in with google"
},
"firebase facebook instance":{
"prefix":"firefacebookinstance",
"body":"let ${0:provider} = new firebase.auth.FacebookAuthProvider();",
"description":"Get instance of facebook provider"
},
"firebase twitter instance":{
"prefix":"firetwitterinstance",
"body":"let ${0:provider} = new firebase.auth.TwitterAuthProvider();",
"description":"Get instance of twitter provider"
},
"firebase github instance":{
"prefix":"firegithubinstance",
"body":"let ${0:provider} = new firebase.auth.GithubAuthProvider();",
"description":"Get instance of github provider"
},
"firebase custom auth":{
"prefix":"firecustomauth",
"body":[
"firebase.auth().signInWithCustomToken(${0:token}).catch(function(${1:error}) {",
"// Handle Errors here.",
"let ${2:errorCode} = error.code;",
"let ${3:errorMessage} = error.message;",
"// ...",
"});"
],
"description":"Sign in the user using custom authentication"
},
"firebase anonymously":{
"prefix":"fireanonymously",
"body":[
"firebase.auth().signInAnonymously().catch(function(error) {",
"// Handle Errors here.",
"let ${1:errorCode} = error.code;",
"let ${2:errorMessage} = error.message;",
"// ...",
"});"
],
"description":"Sign in the user anonymously"
},
"firestore Initialize":{
"prefix":"initializefirestore",
"body":"let ${0:db} = firebase.firestore();",
"description":"Initialize Cloud Firestore through Firebase."
},
"firestore add data":{
"prefix":"adddatafirestore",
"body":[
"${0:db}.collection(${1:/* collection */}).add({ //add creates a unique id for you",
"${2:attribute}: ${3:value}",
"})",
".then(function(docRef) {",
"${4: /* log data */}",
"})",
".catch(function(error) {",
"${5:/* error */}",
"});"
],
"description":"Creating a new collection and document in firestore."
},
"firestore read data":{
"prefix":"readdatafirestore",
"body":[
"${0:db}.collection(${1:/* collection_name */}).get().then((${2:querySnapshot}) => {",
"${2:querySnapshot}.forEach((doc) => {",
"${3:/* log the data */}",
" });",
" });"
],
"description":"Read data from a collection in firestore"
},
"firestore set data":{
"prefix":"setdatafirestore",
"body":[
"${0:db}.collection(${1:/* collection_name */}).doc(${2:/* document_name */}).set({",
"${3:attribute}: ${4:value}",
" });"
],
"description":"Creates or overwrite a single document, use the `set()` method"
},
"firestore reference":{
"prefix":"referencefirestore",
"body":"let ${0:docRef} = ${1:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */});",
"description":"Add firestore reference"
},
"firestore update document":{
"prefix":"updatefirestore",
"body":[
"var ${0:ref} = ${1:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */});",
"return ${0:ref}.update({",
"${4:attribute}:${5:newValue}",
"})",
".then(function() {",
" })",
" .catch(function(${6:error}) {",
"// The document probably doesn't exist.",
"console.error(${6:error});",
" });"
],
"description":"Update the document in firestore."
},
"firestore delete document":{
"prefix":"deletedocfirestore",
"body":[
"${0:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */}).delete().then(function() {",
"${4:/* log the data */}",
"}).catch(function(error) {",
"console.error(${5:error});",
"});"
],
"description":"Delete a document in firestore"
},
"firestore delete a field":{
"prefix":"deletefieldfirestore",
"body":[
"let ${0:ref}= ${1:db}.collection(${2:/* collection_name */}).doc(${3: /* document_name */});",
"let ${4:removeField} = ${5:ref}.update({",
"${6:fieldName}: firebase.firestore.FieldValue.delete()",
" });"
],
"description":"Delete a field in firestore document."
},
"firestore where query":{
"prefix":"wherefirestore",
"body":[
"// Create a query against the collection.",
"let ${1:query} = ${0:ref}.where(${2:/*field_name */}, ${3:/* == */}, ${4:/* value */});"
],
"description":"where query in firestore"
},
"firestore array contains":{
"prefix":"arraycontainsfirestore",
"body":[
" ${0:ref}.where(${1:/* field name */}, ${2:array-contains}, ${3:/* value */})"
],
"description":" Using `array-contains` it filters based on array value"
},
"firestore limit":{
"prefix":"limitfirestore",
"body": "${0:ref}.orderBy(${1:/* fieldname */}).limit(${2: /* number */});",
"description": "Retrieves the first three value of the field."
},
"firestore order multiple fields":{
"prefix":"ordermultifirestore",
"body":[
"${0:ref}.orderBy(${1:/* fieldname */}).orderBy(${2: /* name */}, ${3: /* desc */});"
],
"description":"Order by multiple fields in firestore."
},
"firestore Listen to Changes":{
"prefix":"realtimeupdatefirestore",
"body":[
"${0:db}.collection(${1:/* collection_name */}).doc(${2:/* collection_name */})",
".onSnapshot(function(${3:doc}) {",
"console.log(${3:doc}.data());",
" });"
],
"description":"Listens for realtime changes on a document using `onSnapshot`"
}
}