Created
July 15, 2015 18:12
-
-
Save irrationalistic/656b44c10f95ba621be4 to your computer and use it in GitHub Desktop.
UltiSnips: Require Snippet for Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global !p | |
def camel(line): | |
if not line: return '' | |
res = re.sub(r'[_-].?',lambda x: x.group()[1].upper() if len(x.group()) > 1 else '' ,line) | |
res = res.replace('.', '') | |
if not res: return '' | |
return res[0].lower() + res[1:] | |
def filename(path): | |
return os.path.splitext(os.path.basename(path))[0] | |
def firstUpper(line): | |
if not line: return '' | |
return line[0].upper() + line[1:] | |
endglobal | |
snippet req "CommonJS Require" b | |
var ${2:`!p snip.rv = camel(filename(t[1]))`} = require('$1'); | |
endsnippet | |
snippet reqt "CommonJS Require Title Case" b | |
var ${2:`!p snip.rv = firstUpper(camel(filename(t[1])))`} = require('$1'); | |
endsnippet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment