Skip to content

Instantly share code, notes, and snippets.

@dmitriyK1
Forked from ngryman/README.md
Created June 22, 2016 14:45
Show Gist options
  • Save dmitriyK1/a76e0c016d9c7994c4dd76b11f05b5d2 to your computer and use it in GitHub Desktop.
Save dmitriyK1/a76e0c016d9c7994c4dd76b11f05b5d2 to your computer and use it in GitHub Desktop.
intellij javascript live templates

intellij javascript live templates

Just a dump of handy live templates I use with IntelliJ. They should also work with WebStorm.

How to

  • Go to settings.
  • Search for live templates.
  • Under the javascript section you should be able to manage your templates.

For each template in this gist:

  • create new template
  • fill abbrevation with the @abbr value.
  • fill description with the @desc value.
  • copy/paste the code.
  • click on edit variables
  • for each variable:
    • fill expression with the {} value of the @param.
    • fill default value with the [] value of the @param.

Contribute

Feel free to enhance or add new live templates. Also feel free to host an export jar file and link it here :)

/** loops */
/**
* @abbr: for
* @desc: for loop
* @param $INDEX$ {jsSuggestIndexName()} [i]
* @param: $ARRAY$ {jsArrayVariable()} [array]
* @param: $VAR$ {decapitalize(jsArrayVariable())} [a]
*/
for (var $INDEX$ = 0, len = $ARRAY$.length; $INDEX$ < len; $INDEX$++) {
var $VAR$ = $ARRAY$[$INDEX$];
$END$
}
/**
* @abbr: rfor
* @desc: reverse for loop
* @param $INDEX$ {jsSuggestIndexName()} [i]
* @param: $ARRAY$ {jsArrayVariable()} [array]
* @param: $VAR$ {decapitalize(jsArrayVariable())} [a]
*/
for (var $INDEX$ = $ARRAY$.length - 1; $INDEX$ >= 0; $INDEX$--) {
var $VAR$ = $ARRAY$[$INDEX$];
$END$
}
/** conditions */
/**
* @abbr: if
* @desc: if
* @param $COND$ {} []
*/
if ($COND$) {
$END$
}
/**
* @abbr: ifel
* @desc: if, else
* @param $COND$ {} []
*/
if ($COND$) {
$END$
}
else {
}
/**
* @abbr: ter
* @desc: ternary operator
* @param $COND$ {} []
* @param: $EXPR$ {} []
*/
$COND$ ? $EXPR$ : $END$;
/** objects */
/**
* @abbr: ctor
* @desc: constructor
* @param $CLASS$ {} [Class]
* @param: $PARAM$ {} []
*/
var $CLASS$ = function($PARAM$) {
$END$
};
/**
* @abbr: m
* @desc: method
* @param $CLASS$ {jsQualifiedClassName()} [Class]
* @param $FN$ {jsMethodName()} [fn]
* @param $PARAMS$ {} [params]
*/
$CLASS$.prototype.$FN$ = function($PARAMS$) {
$END$
};
/**
* @abbr: t
* @desc: this
* @param $PROP$ {completeSmart()} []
*/
this.$PROP$;
$END$
/**
* @abbr: o
* @desc: literal object
*/
{
p$END$
};
/**
* @abbr: p
* @desc: literal property
*/
$PROP$: $VAL$,
$END$
/**
* @abbr: so
* @desc: same line literal object
*/
{ sp$END$ };
/**
* @abbr: sp
* @desc: same line literal property
*/
$PROP$: $VAL$, $END$
/** misc */
/**
* @abbr: cl
* @desc: closure
*/
(function() {
$END$
})();
/**
* @abbr: f
* @desc: function
* @param $FN$ {jsMethodName()} [fn]
* @param: $PARAMS$ {} []
*/
function $FN$($PARAMS$) {
$END$
};
/**
* @abbr: us
* @desc: use strict
*/
"use strict";
$END$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment