StandardSnippets
JavaScript Standard Style snippets for Sublime Text
Details
Installs
- Total 1K
- Win 742
- Mac 456
- Linux 266
Dec 21 | Dec 20 | Dec 19 | Dec 18 | Dec 17 | Dec 16 | Dec 15 | Dec 14 | Dec 13 | Dec 12 | Dec 11 | Dec 10 | Dec 9 | Dec 8 | Dec 7 | Dec 6 | Dec 5 | Dec 4 | Dec 3 | Dec 2 | Dec 1 | Nov 30 | Nov 29 | Nov 28 | Nov 27 | Nov 26 | Nov 25 | Nov 24 | Nov 23 | Nov 22 | Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
Standard JavaScript Snippets for Sublime Text
A collection of standardjs code style snippets for JavaScript development in Sublime Text.
Yes!, no semicolons: - Are Semicolons Necessary in JavaScript? - An Open Letter to JavaScript Leaders Regarding Semicolons - JavaScript Semicolon Insertion - Everything You Need to Know
Installation
Installation via Package Control
- Open PackageControl (Ctrl+Shift+P).
- Type and press 'Install Package'.
- Find and install 'StandardSnippets'
Manual installation
- Preferences - Browse Packages.
- Add content of this repo anywhere.
Disabling default snippets
You don't need them with this beautiful package!
- Install PackageResourceViewer via Package Control (Ctrl+Shift+P - Install Package - PackageResourceViewer).
- Extract JavaScript package (Ctrl+Shift+P - Extract - JavaScript).
- Open packages folder (Preferences - Browse Packages).
- Remove JavaScript/Snippets and rename JavaScript folder to any other (e.g. JavaScript-custom).
- Add JavaScript to ignored packages (Ctrl+Shift+P - Disable Package - JavaScript)
Contents
- declarations
- flow control
- functions
- iterables
- objects and classes
- returning values
- types
- promises
- ES6 modules
- testing
- console
- timers
- DOM
- Node.js
- miscellaneous
Declarations
l⇥
let assignment
let ${1:name} = ${2:value}
co⇥
const assignment
const ${1:name} = ${2:value}
yi⇥
const assignment
yield ${1:value}
Flow Control
if⇥
if statement
if (${1:condition}) {
${0}
}
el⇥
else statement
else {
${0}
}
ife⇥
else statement
if (${1:condition}) {
${0}
} else {
}
ei⇥
else if statement
else if (${1:condition}) {
${0}
}
for⇥
for loop
for (let ${1:i} = ${2:start}; ${1:i} < ${3:end}; ${1:i} += 1) {
${0}
}
rfor⇥
reversed for loop
for (let ${1:i} = ${2:start}; ${1:i} >= ${3:end}; ${1:i} -= 1) {
${0}
}
fi⇥
for in loop
for (const ${1:key} in ${2:collection}) {
${0}
}
fo⇥
for of loop
for (const ${1:value} of ${2:collection}) {
${0}
}
}
wl⇥
while loop
while (${1:condition}) {
${0}
}
tc⇥
try/catch
try {
${0}
} catch (${1:err}) {
}
tf⇥
try/finally
try {
${0}
} finally {
}
tcf⇥
try/catch/finally
try {
${0}
} catch (${1:err}) {
} finally {
}
Functions
fun⇥
anonymous function
function (${1:arguments}) {
${0}
}
fn⇥
named function
function ${1:name} (${2:arguments}) {
${0}
}
fas⇥
function assignment
const ${1:name} = function ${1:name} (${2:arguments}) {
${0}
}
iife⇥
immediately-invoked function expression (IIFE)
;(function (${1:arguments}) {
${0}
})(${2})
af⇥
arrow function
(${1:arguments}) => ${2:statement}
afb⇥
arrow function with body
(${1:arguments}) => {
${0}
}
gfun⇥
generator function
function* (${1:arguments}) {
${0}
}
gfn⇥
named generator function
function* ${1:name}(${1:arguments}) {
${0}
}
gfn⇥
generator assignment
const ${1:name} = function* ${1:name} (${2:arguments}) {
${0}
}
Iterables
fe⇥
forEach loop
forEach((${2:item}) => {
${0}
})
map⇥
map function
map((${2:item}) => {
${0}
})
reduce⇥
reduce function
reduce((${2:previous}, ${3:current}) => {
${0}
}${4:, initial})
filter⇥
filter function
filter((${2:item}) => {
${0}
})
find⇥
ES6 find function
find((${2:item}) => {
${0}
})
every⇥
every function
every((${2:item}) => {
${0}
})
some⇥
some function
some((${2:item}) => {
${0}
})
Objects and classes
cs⇥
class (ES6)
class ${1:name} {
constructor(${2:arguments}) {
${0}
}
}
csx⇥
child class (ES6)
class ${1:name} extends ${2:base} {
constructor(${2:arguments}) {
super(${2:arguments})
${0}
}
}
kv⇥
key/value pair
Javascript:
${1:key}: ${2:'value'}
JSON:
"${1:key}": ${2:"value"}
m⇥
method (ES6 syntax)
${1:method}(${2:arguments}) {
${0}
}
proto⇥
prototype method (chainable)
${1:Class}.prototype.${2:methodName} = function (${3:arguments}) {
${0}
}
ok
Object.keys
Object.keys(${1:obj})
oa
Object.assign
Object.assign(${1:dest}, ${2:source})
hop⇥
has own property
Object.prototype.hasOwnProperty.call(${1:object}, ${2:key})
Returning values
ret⇥
return
return ${0}
rp⇥
return Promise (ES6)
return new Promise((resolve, reject) => {
${0}
})
Types
S⇥
String
N⇥
Number
O⇥
Object
A⇥
Array
D⇥
Date
Rx⇥
RegExp
tof⇥
typeof comparison
typeof ${1:source} === '${2:undefined}'
iof⇥
instanceof comparison
${1:source} instanceof ${2:Object}
ia⇥
isArray
Array.isArray(${1:source})
Promises
p⇥
new Promise (ES6)
new Promise((resolve, reject) => {
${0}
})
then⇥
Promise.then (chainable)
${1:promise}.then((${2:value}) => {
${0}
})
catch⇥
Promise.catch (chainable)
${1:promise}.catch((${2:err}) => {
${0}
})
ES6 modules
exp⇥
module export
export ${1:member}
exd⇥
module default export
export default ${1:member}
imp⇥
module import
import ${1:*} from '${2:module}'
ima⇥
module import as
import ${1:*} as ${2:name} from '${3:module}'
imd⇥
module import destructuring
import {$1} from '${2:module}'
BDD testing (Mocha, Jasmine, etc.)
desc⇥
describe
describe('${1:description}', function () {
${0}
})
its⇥
synchronous “it”
it('${1:description}', function () {
${0}
})
ita⇥
asynchronous “it”
it('${1:description}', function (done) {
${0}
})
bf⇥
before test suite
before(function () {
${0}
})
bfe⇥
before each test
beforeEach(function () {
${0}
})
aft⇥
after test suite
after(function () {
${0}
})
afe⇥
after each test
afterEach(function () {
${0}
})
Timers
st⇥
setTimeout
setTimeout(() => {
${0}
}, ${1:delay})
si⇥
setInterval
setInterval(() => {
${0}
}, ${1:delay})
sim⇥
setImmediate
setImmediate(() => {
${0}
})
DOM
ae⇥
addEventListener
${1:document}.addEventListener('${2:event}', ${3:ev} => {
${0}
})
rel⇥
removeEventListener
${1:document}.removeEventListener('${2:event}', ${3:listener})
gi⇥
getElementById
${1:document}.getElementById('${2:id}')
gc⇥
getElementsByClassName
Array.from(${1:document}.getElementsByClassName('${2:class}'))
gt⇥
getElementsByTagName
Array.from(${1:document}.getElementsByTagName('${2:tag}'))
qs⇥
querySelector
${1:document}.querySelector('${2:selector}')
qsa⇥
querySelectorAll
Array.from(${1:document}.querySelectorAll('${2:selector}'))
cdf⇥
createDocumentFragment
${1:document}.createDocumentFragment(${2:elem});
cel⇥
createElement
${1:document}.createElement(${2:elem});
ac⇥
appendChild
${1:document}.appendChild(${2:elem});
rc⇥
removeChild
${1:document}.removeChild(${2:elem});
cla⇥
classList.add
${1:document}.classList.add('${2:class}');
ct⇥
classList.toggle
${1:document}.classList.toggle('${2:class}');
cr⇥
classList.remove
${1:document}.classList.remove('${2:class}');
ga⇥
getAttribute
${1:document}.getAttribute('${2:attr}');
sa⇥
setAttribute
${1:document}.setAttribute('${2:attr}', ${3:value});
ra⇥
removeAttribute
${1:document}.removeAttribute('${2:attr}');
Node.js
cb⇥
Node.js callback
(err, ${1:arguments}) => {
if (err) {
throw err
}
${0}
}
req⇥
require a module
require('${1:module}')
cre⇥
require and assign a module
const ${1:module} = require('${2:module}')
em⇥
export member
exports.${1:name} = ${2:value}
me⇥
module.exports
module.exports = ${1:name}
on⇥
attach an event handler
on('${1:event}', (${2:arguments}) => {
${0}
})
xm⇥
Express middleware
(req, res${1:, next}) => {
${0}
}
xerr⇥
Express error handler
(err, req, res, next) => {
${0}
}
Miscellaneous
us⇥
use strict
'use strict'
js⇥
JSON Stringify
JSON.stringify($0)
jp⇥
JSON Parse
JSON.parse($0)
car⇥
copy array
const ${1:copy} = [...${2:original}${3:, new}]
cas⇥
copy assign
const ${1:copy} = { ...${2:original}${3:, new} }
swap⇥
swap values
[${1}, ${2}] = [${2}, ${1}]
Console
cl⇥
console.log
console.log(${0})
ce⇥
console.error
console.error(${0})
cw⇥
console.warn
console.warn(${0})
cd⇥
console.dir
console.dir(${0})
Contributing
More than happy to accept external contributions to the project in the form of feedback, bug reports and even better pull requests. Please read the contributing guidelines
Related Repositories
Alternatives to Standard Style
- Semistandard - standard, with semicolons
- XO - JavaScript happiness style, by Sindre Sorhus
License
The MIT License (MIT)
Copyright © 2017, Vlad Khitev
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.