diff --git a/.editorconfig b/.editorconfig index b263602..4defa9d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,13 +1,13 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - -root = true - -[*] -end_of_line = lf -insert_final_newline = false -indent_style = tab -indent_size = 4 -end_of_line = lf -charset = utf-8 +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +insert_final_newline = false +indent_style = tab +indent_size = 4 +end_of_line = lf +charset = utf-8 trim_trailing_whitespace = true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4cee540..c149751 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ -language: node_js -node_js: +language: node_js +node_js: - 0.10 \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index e45eee3..fbcaf1e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,31 +1,31 @@ -module.exports = function(grunt) { - grunt.initConfig({ - bump: { - options: { - files: ['package.json'], - commit: true, - commitMessage: 'Release v%VERSION%', - commitFiles: ['package.json'], - createTag: true, - tagName: '%VERSION%', - tagMessage: '', - push: true, - pushTo: 'origin' - } - }, - - lintspaces: { - all: { - src: ['*'], - options: { - editorconfig: '.editorconfig' - } - } - } - }); - - grunt.loadNpmTasks('grunt-bump'); - grunt.loadNpmTasks('grunt-lintspaces'); - - grunt.registerTask('default', ['lintspaces']); +module.exports = function(grunt) { + grunt.initConfig({ + bump: { + options: { + files: ['package.json'], + commit: true, + commitMessage: 'Release v%VERSION%', + commitFiles: ['package.json'], + createTag: true, + tagName: '%VERSION%', + tagMessage: '', + push: true, + pushTo: 'origin' + } + }, + + lintspaces: { + all: { + src: ['*'], + options: { + editorconfig: '.editorconfig' + } + } + } + }); + + grunt.loadNpmTasks('grunt-bump'); + grunt.loadNpmTasks('grunt-lintspaces'); + + grunt.registerTask('default', ['lintspaces']); }; \ No newline at end of file diff --git a/README.md b/README.md index 64f0755..6e1ee62 100644 --- a/README.md +++ b/README.md @@ -1,397 +1,421 @@ -# JavaScript Snippets for Sublime - -## description - -This is a JavaScript Snippets package for [IMWeb team](https://github.com/imweb), it unifies the js snippets for IMWeb team.
-The snippets of this package make a standard list in [Code Guide of IMWeb team](http://imweb.github.io/CodeGuide/#snippets) - -## Install - -To install through [Package Control](http://wbond.net/sublime_packages/package_control), -search for **JavaScript Snippets for IMWeb**. If you still don't have Package Control in Sublime Text, [go get it](http://wbond.net/sublime_packages/package_control/installation). -It's pure awesomeness. - -If you prefer to install it manually, you can download the package and put it inside your `Packages` directory. It should work but will not update automatically. - -## Console - -### [cd] console.dir - -```javascript -console.dir(${1:obj}); -``` - -### [cl] console.log - -```javascript -console.log(${1:obj}); -``` - -## EJS - -### [=fo] <% for %> - -``` javascript -<% for (var ${1:i} = ${2:0}, ${3:l} = ${4:arr}.length; ${1:i} < ${3:l}; ++${1:i}) { %> - ${5} -<% } %> -``` - -### [=if] <% if %> - -``` javascript -<% if(${1:expr}) { %> - ${2} -<% } %> -``` - -### [=] <%= %> - -```javascript -<%${1:=} ${2:expr} %> -``` - -## For - -### [fe] forEach - -```javascript -${1:myArray}.forEach(function(${2:elem}, ${3:index}) { - ${4} -}); -``` - -### [fi] for...in - -```javascript -for (${1:prop} in ${2:obj}) { - if (${2:obj}.hasOwnProperty(${1:prop})) { - ${3} - } -} -``` - -### [for] for - -```javascript -for (var ${1:i} = ${2:0}, ${3:l} = ${4:arr}.length; ${1:i} < ${3:l}; ++${1:i}) { - ${5} -} -``` - -## Function - -### [fn][fun] function - -```javascript -function ${1:functionName}(${2:arguments}) { - ${3:// body...} -} -``` - -### [afn] anonymous function - -```javascript -function(${1:arguments}) { - ${2:// body...} -} -``` - -### [ap] apply - -```javascript -apply(${1:context}, [${2:arguments}]); -``` - -### [ca] call - -```javascript -call(${1:context}, ${2:arguments}); -``` - -### [iif] immediately-invoked function expression - -```javascript -(function(${2:win}) { - ${3:// body...} -})(${1:window}); -``` - -### [ofn] function as a property of an object - -```javascript -${1:functionName}: function(${2:arguments}) { - ${3:// body...} -}, -``` - -## If - -### [ife] if...else - -```javascript -if (${1:expr}) { - ${2:// if body...} -} else { - ${3} -} -``` - -## Jquery - -### [jvt] var $this = $(this) - -```javascript -var \$this = \$(this); -``` - -### [jve] var $var = $('var') - -```javascript -var \$${1} = \$('${2}'); -``` - -### [jvd] var d = $d.data('d') - -```javascript -var ${1:cid} = \$${2:this}.data('${3:cid}'); -``` - -### [da] data() - -```javascript -data('${1}') -``` - -### [jext] $.extend - -```javascript -\$.extend(${1}); -``` - -### [ext] extend() - -```javascript -extend(${1}) -``` - -### [jat] $.attr - -```javascript -\$${1:this}.attr('${2}'${3}); -``` - -### [at] attr() - -```javascript -attr('${1}'${2}) -``` - -### [jcss] $.css - -```javascript -\$${1:this}.css({${2}}); -``` - -### [css] css() - -```javascript -css({${2}}) -``` - -### [jwi] $.width - -```javascript -\$${1:this}.width(${2}); -``` - -### [wi] width() - -```javascript -width(${1}) -``` - -### [jhe] $.height - -```javascript -\$${1:this}.height(${2}); -``` - -### [he] height() - -```javascript -height(${1}) -``` - -### [jsh] $.show - -```javascript -\$${1:this}.show(); -``` - -### [sh] show() - -```javascript -show() -``` - -### [jhi] $.hide - -```javascript -\$${1:this}.hide(); -``` - -### [hi] hide() - -```javascript -hide() -``` - -### [jac] $.addClass - -```javascript -\$${1:this}.addClass('${2}'); -``` - -### [addC] addClass() - -```javascript -addClass('${1}') -``` - -### [jrc] $.removeClass - -```javascript -\$${1:this}.removeClass('${2}'); -``` - -### [rem] removeClass() - -```javascript -removeClass('${1}') -``` - -### [jon] $.on - -```javascript -\$${1:this}.on('${2:click}', ${3}function(e${4}) { - ${5:// body...} -}); -``` - -### [on] on() - -```javascript -on('${1:click}', ${2}function(e${3}) { - ${4:// body...} -}); -``` - -### [jtri] $.trigger - -```javascript -\$${1:doc}.trigger('${2:eventType}'${3}); -``` - -### [tri] trigger() - -```javascript -trigger('${1:eventType}'${2}); -``` - -## MISC - -### [vs] var self = this - -```javascript -var ${1:self} = this; -``` - -### [se] self = this - -```javascript -self = this; -``` - -### [th] that = this - -```javascript -that = this; -``` - -### [al] alert - -```javascript -alert('${1:msg}'); -``` - -### [de] debugger - -```javascript -debugger; -``` - -### [ret] return - -```javascript -return ${1:this}; -``` - -### [ni] new Image - -```javascript -new Image().src = '/${1}'; -``` - -## Node - -### [re] require - -```javascript -require('${1:module}'); -``` - -### [rea] require.async - -```javascript -require.async(['${1:moduleName}'], function(${2:module}) { - ${3:// body...} -}); -``` - -### [me] module.exports - -```javascript -module.exports = {${1}}; -``` - -## Timer - -### [st][setT] setTimeout - -```javascript -setTimeout(function() { - ${2:// body...} -}, ${1:delay}); -``` - -### [si][setI] setInterval - -```javascript -setInterval(function() { - ${2:// body...} -}, ${1:delay}); -``` - -## Contributing - -1. Fork it! -2. Create your feature branch: `git checkout -b my-new-feature` -3. Commit your changes: `git commit -m 'Add some feature'` -4. Push to the branch: `git push origin my-new-feature` -5. Submit a pull request :D - -## History - -Check [Releases](https://github.com/imweb/sublime-js-snippets/releases) for detailed changelog. - +# JavaScript Snippets for Sublime + +## description + +This is a JavaScript Snippets package for [IMWeb team](https://github.com/imweb), it unifies the js snippets for IMWeb team.
+The snippets of this package make a standard list in [Code Guide of IMWeb team](http://imweb.github.io/CodeGuide/#snippets) + +## Install + +To install through [Package Control](http://wbond.net/sublime_packages/package_control), +search for **JavaScript Snippets for IMWeb**. If you still don't have Package Control in Sublime Text, [go get it](http://wbond.net/sublime_packages/package_control/installation). +It's pure awesomeness. + +If you prefer to install it manually, you can download the package and put it inside your `Packages` directory. It should work but will not update automatically. + +## Console + +### [cd] console.dir + +```javascript +console.dir(${1:obj}); +``` + +### [cl] console.log + +```javascript +console.log(${1:obj}); +``` + +## EJS + +### [=fo] <% for %> + +``` javascript +<% for (var ${1:i} = ${2:0}, ${3:l} = ${4:arr}.length; ${1:i} < ${3:l}; ++${1:i}) { %> + ${5} +<% } %> +``` + +### [=if] <% if %> + +``` javascript +<% if(${1:expr}) { %> + ${2} +<% } %> +``` + +### [=] <%= %> + +```javascript +<%${1:=} ${2:expr} %> +``` + +## For + +### [fe] forEach + +```javascript +${1:myArray}.forEach(function(${2:elem}, ${3:index}) { + ${4} +}); +``` + +### [fi] for...in + +```javascript +for (${1:prop} in ${2:obj}) { + if (${2:obj}.hasOwnProperty(${1:prop})) { + ${3} + } +} +``` + +### [for] for + +```javascript +for (var ${1:i} = ${2:0}, ${3:l} = ${4:arr}.length; ${1:i} < ${3:l}; ++${1:i}) { + ${5} +} +``` + +## Function + +### [fn][fun] function + +```javascript +function ${1:functionName}(${2:arguments}) { + ${3:// body...} +} +``` + +### [afn] anonymous function + +```javascript +function(${1:arguments}) { + ${2:// body...} +} +``` + +### [ap] apply + +```javascript +apply(${1:context}, [${2:arguments}]); +``` + +### [ca] call + +```javascript +call(${1:context}, ${2:arguments}); +``` + +### [iif] immediately-invoked function expression + +```javascript +(function(${2:win}) { + ${3:// body...} +})(${1:window}); +``` + +### [ofn] function as a property of an object + +```javascript +${1:functionName}: function(${2:arguments}) { + ${3:// body...} +}, +``` + +## If + +### [ife] if...else + +```javascript +if (${1:expr}) { + ${2:// if body...} +} else { + ${3} +} +``` + +## Jquery + +### [jvt] var $this = $(this) + +```javascript +var \$this = \$(this); +``` + +### [jct] const $this = $(this) + +```javascript +const \$this = \$(this); +``` + +### [jve] var $var = $('var') + +```javascript +var \$${1} = \$('${2}'); +``` + +### [jce] const $var = $('var') + +```javascript +const \$${1} = \$('${2}'); +``` + +### [jvd] var d = $d.data('d') + +```javascript +var ${1:cid} = \$${2:this}.data('${3:cid}'); +``` + +### [jcd] const d = $d.data('d') + +```javascript +const ${1:cid} = \$${2:this}.data('${3:cid}'); +``` + +### [da] data() + +```javascript +data('${1}') +``` + +### [jext] $.extend + +```javascript +\$.extend(${1}); +``` + +### [ext] extend() + +```javascript +extend(${1}) +``` + +### [jat] $.attr + +```javascript +\$${1:this}.attr('${2}'${3}); +``` + +### [at] attr() + +```javascript +attr('${1}'${2}) +``` + +### [jcss] $.css + +```javascript +\$${1:this}.css({${2}}); +``` + +### [css] css() + +```javascript +css({${2}}) +``` + +### [jwi] $.width + +```javascript +\$${1:this}.width(${2}); +``` + +### [wi] width() + +```javascript +width(${1}) +``` + +### [jhe] $.height + +```javascript +\$${1:this}.height(${2}); +``` + +### [he] height() + +```javascript +height(${1}) +``` + +### [jsh] $.show + +```javascript +\$${1:this}.show(); +``` + +### [sh] show() + +```javascript +show() +``` + +### [jhi] $.hide + +```javascript +\$${1:this}.hide(); +``` + +### [hi] hide() + +```javascript +hide() +``` + +### [jac] $.addClass + +```javascript +\$${1:this}.addClass('${2}'); +``` + +### [addC] addClass() + +```javascript +addClass('${1}') +``` + +### [jrc] $.removeClass + +```javascript +\$${1:this}.removeClass('${2}'); +``` + +### [rem] removeClass() + +```javascript +removeClass('${1}') +``` + +### [jon] $.on + +```javascript +\$${1:this}.on('${2:click}', ${3}function(e${4}) { + ${5:// body...} +}); +``` + +### [on] on() + +```javascript +on('${1:click}', ${2}function(e${3}) { + ${4:// body...} +}); +``` + +### [jtri] $.trigger + +```javascript +\$${1:doc}.trigger('${2:eventType}'${3}); +``` + +### [tri] trigger() + +```javascript +trigger('${1:eventType}'${2}); +``` + +## MISC + +### [vs] var self = this + +```javascript +var ${1:self} = this; +``` + +### [cs] const self = this + +```javascript +const ${1:self} = this; +``` + +### [se] self = this + +```javascript +self = this; +``` + +### [th] that = this + +```javascript +that = this; +``` + +### [al] alert + +```javascript +alert('${1:msg}'); +``` + +### [de] debugger + +```javascript +debugger; +``` + +### [ret] return + +```javascript +return ${1:this}; +``` + +### [ni] new Image + +```javascript +new Image().src = '/${1}'; +``` + +## Node + +### [re] require + +```javascript +require('${1:module}'); +``` + +### [rea] require.async + +```javascript +require.async(['${1:moduleName}'], function(${2:module}) { + ${3:// body...} +}); +``` + +### [me] module.exports + +```javascript +module.exports = {${1}}; +``` + +## Timer + +### [st][setT] setTimeout + +```javascript +setTimeout(function() { + ${2:// body...} +}, ${1:delay}); +``` + +### [si][setI] setInterval + +```javascript +setInterval(function() { + ${2:// body...} +}, ${1:delay}); +``` + +## Contributing + +1. Fork it! +2. Create your feature branch: `git checkout -b my-new-feature` +3. Commit your changes: `git commit -m 'Add some feature'` +4. Push to the branch: `git push origin my-new-feature` +5. Submit a pull request :D + +## History + +Check [Releases](https://github.com/imweb/sublime-js-snippets/releases) for detailed changelog. + diff --git a/console-dir.sublime-snippet b/console-dir.sublime-snippet index 0f2dbde..58eaadc 100644 --- a/console-dir.sublime-snippet +++ b/console-dir.sublime-snippet @@ -1,8 +1,8 @@ - - - cd - source.js - console.dir + + + cd + source.js + console.dir \ No newline at end of file diff --git a/console-log.sublime-snippet b/console-log.sublime-snippet index 9cf556f..4860786 100644 --- a/console-log.sublime-snippet +++ b/console-log.sublime-snippet @@ -1,8 +1,8 @@ - - - cl - source.js - console.log + + + cl + source.js + console.log \ No newline at end of file diff --git a/for-each.sublime-snippet b/for-each.sublime-snippet index 2655f58..b5d7868 100644 --- a/for-each.sublime-snippet +++ b/for-each.sublime-snippet @@ -1,10 +1,10 @@ - - - fe - source.js - forEach + + + fe + source.js + forEach \ No newline at end of file diff --git a/for-in.sublime-snippet b/for-in.sublime-snippet index 5dcdee7..1ef6eec 100644 --- a/for-in.sublime-snippet +++ b/for-in.sublime-snippet @@ -1,12 +1,12 @@ - - - fi - source.js - for in - + + + fi + source.js + for in + diff --git a/function-anonymous.sublime-snippet b/function-anonymous.sublime-snippet index a6b5b63..9453457 100644 --- a/function-anonymous.sublime-snippet +++ b/function-anonymous.sublime-snippet @@ -1,10 +1,10 @@ - - - afn - source.js - anonymous function + + + afn + source.js + anonymous function \ No newline at end of file diff --git a/function-apply.sublime-snippet b/function-apply.sublime-snippet index 4521fbc..7b8248e 100644 --- a/function-apply.sublime-snippet +++ b/function-apply.sublime-snippet @@ -1,8 +1,8 @@ - - - ap - source.js - method.apply() + + + ap + source.js + method.apply() \ No newline at end of file diff --git a/function-call.sublime-snippet b/function-call.sublime-snippet index 50bc0fd..dd47fcb 100644 --- a/function-call.sublime-snippet +++ b/function-call.sublime-snippet @@ -1,8 +1,8 @@ - - - ca - source.js - method.call() + + + ca + source.js + method.call() \ No newline at end of file diff --git a/function-iife.sublime-snippet b/function-iife.sublime-snippet index 9d8e3b1..5530bdd 100644 --- a/function-iife.sublime-snippet +++ b/function-iife.sublime-snippet @@ -1,10 +1,10 @@ - - - iif - source.js - immediately-invoked function expression + + + iif + source.js + immediately-invoked function expression \ No newline at end of file diff --git a/function-objectProperty.sublime-snippet b/function-objectProperty.sublime-snippet index 81c3a1f..6b95cf3 100644 --- a/function-objectProperty.sublime-snippet +++ b/function-objectProperty.sublime-snippet @@ -1,10 +1,10 @@ - - - ofn - source.js - function as a property of an object + + + ofn + source.js + function as a property of an object \ No newline at end of file diff --git a/function.sublime-snippet b/function.sublime-snippet index 4cd5ba6..fa19795 100644 --- a/function.sublime-snippet +++ b/function.sublime-snippet @@ -1,10 +1,10 @@ - - - fn - source.js - function + + + fn + source.js + function \ No newline at end of file diff --git a/function2.sublime-snippet b/function2.sublime-snippet index d390a21..4767376 100644 --- a/function2.sublime-snippet +++ b/function2.sublime-snippet @@ -1,10 +1,10 @@ - - - fun - source.js - function + + + fun + source.js + function \ No newline at end of file diff --git a/jquery-getDataES.sublime-snippet b/jquery-getDataES.sublime-snippet new file mode 100644 index 0000000..109de59 --- /dev/null +++ b/jquery-getDataES.sublime-snippet @@ -0,0 +1,11 @@ + + + + + jcd + const v = $.data + + source.js, storage.type.js + \ No newline at end of file diff --git a/jquery-getJqueryEleES.sublime-snippet b/jquery-getJqueryEleES.sublime-snippet new file mode 100644 index 0000000..a1aca8e --- /dev/null +++ b/jquery-getJqueryEleES.sublime-snippet @@ -0,0 +1,11 @@ + + + + + jce + $x=$('xxx'); + + source.js, keyword.operator.js + \ No newline at end of file diff --git a/jquery-getThisES.sublime-snippet b/jquery-getThisES.sublime-snippet new file mode 100644 index 0000000..4e56e65 --- /dev/null +++ b/jquery-getThisES.sublime-snippet @@ -0,0 +1,11 @@ + + + + + jct + const $this = $(this); + + source.js, storage.type.js + \ No newline at end of file diff --git a/misc-alert.sublime-snippet b/misc-alert.sublime-snippet index a44d8d5..cc7e482 100644 --- a/misc-alert.sublime-snippet +++ b/misc-alert.sublime-snippet @@ -1,8 +1,8 @@ - - - al - source.js - alert + + + al + source.js + alert \ No newline at end of file diff --git a/misc-debugger.sublime-snippet b/misc-debugger.sublime-snippet index 2abe63b..a117666 100644 --- a/misc-debugger.sublime-snippet +++ b/misc-debugger.sublime-snippet @@ -1,8 +1,8 @@ - - - de - source.js - debugger + + + de + source.js + debugger \ No newline at end of file diff --git a/misc-saveContextES.sublime-snippet b/misc-saveContextES.sublime-snippet new file mode 100644 index 0000000..070a198 --- /dev/null +++ b/misc-saveContextES.sublime-snippet @@ -0,0 +1,11 @@ + + + + + cs + const xxx = this; + + source.js + \ No newline at end of file diff --git a/node-moduleExports.sublime-snippet b/node-moduleExports.sublime-snippet index ca9d28e..10f6db2 100644 --- a/node-moduleExports.sublime-snippet +++ b/node-moduleExports.sublime-snippet @@ -1,8 +1,8 @@ - - - me - source.js - module.exports + + + me + source.js + module.exports \ No newline at end of file diff --git a/node-require.sublime-snippet b/node-require.sublime-snippet index 7aba199..d4f0faf 100644 --- a/node-require.sublime-snippet +++ b/node-require.sublime-snippet @@ -1,8 +1,8 @@ - - - re - source.js - require + + + re + source.js + require \ No newline at end of file diff --git a/package.json b/package.json index 850b9ce..ed70bb7 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ -{ - "name": "sublime-js-snippets", - "version": "0.0.1", - "repository": { - "type": "git", - "url": "https://github.com/imweb/sublime-js-snippets.git" - }, - "devDependencies": { - "grunt": "0.4.2", - "grunt-bump": "0.0.13", - "grunt-cli": "0.1.11", - "grunt-lintspaces": "0.3.1" - }, - "scripts": { - "test": "grunt" - } -} +{ + "name": "sublime-js-snippets", + "version": "0.3.0", + "repository": { + "type": "git", + "url": "https://github.com/imweb/sublime-js-snippets.git" + }, + "devDependencies": { + "grunt": "0.4.2", + "grunt-bump": "0.0.13", + "grunt-cli": "0.1.11", + "grunt-lintspaces": "0.3.1" + }, + "scripts": { + "test": "grunt" + } +} diff --git a/timer-setInterval.sublime-snippet b/timer-setInterval.sublime-snippet index 0a6b731..f564a3f 100644 --- a/timer-setInterval.sublime-snippet +++ b/timer-setInterval.sublime-snippet @@ -1,10 +1,10 @@ - - - si - source.js - setInterval + + + si + source.js + setInterval \ No newline at end of file diff --git a/timer-setTimeout.sublime-snippet b/timer-setTimeout.sublime-snippet index 31fe693..034e784 100644 --- a/timer-setTimeout.sublime-snippet +++ b/timer-setTimeout.sublime-snippet @@ -1,10 +1,10 @@ - - - st - source.js - setTimeout + + + st + source.js + setTimeout \ No newline at end of file diff --git a/timers-setInterval.sublime-snippet b/timers-setInterval.sublime-snippet index bcce2b2..226313e 100644 --- a/timers-setInterval.sublime-snippet +++ b/timers-setInterval.sublime-snippet @@ -1,10 +1,10 @@ - - - setI - source.js - setInterval + + + setI + source.js + setInterval \ No newline at end of file diff --git a/timers-setTimeout.sublime-snippet b/timers-setTimeout.sublime-snippet index b6b4164..c4583a6 100644 --- a/timers-setTimeout.sublime-snippet +++ b/timers-setTimeout.sublime-snippet @@ -1,10 +1,10 @@ - - - setT - source.js - setTimeout + + + setT + source.js + setTimeout \ No newline at end of file