From 02bea6534c10494b6a199fffb8407cd8cd01adef Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 10 Feb 2016 01:12:36 +0100 Subject: [PATCH] fp docs - Remove notes about mutation in description. --- lib/doc/apply-fp-mapping/description.js | 39 +++++++++++++ lib/doc/apply-fp-mapping/index.js | 2 + test/test-fp-doc.js | 78 ++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 lib/doc/apply-fp-mapping/description.js diff --git a/lib/doc/apply-fp-mapping/description.js b/lib/doc/apply-fp-mapping/description.js new file mode 100644 index 000000000..f6b4f1bdd --- /dev/null +++ b/lib/doc/apply-fp-mapping/description.js @@ -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 = /\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('