Skip to content

Instantly share code, notes, and snippets.

@michael-wolfenden
Last active October 23, 2015 03:35
Show Gist options
  • Save michael-wolfenden/cd94b4966b12ebfdac53 to your computer and use it in GitHub Desktop.
Save michael-wolfenden/cd94b4966b12ebfdac53 to your computer and use it in GitHub Desktop.
turbo-javascript snippets for vscode
{
//////////////////////////////////////////////////////////////////////
// ASYNC
//////////////////////////////////////////////////////////////////////
"Node callback": {
"prefix": "cb",
"body": [
"function (err, ${1:value}) {$0}"
]
},
"Promise": {
"prefix": "p",
"body": [
"new Promise((resolve, reject) => {",
"\t$0",
"})"
]
},
"Promise.then": {
"prefix": "then",
"body": [
"${1:promise}.then(${2:value} => {",
"\t$0",
"});"
]
},
"chain then": {
"prefix": ".then",
"body": [
".then(${1:value} => {$0})"
]
},
"Promise.catch": {
"prefix": "catch",
"body": [
"${1:promise}.catch(${2:err} => {",
"\t$0",
"});"
]
},
"chain catch": {
"prefix": ".catch",
"body": [
".catch(${1:err} => {$0})"
]
},
//////////////////////////////////////////////////////////////////////
// BDD
//////////////////////////////////////////////////////////////////////
"describe": {
"prefix": "desc",
"body": [
"describe('${1:description}', () => {",
"\t$0",
"});"
]
},
"it asynchronous": {
"prefix": "ita",
"body": [
"it('${1:description}', (done) => {",
"\t$0",
"});"
]
},
"it synchronous": {
"prefix": "it",
"body": [
"it('${1:description}', () => {",
"\t$0",
"});"
]
},
"mocha before": {
"prefix": "bf",
"body": [
"before(() => {",
"\t$0",
"});"
]
},
"mocha beforeEach": {
"prefix": "bfe",
"body": [
"beforeEach(() => {",
"\t$0",
"});"
]
},
"mocha after": {
"prefix": "aft",
"body": [
"after(() => {",
"\t$0",
"});"
]
},
"mocha afterEach": {
"prefix": "afe",
"body": [
"afterEach(() => {",
"\t$0",
"});"
]
},
"chai expect": {
"prefix": "bexpect",
"body": [
"expect(${1:expected}).to.${2:};"
]
},
"chai expect to equal": {
"prefix": "bequal",
"body": [
"expect(${1:expected}).to.equal(${2:value});"
]
},
"chai expect to have length": {
"prefix": "blen",
"body": [
"expect(${1:expected}).to.have.length(${2:length});"
]
},
"chai expect to match": {
"prefix": "bmatch",
"body": [
"expect(${1:expected}).to.match(/${2:match}/i);"
]
},
"chai expect to have property": {
"prefix": "bprop",
"body": [
"expect(${1:expected}).to.match(/${2:match}/i);"
]
},
"chai expect to have been called": {
"prefix": "bcalled",
"body": [
"expect(${1:expected}).to.have.been.called${2:};"
]
},
//////////////////////////////////////////////////////////////////////
// CLASSES
//////////////////////////////////////////////////////////////////////
"class": {
"prefix": "cls",
"body": [
"class ${1:name} {",
"\tconstructor(${2:arguments}) {",
"\t\t$0",
"\t}",
"}"
]
},
"class extends": {
"prefix": "clsex",
"body": [
"class ${1:name} extends ${2:base} {",
"\tconstructor(${3:arguments}) {",
"\t\tsuper(${3:arguments});",
"\t\t$0",
"\t}",
"}"
]
},
//////////////////////////////////////////////////////////////////////
// CONSOLE
//////////////////////////////////////////////////////////////////////
"console.log": {
"prefix": "cl",
"body": [
"console.log('${1:arg}', ${1:arg});"
]
},
"console.error": {
"prefix": "ce",
"body": [
"console.error('${1:arg}', ${1:arg});"
]
},
"console.warn": {
"prefix": "cw",
"body": [
"console.warn('${1:arg}', ${1:arg});"
]
},
//////////////////////////////////////////////////////////////////////
// DECLARATIONS
//////////////////////////////////////////////////////////////////////
"var statement": {
"prefix": "v",
"body": [
"var ${1:name}"
]
},
"var assignment": {
"prefix": "v=",
"body": [
"var ${1:name} = ${2:value}"
]
},
"let statement": {
"prefix": "l",
"body": [
"let ${1:name}"
]
},
"let assignment": {
"prefix": "l=",
"body": [
"let ${1:name} = ${2:value}"
]
},
"const statement": {
"prefix": "c",
"body": [
"const ${1:name}"
]
},
"const assignment": {
"prefix": "c=",
"body": [
"const ${1:name} = ${2:value}"
]
},
//////////////////////////////////////////////////////////////////////
// DOM
//////////////////////////////////////////////////////////////////////
"addEventListener": {
"prefix": "ae",
"body": [
"${1:document}.addEventListener('${2:event}', ${3:ev} => {",
"\t$0",
"});"
]
},
"getElementById": {
"prefix": "gi",
"body": [
"${1:document}.getElementById('${2:id}')"
]
},
"getElementsByClassName": {
"prefix": "gc",
"body": [
"Array.from(${1:document}.getElementsByClassName('${2:class}'))"
]
},
"getElementsByTagName": {
"prefix": "gt",
"body": [
"Array.from(${1:document}.getElementsByTagName('${2:tag}'))"
]
},
"querySelector": {
"prefix": "qs",
"body": [
"${1:document}.querySelector('${2:selector}')"
]
},
"querySelectorAll": {
"prefix": "qsa",
"body": [
"Array.from(${1:document}.querySelectorAll('${2:selector}'))"
]
},
//////////////////////////////////////////////////////////////////////
// FLOW-CONTROL
//////////////////////////////////////////////////////////////////////
"if statement": {
"prefix": "if",
"body": [
"if (${1:condition}) {",
"\t$0",
"}"
]
},
"else statement": {
"prefix": "el",
"body": [
"else {",
"\t$0",
"}"
]
},
"if/else statement": {
"prefix": "ife",
"body": [
"if (${1:condition}) {",
"\t$0",
"} else {",
"\t",
"}"
]
},
"else if statement": {
"prefix": "ei",
"body": [
"else if (${1:condition}) {",
"\t$0",
"}"
]
},
"for loop": {
"prefix": "fl",
"body": [
"for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length; ${1:i} < ${2:len}; ${1:i}++) {",
"\t$0",
"}"
]
},
"for in loop": {
"prefix": "fi",
"body": [
"for (let ${1:key} in ${2:source}) {",
"\tif (${2:source}.hasOwnProperty(${1:key})) {",
"\t\t$0",
"\t}",
"}"
]
},
"for of loop": {
"prefix": "fo",
"body": [
"for (let ${1:key} of ${2:source}) {",
"\t$0",
"}"
]
},
"while loop": {
"prefix": "wl",
"body": [
"while (${1:condition}) {",
"\t$0",
"}"
]
},
"try/catch": {
"prefix": "tc",
"body": [
"try {",
"\t$0",
"} catch (${1:err}) {",
"\t",
"}"
]
},
"try/finally": {
"prefix": "tf",
"body": [
"try {",
"\t$0",
"} finally {",
"\t",
"}"
]
},
"try/catch/finally": {
"prefix": "tcf",
"body": [
"try {",
"\t$0",
"} catch (${1:err}) {",
"\t",
"} finally {",
"\t",
"}"
]
},
//////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////
"anonymous function": {
"prefix": "f",
"body": [
"function (${1:arguments}) {$0}"
]
},
"named function": {
"prefix": "fn",
"body": [
"function ${1:name}(${2:arguments}) {",
"\t$0",
"}"
]
},
"immediately-invoked function expression": {
"prefix": "iife",
"body": [
"(function (${1:arguments}) {",
"\t$0",
"})(${2});"
]
},
"function apply": {
"prefix": "fa",
"body": [
"${1:fn}.apply(${2:this}, ${3:arguments})"
]
},
"function call": {
"prefix": "fc",
"body": [
"${1:fn}.call(${2:this}, ${3:arguments})"
]
},
"function bind": {
"prefix": "fb",
"body": [
"${1:fn}.bind(${2:this}, ${3:arguments})"
]
},
"arrow function": {
"prefix": "afb",
"body": [
"(${1:arguments}) => ${2:statement}"
]
},
"arrow function with body": {
"prefix": "af",
"body": [
"(${1:arguments}) => {",
"\t$0",
"}"
]
},
"generator": {
"prefix": "gf",
"body": [
"function* (${1:arguments}) {",
"\t$0",
"}"
]
},
"named generator": {
"prefix": "gfn",
"body": [
"function* ${1:name}(${2:arguments}) {",
"\t$0",
"}"
]
},
//////////////////////////////////////////////////////////////////////
// ITERABLES
//////////////////////////////////////////////////////////////////////
"forEach loop": {
"prefix": "fe",
"body": [
"${1:iterable}.forEach((${2:item}) => {",
"\t$0",
"});"
]
},
"chain forEach": {
"prefix": ".fe",
"body": [
".forEach((${1:item}) => {$0})"
]
},
"map": {
"prefix": "map",
"body": [
"${1:iterable}.map((${2:item}) => {",
"\t$0",
"});"
]
},
"chain map": {
"prefix": ".map",
"body": [
".map((${1:item}) => {$0})"
]
},
"reduce": {
"prefix": "reduce",
"body": [
"${1:iterable}.reduce((${2:previous}, ${3:current}) => {",
"\t$0",
"}${4:, initial});"
]
},
"chain reduce": {
"prefix": ".reduce",
"body": [
".reduce((${1:previous}, ${2:current}) => {$0}${4:, initial})"
]
},
"filter": {
"prefix": "filter",
"body": [
"${1:iterable}.filter((${2:item}) => {",
"\t$0",
"});"
]
},
"chain filter": {
"prefix": ".filter",
"body": [
".filter((${1:item}) => {$0})"
]
},
"find": {
"prefix": "find",
"body": [
"${1:iterable}.find((${2:item}) => {",
"\t$0",
"});"
]
},
"chain find": {
"prefix": ".find",
"body": [
".find((${1:item}) => {$0})"
]
},
//////////////////////////////////////////////////////////////////////
// MISC
//////////////////////////////////////////////////////////////////////
"use strict": {
"prefix": "us",
"body": [
"'use strict';"
]
},
//////////////////////////////////////////////////////////////////////
// MODULES
//////////////////////////////////////////////////////////////////////
"module export": {
"prefix": "ex",
"body": [
"export ${1:member};"
]
},
"module default export": {
"prefix": "exd",
"body": [
"export default ${1:member};"
]
},
"import module": {
"prefix": "im",
"body": [
"import ${1:*} from '${2:module}';"
]
},
"import module as": {
"prefix": "ima",
"body": [
"import ${1:*} as ${2:name} from '${3:module}';"
]
},
//////////////////////////////////////////////////////////////////////
// NODE-ASSERT
//////////////////////////////////////////////////////////////////////
"assert.equal": {
"prefix": "ase",
"body": [
"assert.equal(${1:actual}, ${2:expected});"
]
},
"assert.notEqual": {
"prefix": "asn",
"body": [
"assert.notEqual(${1:actual}, ${2:expected});"
]
},
"assert.deepEqual": {
"prefix": "asd",
"body": [
"assert.deepEqual(${1:actual}, ${2:expected});"
]
},
//////////////////////////////////////////////////////////////////////
// NODE-EVENTS
//////////////////////////////////////////////////////////////////////
"event handler": {
"prefix": "on",
"body": [
"${1:emitter}.on('${2:event}', (${3:arguments}) => {",
"\t$0",
"});"
]
},
"chain event handler": {
"prefix": ".on",
"body": [
".on('${2:event}', (${3:arguments}) => {$0})"
]
},
//////////////////////////////////////////////////////////////////////
// NODE-EXPRESS
//////////////////////////////////////////////////////////////////////
"Express middleware": {
"prefix": "xm",
"body": [
"function (req, res${1:, next}) {",
"\t$0",
"}"
]
},
"Express error handler": {
"prefix": "xerr",
"body": [
"function (err, req, res, next) {",
"\t$0",
"}"
]
},
//////////////////////////////////////////////////////////////////////
// NODE-MODULES
//////////////////////////////////////////////////////////////////////
"require": {
"prefix": "re",
"body": [
"require('${1:module}');"
]
},
"exports.member": {
"prefix": "em",
"body": [
"exports.${1:member} = ${2:value};"
]
},
"module.exports": {
"prefix": "me",
"body": [
"module.exports = ${1:name};"
]
},
"module as class": {
"prefix": "mc",
"body": [
"var ${1:name} = (function () {",
"\tfunction ${1:name}(${2:arguments}) {",
"\t\t$0",
"\t}",
"\treturn ${1:name};",
"})();",
"",
"module.exports = ${1:name};"
]
},
//////////////////////////////////////////////////////////////////////
// OBJECTS
//////////////////////////////////////////////////////////////////////
"key/value pair": {
"prefix": ":",
"body": [
"${1:key}: ${2:'value'}"
]
},
"method": {
"prefix": "m",
"body": [
"${1:method}(${2:arguments}) {",
"\t$0",
"}"
]
},
"getter": {
"prefix": "get",
"body": [
"get ${1:property}() {",
"\t$0",
"}"
]
},
"setter": {
"prefix": "set",
"body": [
"set ${1:property}(${2:value}) {",
"\t$0",
"}"
]
},
"getter + setter": {
"prefix": "gs",
"body": [
"get ${1:property}() {",
"\t$0",
"}",
"set ${1:property}(${2:value}) {",
"\t",
"}"
]
},
"prototype method": {
"prefix": "proto",
"body": [
"${1:Class}.prototype.${2:method} = function (${3:arguments}) {",
"\t$0",
"};"
]
},
"chain prototype method": {
"prefix": ".proto",
"body": [
".prototype.${2:methodName} = function (${3:arguments}) {",
"\t$0",
"}"
]
},
"Object.assign": {
"prefix": "a",
"body": [
"Object.assign(${1:dest}, ${2:source})"
]
},
//////////////////////////////////////////////////////////////////////
// RETURN
//////////////////////////////////////////////////////////////////////
"return": {
"prefix": "r",
"body": [
"return $0;"
]
},
"return this": {
"prefix": "rth",
"body": [
"return this;"
]
},
"return null": {
"prefix": "rn",
"body": [
"return null;"
]
},
"return true": {
"prefix": "rt",
"body": [
"return true;"
]
},
"return false": {
"prefix": "rf",
"body": [
"return false;"
]
},
"return 0": {
"prefix": "r0",
"body": [
"return 0;"
]
},
"return -1": {
"prefix": "r-1",
"body": [
"return -1;"
]
},
"return promise": {
"prefix": "rp",
"body": [
"return new Promise((resolve, reject) => {",
"\t$0",
"});"
]
},
//////////////////////////////////////////////////////////////////////
// TIMERS
//////////////////////////////////////////////////////////////////////
"setTimeout": {
"prefix": "st",
"body": [
"setTimeout(() => {",
"\t$0",
"}, ${1:delay});"
]
},
"setInterval": {
"prefix": "si",
"body": [
"setInterval(() => {",
"\t$0",
"}, ${1:delay});"
]
},
"setImmediate": {
"prefix": "sim",
"body": [
"setImmediate(() => {",
"\t$0",
"});"
]
},
//////////////////////////////////////////////////////////////////////
// TYPES
//////////////////////////////////////////////////////////////////////
"String": {
"prefix": "S",
"body": [
"String"
]
},
"Number": {
"prefix": "N",
"body": [
"Number"
]
},
"Object": {
"prefix": "O",
"body": [
"Object"
]
},
"Array": {
"prefix": "A",
"body": [
"Array"
]
},
"Date": {
"prefix": "D",
"body": [
"Date"
]
},
"RegExp": {
"prefix": "Rx",
"body": [
"RegExp"
]
},
"typeof": {
"prefix": "tof",
"body": [
"typeof ${1:source} === '${2:undefined}'"
]
},
"instanceof": {
"prefix": "iof",
"body": [
"${1:source} instanceof ${2:Object}"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment