react-docgen-deprecation-handler
Version:
Add deprecation status for props
25 lines (19 loc) • 741 B
JavaScript
const pattern = / \:\w*/
function deprecationHandler(documentation) {
for (var [key, value] of documentation._props.entries()) {
if (value.description.includes("@deprecated")) {
value.deprecated = true
/* default expected value of annotation */
let deprecatedAnnotation = "@deprecated "
/* extended metadata format: @deprecated:metadata */
const match = value.description.match(pattern)
if (match) {
deprecatedAnnotation = match[0]
value.deprecationData = deprecatedAnnotation.replace("@deprecated:", "")
}
/* strip annotation */
value.description = value.description.replace(deprecatedAnnotation, "")
}
}
}
module.exports = deprecationHandler