From 18dea5502fa5e02f1ceefc039f9de4e6c7d8b063 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 24 Nov 2016 22:28:50 +0000 Subject: [PATCH] add shim for trimRight --- plugins/c9.ide.plugins/updater-npm.js | 8 ++------ plugins/c9.ide.ui/lib_apf.js | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/c9.ide.plugins/updater-npm.js b/plugins/c9.ide.plugins/updater-npm.js index 3a02daea..47e760a1 100644 --- a/plugins/c9.ide.plugins/updater-npm.js +++ b/plugins/c9.ide.plugins/updater-npm.js @@ -159,10 +159,6 @@ define(function(require, exports, module) { } } - function trimRight(str) { - return str.replace(/\s+$/, ""); - } - /* -- npm Management ----- */ /** @@ -207,8 +203,8 @@ define(function(require, exports, module) { if (err) return callback(err, stdout, err.message); - stdout = trimRight(stdout); - stderr = trimRight(stderr); + stdout = stdout.trimRight(); + stderr = stderr.trimRight(); callback(null, stdout, stderr); }); diff --git a/plugins/c9.ide.ui/lib_apf.js b/plugins/c9.ide.ui/lib_apf.js index 78b48f4b..d4db9446 100644 --- a/plugins/c9.ide.ui/lib_apf.js +++ b/plugins/c9.ide.ui/lib_apf.js @@ -2978,9 +2978,25 @@ String.prototype.uCaseFirst = function(){ * * @type {String} */ -String.prototype.trim = function(){ - return this.replace(/[\s\n\r]*$/, "").replace(/^[\s\n\r]*/, ""); -}; +if (!String.prototype.trim) { + String.prototype.trim = function(){ + return this.replace(/\s+$/, "").replace(/^\s+/, ""); + }; +} +/** + * annex b, but useful until trimStart/End are implemented by browsers + */ +if (!String.prototype.trimLeft) { + String.prototype.trimLeft = function(){ + return this.replace(/^\s+/, ""); + }; +} + +if (!String.prototype.trimRight) { + String.prototype.trimRight = function(){ + return this.replace(/\s+$/, ""); + }; +} /* * Concatenate a string with itself n-times.