diff options
author | Jackson Tian <shyvo1987@gmail.com> | 2016-03-17 12:23:52 +0800 |
---|---|---|
committer | Benjamin Gruenbaum <inglor@gmail.com> | 2016-03-23 15:58:52 +0200 |
commit | 91466b855f0ced0df9a2d7444eea8ac7b89e278e (patch) | |
tree | 3b2db268ae1960f2343d414e527af8bdadbc6641 /lib/os.js | |
parent | fb51c396ff823f8274bc4bea487da562ce57d75e (diff) | |
download | android-node-v8-91466b855f0ced0df9a2d7444eea8ac7b89e278e.tar.gz android-node-v8-91466b855f0ced0df9a2d7444eea8ac7b89e278e.tar.bz2 android-node-v8-91466b855f0ced0df9a2d7444eea8ac7b89e278e.zip |
lib: refactor code with startsWith/endsWith
reduce using RegExp for string test. This pull reuqest replaces
various usages of regular expressions in favor of the ES2015
startsWith and endsWith methods.
PR-URL: https://github.com/nodejs/node/pull/5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib/os.js')
-rw-r--r-- | lib/os.js | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -24,23 +24,23 @@ exports.platform = function() { return process.platform; }; -const trailingSlashRe = isWindows ? /[^:]\\$/ - : /.\/$/; - exports.tmpdir = function() { var path; if (isWindows) { path = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + '\\temp'; + if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\')) + path = path.slice(0, -1); } else { path = process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp'; + if (path.length > 1 && path.endsWith('/')) + path = path.slice(0, -1); } - if (trailingSlashRe.test(path)) - path = path.slice(0, -1); + return path; }; |