Skip to content

My SublimeText 3 snippets. From BDD through `assert` to singleton pattern, es6 fat arrows and es6 import

Notifications You must be signed in to change notification settings

tunnckoCore/javascript-charlike-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javascript-charlike-snippets

My SublimeText 2/3 snippets. From BDD through assert to singleton pattern, es6 fat arrows and es6 import

Rebuilding

zip javascript-charlike-snippets.sublime-package -r javascript-charlike-snippets && cp javascript-charlike-snippets.sublime-package ~/.config/sublime-text-3/Installed\ Packages/

Code Style

standard

This snippets use standard to maintain code style and consistency, and to avoid style arguments. You are encouraged to install it globally.

Table of Contents

  • module system
    • rr node variable require
    • req node require
    • imp javascript import
  • functions-and-arrows
    • fat es6 arrow function
    • ofat es6 arrow function as object property
    • me module.exports
    • men module.exports - named function
    • mea module.exports - anonymous function
    • fn named function
    • afn anonymous function
    • ofn named function as object property
    • oafn anonymous function as object property
    • fixture fixture function (useful when assert.throws)
    • iife immediately-invoked function expression
  • assert
    • ase assert.equal
    • asn assert.notEqual
    • asse assert.strictEqual
    • assn assert.notStrictEqual
    • asd assert.deepEqual
    • asdn assert.notDeepEqual
    • assd assert.deepStrictEqual
    • assdn assert.notDeepStrictEqual
    • asi assert.ifError
    • ast assert.throws(actual, expected, msg)
    • aste assert.throws fixture Error
    • asttype assert.throws fixture TypeError
    • astre assert.throws fixture regexp message
  • testing
    • desc describe
    • ita it async
    • its it sync
  • console and misc
    • cl console.log
    • ce console.error
    • self self this
    • us use strict
    • loop fast while loop
    • singleton singleton pattern
    • var variable assigning, e.g. var foo = bar
    • iftypeof if block with typeof check
    • iferr if block with typeof check and throw TypeError
    • typeof typeof check with strict equality
    • thr throw error
    • thn throw error with new

module system

  • [rr] node variable require
var ${2:pkg} = require('${1:package}')${0}
  • [req] node require
require('${1:package}')${0}
  • [imp] javascript import
import ${2:pkg} from '${1:package}'${0}

functions and arrows

  • [fat] es6 arrow
(${1:args}) => ${0}
  • [ofat] es6 arrow as object property
${1:name}: (${2:args}) => ${0}
  • [me] module.exports
module.exports = ${0}
  • [men] module.exports - named function
module.exports = function ${1:name} (${2:args}) {
  ${0}
}
  • [mea] module.exports - anonymous function
module.exports = function (${2:args}) {
  ${0}
}
  • [fn] named function
function ${1:name} (${2:args}) {
  ${0}
}
  • [afn] anonymous function
function (${1:args}) {
  ${0}
}
  • [ofn] named function as object property
${1:name}: function ${1:name} (${2:args}) {
  ${0}
}
  • [oafn] anonymous function as object property
${1:name}: function (${2:args}) {
  ${0}
}
  • [fixture] fixture function (useful when assert.throws)
function fixture () {
  ${1:fnName}
}${0}

assert

  • [ase] assert equal
${1:assert}.equal(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [asn] assert notEqual
${1:assert}.notEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [asse] assert strictEqual
${1:assert}.strictEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [assn] assert notStrictEqual
${1:assert}.notStrictEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [asd] assert deepEqual
${1:assert}.deepEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [asdn] assert notDeepEqual
${1:assert}.notDeepEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [assd] assert.deepStrictEqual
${1:assert}.deepStrictEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [assdn] assert.notDeepStrictEqual
${1:assert}.notDeepStrictEqual(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [asi] assert.ifError
${1:assert}.ifError(${2:err})${0}
  • [ast] assert.throws
${1:assert}.throws(${2:actual}, ${3:expected}, ${4:msg})${0}
  • [aste] assert.throws fixture Error
${1:assert}.throws(${2:fixture}, Error)${0}
  • [asttype] assert.throws fixture TypeError
${1:assert}.throws(${2:fixture}, TypeError)${0}
  • [astre] assert.throws fixture regexp message
${1:assert}.throws(${2:fixture}, /${3:expected msg}/)${0}

testing

  • [desc] describe
${1:describe}('${2:description}', function () {
  ${0}
})
  • [ita] it async
${1:it}('${2:description}', function (${3:done}) {
  ${0}
  ${4:done}()
})
  • [its] it sync
${1:it}('${2:description}', function () {
  ${0}
})

console and misc

  • [cl] console.log
console.log(${1:actual})${0}
  • [ce] console.error
console.error(${1:actual})${0}
  • [self] self this
var self = this
  • [us] use strict
'use strict'
  • [loop] fast while loop
var len = ${1:arr}.length
var i = 0

while (i < len) {
  var val = ${1:arr}[${2:i++}]
  ${0}
}
  • [singleton] singleton pattern
function ${1:ClassName} (${2:options}) {
  if (!(this instanceof ${1:ClassName})) {
    return new ${1:ClassName}(${2:options})
  }
  ${0}
}
  • [var] variable assigning
var ${2:foo} = ${1:bar}${0}
  • [iftypeof] if block with typeof check
if (typeof ${1:actual} === ${2:expected}) {
  ${0}
}
  • [iferr] if block with typeof check and throw TypeError
if (typeof ${1:actual} === ${2:expected}) {
  throw new ${3:TypeError}('${4:message}')
}${0}
  • [typeof] typeof check with strict equality
typeof ${1:actual} === ${2:expected}
  • [thr] throw error
throw ${1:err}
  • [thn] throw error with new
throw new ${1:TypeError}('${2:message}')${0}

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

My SublimeText 3 snippets. From BDD through `assert` to singleton pattern, es6 fat arrows and es6 import

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published