originally forked from https://github.com/gaboesquivel/atom-standardjs-snippets, but we've added couple more. Also these are not using special characters because vscode doesn't like them in the snippets.
A collection of ES6 snippets for faster JavaScript development in Atom Editor.
This collection is complementary to atom/language-javascript. It's based on extrabacon/atom-turbo-javascript and it enforces standardjs code style.
Yes!, no semicolons:
- Are Semicolons Necessary in JavaScript?
- An Open Letter to JavaScript Leaders Regarding Semicolons
- JavaScript Semicolon Insertion - Everything You Need to Know
I certainly prefer snippets to have the top priority in the autocompletion. This is not a default settingm but can be enabled by:
"editor.snippetSuggestions": "top",
in your settings.json. Otherwise vscode prefers keywords on the top.
Snippets are optimized to be short and easy to remember. Note that these links work only on github, not on VSCode marketplace:
- declarations
- flow control
- functions
- iterables
- objects and classes
- returning values
- types
- promises
- ES6 modules
- testing
- console
- timers
- DOM
- Node.js
- miscellaneous
var ${1:name}
var ${1:name} = ${2:value}
let ${1:name}
let ${1:name} = await ${2:value}
let ${1:name} = yield ${2:value}
const ${1:name}
const {${1:name}} = ${2:value}
const ${1:name} = await ${2:value}
const ${1:name} = yield ${2:value}
if (${1:condition}) {
${0}
}
else {
${0}
}
if (${1:condition}) {
${0}
} else {
}
else if (${1:condition}) {
${0}
}
for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length ${1:i} < ${2:len}; ${1:i}++) {
${0}
}
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}
}
let ${1:array}Index = ${1:array}.length
while (${1:array}Index--) {
${0}
}
try {
${0}
} catch (${1:err}) {
}
try {
${0}
} finally {
}
try {
${0}
} catch (${1:err}) {
} finally {
}
function (${1:arguments}) {${0}}
function ${1:name}(${2:arguments}) {
${0}
}
async function (${1:arguments}) {
${0}
}
async (${1:arguments}) => {
${0}
}
;(function (${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}) => {
${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}
})
${1:iterable}.every((${2:item}) => {
${0}
})
${1:iterable}.some((${2:item}) => {
${0}
})
class ${1:name} {
constructor(${2:arguments}) {
${0}
}
}
class ${1:name} extends ${2:base} {
constructor(${2:arguments}) {
super(${2:arguments})
${0}
}
}
${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}
}
Object.keys(${1:obj})
Object.create(${1:obj})
Object.assign(${1:dest}, ${2:source})
Object.getOwnPropertyDescriptor(${1:dest}, '${2:prop}')
Object.defineProperty(${1:dest}, '${2:prop}', {
${0}
})
return ${0}
return this
return null
return {
${0}
}
return [
${0}
]
return new Promise((resolve, reject) => {
${0}
})
typeof ${1:source} === '${2:undefined}'
${1:source} instanceof ${2:Object}
Array.isArray(${1:source})
Promise.all([${1:value}])
new Promise((resolve, reject) => {
${0}
})
${1:promise}.then((${2:value}) => {
${0}
})
${1:promise}.catch(error => {
${0}
})
export ${1:member}
export default ${1:member}
export default function ${1:name} (${2:arguments}) {\n\t${0}\n}
export const ${1:member} = ${2:value}
import ${1:*} from '${2:module}'
import ${1:*} as ${2:name} from '${3:module}'
import {$1} from '${2:module}'
describe('${1:description}', function () {
${0}
})
it('${1:description}', function () {
${0}
})
it('${1:description}', function (done) {
${0}
})
before(function () {
${0}
})
beforeEach(function () {
${0}
})
after(function () {
${0}
})
afterEach(function () {
${0}
})
setTimeout(() => {
${0}
}, ${1:delay})
setTimeout(() => {
${0}
}, ${1:delay})
setImmediate(() => {
${0}
})
${1:document}.addEventListener('${2:event}', ${3:ev} => {
${0}
})
${1:document}.removeEventListener('${2:event}', ${3:listener})
ev.preventDefault()
ev.stopPropagation()
return false
${1:document}.getElementById('${2:id}')
Array.from(${1:document}.getElementsByClassName('${2:class}'))
Array.from(${1:document}.getElementsByTagName('${2:tag}'))
${1:document}.querySelector('${2:selector}')
Array.from(${1:document}.querySelectorAll('${2:selector}'))
${1:document}.createDocumentFragment(${2:elem});
${1:document}.createElement(${2:elem});
${1:document}.appendChild(${2:elem});
${1:document}.removeChild(${2:elem});
${1:document}.classList.add('${2:class}');
${1:document}.classList.toggle('${2:class}');
${1:document}.classList.remove('${2:class}');
${1:document}.getAttribute('${2:attr}');
${1:document}.setAttribute('${2:attr}', ${3:value});
${1:document}.removeAttribute('${2:attr}');
function (err, ${1:value}) {
if (err) throw err
t${0}
}
require('${1:module}')
const ${1:module} = require('${1:module}')
exports.${1:name} = ${2:value}
module.exports = ${1:name}
${1:emitter}.on('${2:event}', (${3:arguments}) => {
${0}
})
'use strict'
JSON.stringify($0)
JSON.parse($0)
await ${0}
await Promise.all(${1:value})
await Promise.all(${1:array}.map((${2:value}) => {\n\t${0}\n}))
console.log(${0})
console.error(${0})
console.warn(${0})
console.dir(${0})
If you're not writing react, including them should not really bother you because they are not short as the regular JS snippets. ALso IMHO react is the leading solution for FE apps deserves to be included by default, because any JS dev will have to write some react eventually over the course of his/her careeer. By having them in a single package we can easily make sure --there aren't any conflicts in the trigger prefixes.
- JavaScript (.js)
- TypeScript (.ts)
- JavaScript React (.jsx)
- TypeScript React (.tsx)
These were taken from https://github.com/TimonVS/vscode-react-standard because the maintainer wasn't able to publish a new version for months even when there was a considerable flaw in the released version.
Below is a list of all available snippets and the triggers of each one. The ⇥ means the TAB
key.
Trigger | Content |
---|---|
j→ |
jsx component |
jc→ |
jsx self-closed component |
rcc→ |
class component skeleton |
rccp→ |
class component skeleton with prop types after the class |
rcjc→ |
class component skeleton without import and default export lines |
rcfc→ |
class component skeleton that contains all the lifecycle methods |
rsc→ |
stateless component skeleton |
rscp→ |
stateless component with prop types skeleton |
rpt→ |
empty propTypes declaration |
con→ |
class default constructor with props |
conc→ |
class default constructor with props and context |
est→ |
empty state object |
cwm→ |
componentWillMount method |
cdm→ |
componentDidMount method |
cwr→ |
componentWillReceiveProps method |
scu→ |
shouldComponentUpdate method |
cwup→ |
componentWillUpdate method |
cdup→ |
componentDidUpdate method |
cwun→ |
componentWillUnmount method |
ren→ |
render method |
sst→ |
this.setState with object as parameter |
ssf→ |
this.setState with function as parameter |
props→ |
this.props |
state→ |
this.state |
bnd→ |
binds the this of method inside the constructor |
The following table lists all the snippets that can be used for prop types.
Every snippet regarding prop types begins with pt
so it's easy to group it all together and explore all the available options.
On top of that each prop type snippets has one equivalent when we need to declare that this property is also required.
For example pta
creates the PropTypes.array
and ptar
creates the PropTypes.array.isRequired
Trigger | Content |
---|---|
pta→ |
PropTypes.array, |
ptar→ |
PropTypes.array.isRequired, |
ptb→ |
PropTypes.bool, |
ptbr→ |
PropTypes.bool.isRequired, |
ptf→ |
PropTypes.func, |
ptfr→ |
PropTypes.func.isRequired, |
ptn→ |
PropTypes.number, |
ptnr→ |
PropTypes.number.isRequired, |
pto→ |
PropTypes.object., |
ptor→ |
PropTypes.object.isRequired, |
pts→ |
PropTypes.string, |
ptsr→ |
PropTypes.string.isRequired, |
ptnd→ |
PropTypes.node, |
ptndr→ |
PropTypes.node.isRequired, |
ptel→ |
PropTypes.element, |
ptelr→ |
PropTypes.element.isRequired, |
pti→ |
PropTypes.instanceOf(ClassName), |
ptir→ |
PropTypes.instanceOf(ClassName).isRequired, |
pte→ |
PropTypes.oneOf(['News', 'Photos']), |
pter→ |
PropTypes.oneOf(['News', 'Photos']).isRequired, |
ptet→ |
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
ptetr→ |
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, |
ptao→ |
PropTypes.arrayOf(PropTypes.number), |
ptaor→ |
PropTypes.arrayOf(PropTypes.number).isRequired, |
ptoo→ |
PropTypes.objectOf(PropTypes.number), |
ptoor→ |
PropTypes.objectOf(PropTypes.number).isRequired, |
ptsh→ |
PropTypes.shape({color: PropTypes.string, fontSize: PropTypes.number}), |
ptshr→ |
PropTypes.shape({color: PropTypes.string, fontSize: PropTypes.number}).isRequired, |
The MIT License (MIT)
Copyright (c) 2016, Jiří Špác
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.