UNPKG

keep-a-changelog

Version:

Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.

37 lines (36 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Change { title; description; issues = []; static extractIssues(text, issues) { return text .replace(/(^|[^\\])\[#(\d+)\](?=[^\(]|$)/g, (_, start, index) => { if (!issues.includes(index)) { issues.push(index); } return `${start}[#${index}]`; }) .replace(/(^|[\s,])#(\d+)(?=[\s,\.]|$)/g, (_, start, index) => { if (!issues.includes(index)) { issues.push(index); } return `${start}[#${index}]`; }); } constructor(title, description = "") { this.title = Change.extractIssues(title, this.issues); this.description = Change.extractIssues(description, this.issues); } toString(bulletStyle = "-") { let t = this.title.split("\n").map((line) => ` ${line}`.trimEnd()); t[0] = bulletStyle + t[0].substr(1); if (this.description) { t.push(""); t = t.concat(this.description.split("\n").map((line) => ` ${line}`.trimEnd())); } return t.join("\n").trim(); } } exports.default = Change;