fp docs - Remove notes about mutation in description.

This commit is contained in:
Jeroen Engels
2016-02-10 01:12:36 +01:00
committed by John-David Dalton
parent 6f4099c20b
commit 02bea6534c
3 changed files with 116 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
var _ = require('lodash'),
j = require('jscodeshift'),
Entry = require('docdown/lib/entry'),
common = require('./common');
var baseGetDesc = Entry.prototype.getDesc;
var lineBreaksRegex = /<br\/?>\n?$/g;
/**
* Return the `description` of the entry, only without the possible note about mutation.
*
* @returns {Function} Updated description.
*/
function getReorderedExample() {
var lines = baseGetDesc.call(this).split('\n');
var indexOfLine = _.findIndex(lines, function(line) {
return _.includes(line, 'mutate');
});
if (indexOfLine === -1) {
return lines.join('\n');
}
var linesToDelete = 1;
while (indexOfLine + linesToDelete < lines.length &&
!lines[indexOfLine + linesToDelete].startsWith('<br')) {
linesToDelete++;
}
lines.splice(indexOfLine, linesToDelete);
while (_.last(lines).startsWith('<br')) {
lines = _.initial(lines);
}
return lines.join('\n');
}
module.exports = getReorderedExample;

View File

@@ -1,4 +1,5 @@
var Entry = require('docdown/lib/entry'),
getUpdatedDesc = require('./description'),
getReorderedParams = require('./parameters'),
getReorderedExample = require('./example');
@@ -6,6 +7,7 @@ var Entry = require('docdown/lib/entry'),
* Updates `docdown` `Entry`'s prototype so that parameters/arguments are reordered according to `mapping`.
*/
module.exports = function applyFPMapping(mapping) {
Entry.prototype.getDesc = getUpdatedDesc;
Entry.prototype.getParams = getReorderedParams(mapping);
Entry.prototype.getExample = getReorderedExample(mapping);
};