Created
August 17, 2014 10:37
-
-
Save hail2u/063e59bf6a84e7b727d5 to your computer and use it in GitHub Desktop.
環境変数入りのパスを展開するののだいたい動くやつ
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
function expandPath(p) { | |
return p.replace(/(?:\$(\w+?)|%(.*?)%)/g, function (match, name) { | |
return process.env[name]; | |
}); | |
} | |
console.log(expandPath('$HOME/foo/bar')); // C:/Users/John/foo/bar | |
console.log(expandPath('%USERPROFILE%\\foo\\bar')); // C:\\Users\\John\\foo\\bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment