Merge pull request #5661 from NodeBB/utils-rtrim

Deprecate non-standard `String.prototype.rtrim`
This commit is contained in:
Barış Soner Uşaklı
2017-05-09 16:44:43 -04:00
committed by GitHub
3 changed files with 17 additions and 8 deletions

View File

@@ -412,9 +412,13 @@
(relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true) // Subfolder installs need this additional check
);
},
rtrim: function (str) {
return str.replace(/\s+$/g, '');
},
};
/* eslint "no-extend-native": "off" */
/* eslint "no-extend-native": "off" */
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function (prefix) {
if (this.length < prefix.length) {
@@ -436,9 +440,11 @@
};
}
// DEPRECATED: remove in 1.6
if (typeof String.prototype.rtrim !== 'function') {
String.prototype.rtrim = function () {
return this.replace(/\s+$/g, '');
console.warn('[deprecated] `String.prototype.rtrim` is deprecated as of NodeBB v1.5; use `utils.rtrim` instead.');
return utils.rtrim(this);
};
}