angular/aio/tools/transforms/angular-base-package/processors/splitDescription.js
Tobias Speicher 4ddcf81e61 refactor: replace deprecated String.prototype.substr() (#45397)
.substr() is deprecated so we replace it with functions which work similarily but aren't deprecated

Signed-off-by: Tobias Speicher <[email protected]>

PR Close #45397
2022-03-24 11:48:09 -07:00

28 lines
894 B
JavaScript

/**
* Split the description (of selected docs) into:
* * `shortDescription`: the first paragraph
* * `description`: the rest of the paragraphs
*/
module.exports = function splitDescription() {
return {
$runAfter: ['tags-extracted'],
$runBefore: ['processing-docs'],
docTypes: [],
$process(docs) {
docs.forEach(doc => {
if (this.docTypes.indexOf(doc.docType) !== -1 && doc.description !== undefined) {
const description = doc.description.trim();
const endOfParagraph = description.search(/\n\s*\n/);
if (endOfParagraph === -1) {
doc.shortDescription = description;
doc.description = '';
} else {
doc.shortDescription = description.slice(0, endOfParagraph).trim();
doc.description = description.slice(endOfParagraph).trim();
}
}
});
}
};
};