Skip to content

Instantly share code, notes, and snippets.

@dancourbano
Last active July 28, 2022 03:33
Show Gist options
  • Select an option

  • Save dancourbano/f645f5dba32f90ca9dd7e45f3d709dc8 to your computer and use it in GitHub Desktop.

Select an option

Save dancourbano/f645f5dba32f90ca9dd7e45f3d709dc8 to your computer and use it in GitHub Desktop.
Snippets Javascript Visual Studio Code
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Print to console": {
"prefix": "co",
"body": [
"console.log($1);",
"$2"
],
"description": "Log output to console"
},
"Create a class": {
"prefix": "cc",
"body": [
"class $1 {",
"\tconstructor(){",
"\t\t$2",
"\t}",
"}"
],
"description": "create a class with a constructor"
},
"For Loop": {
"prefix": ["forof"],
"body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"],
"description": "A for loop."
},
"for":{
"prefix":"for",
"body":[
"for($${1;i}=0;$${1:i} -lt $${2:array}.Count;$${1:i}++) {",
"\t${0:$TM_SELECTED_TEXT",
"}"
],
"description": "for loop snippet"
},
"Create a async function": {
"prefix": "asy",
"body": [
"async() =>{",
"\t$1",
"}"
],
"description": "create a async function"
},
"require": {
"prefix": "rrr",
"body": ["const $1 = require('$2');"]
},
"import from": {
"prefix": "imf",
"body": ["import $1 from '$2';"]
},
"Stateless Component": {
"prefix": "cons",
"body": "const $1 = (${2:props}) => {$3}"
},
"function_declaration": {
"prefix": "fn",
"body": [
"function ${1:name} (${2:param}) {",
"\t$0",
"}"
],
"description": "function declaration - hoisted"
},
"function_expression": {
"prefix": "fne",
"body": [
"${1:const} ${2:variableName} = function(${3:param}) {",
"\t$0",
"}"
],
"description": "function expression - not hoisted"
},
"concise_arrow_function": {
"prefix": "fna",
"body": [
"(${1:}) => ${2:{$0\\}}"
],
"description": "concise arrow function"
},
"fat_arrow_function": {
"prefix": "const",
"body": [
"${1:const }${2:funcName} = (${3:}) => {$0}"
],
"description": "fat arrow function"
},
"Put setTimeout statement": {
"prefix": "setT",
"body": [
"setTimeout(() => {$0}, ${1:timeout});"
],
"description": "Insert setTimeout statement"
},
"Put setInterval statement": {
"prefix": "setI",
"body": [
"setInterval(() => {$0}, ${1:interval});"
],
"description": "Insert setInterval statement"
},
"if": {
"prefix": "if",
"body": [
"if (${1:condition}) {",
" $0",
"}",
],
"description": "Create multiline command."
},
"arrow": {
"prefix": "a",
"body": [
"(${1:param}) => {",
" $0",
"}"
],
"description": ""
},
"pulse-route": {
"prefix": "route",
"body": [
"${1:name}: request => request.get(`${2:route}`)",
],
"description": "Create multiline command."
},
"Class component": {
"prefix": "rclass",
"body": [
"/* @flow strict-local */\n",
"import React, { PureComponent } from 'react';\n",
"type Props = {};\n",
"export default class $1 extends PureComponent<Props> {",
"\trender() {",
"\t\treturn <h1>$1</h1>;",
"\t}",
"}\n"
],
"description": "react class component snippet"
},
"Functional component": {
"prefix": "rfun",
"body": [
"/* @flow strict-local */\n",
"import React from 'react';\n",
"type Props = {};\n",
"export default function $1({}: Props) {",
"\treturn <h1>$1</h1>;",
"}\n"
],
"description": "react class component snippet"
},
"then catch": {
"prefix": "thencatch",
"body": [
".then( (${1:data}) => console.log(${1:data}))",
".catch( (${2:err}) => console.log(${2:err}));"
],
"description": ".then().catch()"
},
"then": {
"prefix": "then",
"body": [
".then( (${1:data}) => console.log(${1:data}))"
],
"description": ".then()"
},
"catch": {
"prefix": "catch",
"body": [
".catch( (${1:err}) => console.log(${1:err}));"
],
"description": ".catch()"
},
"require module": {
"prefix": "req",
"body": [
"const ${1:variableName} = require('${2:module}')"
],
"description": "require module"
},
"express_hbs_base": {
"prefix": "ehbs",
"body": [
"const express = require('express');",
"const hbs = require('hbs');",
"const app = express();",
"const PORT = 3000;",
"",
"",
"// SET THE TEMPLATE ENGINE",
"app.set('view engine', 'hbs');",
"app.set('views', __dirname + '/views');",
"",
"// SET THE STATIC FOLDER FOR PUBLIC FILES",
"app.use(express.static(__dirname + '/public'));",
"",
"// REGISTER THE PARTIAL ",
"hbs.registerPartials(__dirname + '/views/partials');",
"",
"",
"// START THE SERVER",
"app.listen(PORT, () => console.log(`Server listening on port ${ PORT } !`));"
],
"description": "Express and Handlebars basic skeleton"
},
"describe_test": {
"prefix": "descri",
"body": [
"describe('${1:description}' ,(${2})=>{",
"\ttest('${3}', (${4})=>{",
"\t\t${5}",
"\t});",
"\t${6}",
"});"
],
"description": "describe module test nodejs"
},
"add_test": {
"prefix": "test",
"body": [
"test('${1:descriptionTest}', (${2})={",
"\t${3}",
"});",
"${4}"
],
"description": "add module test nodejs"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment