Repository for my javascript projects
Just install JavaScript Snippets by Nathan Chapman
in VScode
Snippets are optimized to be short and easy to remember.
Below is a list of all available snippets and the triggers of each one. The ⇥ means the TAB
key.
var ${0}
var ${1:name} = ${2:value};
let ${0}
let ${1:name} = ${2:value};
let {${1:name}} = ${2:value};
const ${0}
const ${1:name} = ${2:value};
const {${1:name}} = ${2:value};
if (${1:condition}) {
${0}
}
else {
${0}
}
if (${1:condition}) {
${0}
} else {
}
else if (${1:condition}) {
${0}
}
${1:condition} ? ${2:expression} : ${3:expression};
for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length; ${1:i} < ${2:len}; ${1:i}++) {
${0}
}
for (let ${1:i} = ${2:iterable}.length - 1; ${1:i} >= 0; ${1:i}--) {
${0}
}
for (let ${1:key} in ${2:array}) {
if (${2:array}.hasOwnProperty(${1:key})) {
${0}
}
}
},
for (let ${1:key} of ${2:array}) {
${0}
}
while (${1:condition}) {
${0}
}
try {
${0}
} catch (${1:err}) {
}
try {
${0}
} finally {
}
try {
${0}
} catch (${1:err}) {
} finally {
}
switch (${1:expr}) {
case ${2:value}:
return $0;
default:
return;
}
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}) => {
${0}
}
function* (${1:arguments}) {
${0}
}
function* ${1:name}(${2:arguments}) {
${0}
}
[...Array(${1:length}).keys()]${0}
${1}.forEach((${2:item}) => {
${0}
});
${1}.map((${2:item}) => {
${0}
});
${1}.reduce((${2:previous}, ${3:current}) => {
${0}
}${4:, initial});
${1}.filter(${2:item} => {
${0}
});
${1}.find(${2:item} => {
${0}
});
{
kv${0}
};
{ kv${0} };
${1:key}: ${2:value},
class ${1:name} {
constructor(${2:arguments}) {
${0}
}
}
class ${1:name} extends ${2:base} {
constructor(${3:arguments}) {
super(${3:arguments});
${0}
}
}
constructor(${1:arguments}) {
super(${1: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}) {
}
var ${1:Class} = function(${2:arguments}) {
${0}
};
${1:Class}.prototype.${2:method} = function(${3:arguments}) {
${0}
};
Object.assign(${1:dest}, ${2:source})
Object.assign({}, ${1:original}, ${2:source})
return ${0};
return new Promise((resolve, reject) => {
${0}
});
return (
${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};
export default ${1:member};
import ${1:*} from '${2:module}';
import ${1:*} as ${2:name} from '${3:module}';
(err, ${1:value}) => {${0}}
require('${1:module}');
require('./${1:module}');
const ${1:module} = require('${1:module}');
const ${1:module} = require('./${1:module}');
const {${1:module}} = require('${1:module}');
const {${1:module}} = require('./${1:module}');
exports.${1:member} = ${2:value};
module.exports = ${1:name};
module.exports = {
${1:member}
};
${1:emitter}.on('${2:event}', (${3:arguments}) => {
${0}
});
describe('${1:description}', () => {
${0}
});
context('${1:description}', () => {
${0}
});
it('${1:description}', () => {
${0}
});
it('${1:description}', () => {
${0}
});
it('${1:description}', (done) => {
${0}
done();
});
before(() => {
${0}
});
beforeEach(() => {
${0}
});
after(() => {
${0}
});
afterEach(() => {
${0}
});
console.log(${0});
console.error(${0});
console.warn(${0});
console.log('${0}', ${0});
console.error('${0}', ${0});
console.warn('${0}', ${0});
setTimeout(() => {
${0}
}, ${1:delay});
setInterval(() => {
${0}
}, ${1:delay});
setImmediate(() => {
${0}
});
process.nextTick(() => {
${0}
});
'use strict';
If snippets do not show up, add the following to your settings file
"emmet.includeLanguages": {
"ejs": "html",
},
** ejs Snippets are found below.**
→ Denotes the TAB
key.
Snippet→ | Alternate | Output |
---|---|---|
ejs→ |
<% |
<% %> - No output tag |
ejsout→ |
<%= |
<%= %> - Outputs HTML value |
ejsesc→ |
<%- |
<%- %> - Outputs unescaped |
ejscom→ |
<%# |
<%# %> - Comment tag |
ejslit→ |
<%% |
<%% %> - Outputs Literal <% |
ejsinc→ |
<% |
include statement |
ejsfor→ |
<% |
for Javascript Loop |
ejseach→ |
<% |
forEach Javascript Loop |
ejsif→ |
<% |
if Statement with condition |
ejselif→ |
<% |
else if Statement - Middle section only. Assumes you have already written the first if statement. |
ejselse→ |
<% |
else Statement - Middle section only. Assumes you have already written the first if statement. |