Deprecate utils.walk, remove prototype modification

v1.18.x
Peter Jaszkowiak 8 years ago
parent 1ed571189c
commit 1892492505

@ -2,9 +2,13 @@
(function (factory) { (function (factory) {
if (typeof module === 'object' && module.exports) { if (typeof module === 'object' && module.exports) {
var winston = require('winston');
var file = require('../../src/file'); var file = require('../../src/file');
module.exports = factory(require('xregexp')); module.exports = factory(require('xregexp'));
module.exports.walk = function (dir, done) { module.exports.walk = function (dir, done) {
// DEPRECATED
winston.warn('[deprecated] `utils.walk` is deprecated. Use `file.walk` instead.');
file.walk(dir, done); file.walk(dir, done);
}; };
@ -424,11 +428,5 @@
}; };
} }
if (typeof String.prototype.rtrim !== 'function') {
String.prototype.rtrim = function () {
return this.replace(/\s+$/g, '');
};
}
return utils; return utils;
})); }));

@ -87,6 +87,10 @@ module.exports = function (Topics) {
], callback); ], callback);
}; };
function rtrim(str) {
return str.replace(/\s+$/g, '');
}
Topics.post = function (data, callback) { Topics.post = function (data, callback) {
var uid = data.uid; var uid = data.uid;
data.title = String(data.title).trim(); data.title = String(data.title).trim();
@ -101,7 +105,7 @@ module.exports = function (Topics) {
}, },
function (next) { function (next) {
if (data.content) { if (data.content) {
data.content = data.content.rtrim(); data.content = rtrim(data.content);
} }
check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next); check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);
}, },
@ -234,7 +238,7 @@ module.exports = function (Topics) {
function (filteredData, next) { function (filteredData, next) {
content = filteredData.content || data.content; content = filteredData.content || data.content;
if (content) { if (content) {
content = content.rtrim(); content = rtrim(content);
} }
check(content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next); check(content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);

Loading…
Cancel
Save