A collection of commands and ES6 focused snippets for optimizing modern Javascript development productivity. It aims to be compliant with AirBnB's mostly reasonable approach to Javascript.
Note: this is a fork of turbo-javascript that uses arrow functions by default and adds a few more snippets for chai and classes for convenience.
Version 1.0.0
- Uses single quotes to comply with AirBnB guidelines
If you need double quotes please downgrade apm install es6-typescript@0.7.0
Use the following keymaps to speed up your development. You can quickly terminate lines with semicolons or manipulate blocks of code with ease.
Terminates the current line with a semicolon.
Terminates the current line with a comma (great for object literals).
Terminates the current line with a colon or semicolon, followed with a new line. A comma is inserted when the cursor is inside an object literal, otherwise a semicolon is inserted.
Creates a statement block { ... } with the selected text placed inside and properly indented. If the selection is already wrapped with a block, the block is removed and its content is unindented.
Snippets are optimized to be short and easy to remember. Some snippets are "chainable" and render differently when preceded by a ".".
For example, .fe renders a chain-friendly version of the forEach snippet, while fe renders a full code block.
var ${1:name};var ${1:name} = ${2:value};let ${1:name};let ${1:name} = ${2:value};const ${1:name};const ${1:name} = ${2:value};const ${1:name} = Symbol('${1:name}');if (${1:condition}) {
${0}
}else {
${0}
}if (${1:condition}) {
${2}
} else {
${3}
}else if (${1:condition}) {
${0}
}for (let ${1:i} = 0; ${1:i} < ${2:iterable}${3:.length}; ${1:i}++) {
${4}
}for (let ${1:key} in ${2:source}) {
if (${2:source}.hasOwnProperty(${1:key})) {
${0}
}
}for (let ${1:key} of ${2:source}) {
${0}
}while (${1:condition}) {
${0}
}try {
${1}
} catch (${2:err}) {
${3}
}try {
${1}
} finally {
${2}
}try {
${1}
} catch (${2:err}) {
${3}
} finally {
${4}
}function (${1:arguments}) {${0}}function ${1:name}(${2:arguments}) {
${0}
}((${1:arguments}) => {
${0}
})(${2});${1:fn}.apply(${2:this}, ${3:arguments})${1:fn}.call(${2:this}, ${3:arguments})${1:fn}.bind(${2:this}, ${3:arguments})${1:(arguments)} => ${2:statement}${1:(arguments)} => {
\t${0}
}function* (${1:arguments}) {
${0}
}function* ${1:name}(${1:arguments}) {
${0}
}${1:iterable}.forEach((${2:item}) => {
${0}
});${1:iterable}.map((${2:item}) => {
${0}
});${1:iterable}.reduce((${2:previous}, ${3:current}) => {
${0}
}${4:, initial});${1:iterable}.filter((${2:item}) => {
${0}
});${1:iterable}.find((${2:item}) => {
${0}
});class ${1:name} {
constructor(${2:arguments}) {
${0}
}
}class ${1:name} extends ${2:base} {
constructor(${2:arguments}) {
super(${2:arguments})
${0}
}
}{$1:name}({$2:arguments}) {
${0}
}Javascript:
${1:key}: ${2:'value'}${1:method}(${2:arguments}) {
${0}
}get ${1:property}() {
${0}
}set ${1:property}(${2:value}) {
${0}
}get ${1:property}() {
${0}
}
set ${1:property}(${2:value}) {
}${1:Class}.prototype.${2:methodName} = function (${3:arguments}) {
${0}
};return ${0};return this;return null;return true;return false;return 0;return -1;return new Promise((resolve, reject) => {
${0}
});typeof ${1:source} === '${2:undefined}'${1:source} instanceof ${2:Object}new Promise((resolve, reject) => {
${0}
})${1:promise}.then((${2:value}) => {
${0}
});${1:promise}.catch((${2:err}) => {
${0}
});export ${1:member};import ${1:*} from '${2:module}';import ${1:*} as ${2:name} from '${3:module}';import \{ ${1:name} \} from '${2:module}';describe('${1:description}', () => {
${0}
});it('${1:description}', () => {
${0}
});it('${1:description}', (done) => {
${0}
});before(() => {
${0}
});beforeEach(() => {
${0}
});after(() => {
${0}
});afterEach(() => {
${0}
});console.log('${1:title}', ${2:$1}$0);console.log(${0});console.error(${0});console.warn(${0});setTimeout(() => {
${0}
}, ${1:delay});setTimeout(() => {
${0}
}, ${1:delay});setImmediate(() => {
${0}
});${1:document}.addEventListener('${2:event}', function (e) {
${0}
});${1:document}.getElementById('${2:id}')Array.from(${1:document}.getElementsByClassName('${2:class}'))Array.from polyfill required for ES5
Array.from(${1:document}.getElementsByTagName('${2:tag}'))Array.from polyfill required for ES5
${1:document}.querySelector('${2:selector}')Array.from(${1:document}.querySelectorAll('${2:selector}'))Array.from polyfill required for ES5
(err${1:, value}) => {${0}}require('${1:module}');exports.${1:name} = ${2:value};module.exports = ${1:name};${1:emitter}.on('${2:event}', (${3:arguments}) => {
${0}
});'use strict';The MIT License (MIT)