This extension contains code snippets for JavaScript in ES6 syntax for Vs Code editor (supports both JavaScript and TypeScript). It includes snippets for new features released with ECMAScript 2023.
This extension is a fork from the original JavaScript (ES6) code snippets made by xabikos. The original extension is no longer maintained and the author is not accepting pull requests. This fork is maintained by Marco Goedert.
All the snippets include the final semicolon ; There is a fork of those snippets here
made by @jmsv where semicolons are not included. So feel free to use them according to your needs.
Installation
In order to install an extension you need to launch the Command Palette (Ctrl + Shift + P or Cmd + Shift + P) and type Extensions.
There you have either the option to show the already installed snippets or install new ones. Search for JavaScript (ES6) code snippets and install it.
Supported languages (file extensions)
JavaScript (.js)
TypeScript (.ts)
JavaScript React (.jsx)
TypeScript React (.tsx)
Html (.html)
Vue (.vue)
Snippets
Below is a list of all available snippets and the triggers of each one. The ⇥ means the TAB key.
ECMAScript 2023 new features
Trigger
Content
trv→
Returns a new array with reversed elements ${1:array}.toReversed();
tsd→
Returns a new array with sorted elements ${1:array}.toSorted(${2:compareFn});
tsp→
Returns a new array with spliced elements ${1:array}.toSpliced(${2:start}, ${3:deleteCount}, ...${4:items});
with
Returns a new array with a changed value at the specified index ${1:array}.with(${2:index}, ${3:value});
tatrv
Returns a new TypedArray with reversed elements ${1:typedArray}.toReversed();
tatsd
Returns a new TypedArray with sorted elements ${1:typedArray}.toSorted(${2:compareFn});
tawith
Returns a new TypedArray with a changed value at the specified index ${1:typedArray}.with(${2:index}, ${3:value});
fl
Finds the last element in the array that satisfies the condition array.findLast(${1:condition});
fli
Finds the index of the last element in the array that satisfies the condition array.findLastIndex(${1:condition});
tc39/proposal-change-array-by-copy: Provides additional methods on Array.prototype and TypedArray.prototype to enable changes on the array by returning a new copy of it with the change.
tc39/proposal-hashbang: This proposal is to match de-facto usage in some CLI JS hosts that allow for Shebangs / Hashbang. Such hosts strip the hashbang in order to generate valid JS source texts before passing to JS engines currently. This would move the stripping to engines, it does unify and standardize how that is done.
ECMAScript 2022 new features
Trigger
Content
at→
Access the character at the specified index using negative or positive index ${1:target}.at(${2:index});
own→
Check if an object has a specific property Object.hasOwn(${1:object}, ${2:property});
Import and export
Trigger
Content
imp→
imports entire module import fs from 'fs';
imn→
imports entire module without module name import 'animate.css'
imd→
imports only a portion of the module using destructing import {rename} from 'fs';
ime→
imports everything as alias from the module import * as localAlias from 'fs';
ima→
imports only a portion of the module as alias import { rename as localRename } from 'fs';
rqr→
require package require('');
req→
require package to const const packageName = require('packageName');
mde→
default module.exports module.exports = {};
env→
exports name variable export const nameVariable = localVariable;
enf→
exports name function export const log = (parameter) => { console.log(parameter);};
edf→
exports default function export default function fileName (parameter){ console.log(parameter);};
ecl→
exports default class export default class Calculator { };
ece→
exports default class by extending a base one export default class Calculator extends BaseClass { };
Class helpers
Trigger
Content
con→
adds default constructor in the class constructor() {}
met→
creates a method inside a class add() {}
pge→
creates a getter property get propertyName() {return value;}
pse→
creates a setter property set propertyName(value) {}
Various methods
Trigger
Content
fre→
forEach loop in ES6 syntax array.forEach(currentItem => {})
fof→
for ... of loop for(const item of object) {}
fin→
for ... in loop for(const item in object) {}
anfn→
creates an anonymous function (params) => {}
nfn→
creates a named function const add = (params) => {}