keep-a-changelog 2.0.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +28 -2
  2. package/README.md +21 -6
  3. package/esm/_dnt.polyfills.js +15 -0
  4. package/esm/bin.js +9 -4
  5. package/esm/deps/deno.land/std@0.173.0/_util/asserts.js +21 -0
  6. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/_util/os.js +4 -1
  7. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/flags/mod.js +145 -36
  8. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.js +1 -0
  9. package/esm/deps/deno.land/std@0.173.0/path/_interface.js +3 -0
  10. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.js +1 -0
  11. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.js +1 -1
  12. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.js +1 -1
  13. package/esm/deps/deno.land/std@0.173.0/path/mod.js +32 -0
  14. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.js +23 -16
  15. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.js +1 -1
  16. package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.js +20 -15
  17. package/esm/deps/{deno_land/x/semver_v1.4.0 → deno.land/std@0.173.0/semver}/mod.js +227 -334
  18. package/esm/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.js +0 -0
  19. package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.js +1 -1
  20. package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.js +0 -0
  21. package/esm/mod.js +1 -0
  22. package/esm/src/Change.js +15 -15
  23. package/esm/src/Changelog.js +9 -1
  24. package/esm/src/Release.js +21 -4
  25. package/esm/src/deps.js +1 -1
  26. package/esm/src/parser.js +24 -5
  27. package/esm/test/changelog.custom.type.md +0 -1
  28. package/esm/test/changelog.expected.linted.md +208 -0
  29. package/esm/test/changelog.expected.md +6 -4
  30. package/esm/test/changelog.md +7 -3
  31. package/esm/test/empty.expected.md +0 -1
  32. package/package.json +13 -8
  33. package/script/_dnt.polyfills.js +16 -0
  34. package/script/_dnt.shims.js +66 -0
  35. package/script/bin.js +144 -0
  36. package/script/deps/deno.land/std@0.173.0/_util/asserts.js +27 -0
  37. package/script/deps/deno.land/std@0.173.0/_util/os.js +44 -0
  38. package/script/deps/deno.land/std@0.173.0/flags/mod.js +368 -0
  39. package/script/deps/deno.land/std@0.173.0/path/_constants.js +49 -0
  40. package/script/deps/deno.land/std@0.173.0/path/_interface.js +4 -0
  41. package/script/deps/deno.land/std@0.173.0/path/_util.js +125 -0
  42. package/script/deps/deno.land/std@0.173.0/path/common.js +40 -0
  43. package/script/deps/deno.land/std@0.173.0/path/glob.js +391 -0
  44. package/script/deps/deno.land/std@0.173.0/path/mod.js +63 -0
  45. package/script/deps/deno.land/std@0.173.0/path/posix.js +539 -0
  46. package/script/deps/deno.land/std@0.173.0/path/separator.js +8 -0
  47. package/script/deps/deno.land/std@0.173.0/path/win32.js +1007 -0
  48. package/script/deps/deno.land/std@0.173.0/semver/mod.js +1458 -0
  49. package/script/deps/deno.land/std@0.51.0/fs/eol.js +34 -0
  50. package/script/deps/deno.land/x/ini@v2.1.0/ini.js +256 -0
  51. package/script/deps/deno.land/x/ini@v2.1.0/mod.js +17 -0
  52. package/script/mod.js +15 -0
  53. package/{umd → script}/package.json +0 -0
  54. package/script/src/Change.js +51 -0
  55. package/script/src/Changelog.js +148 -0
  56. package/script/src/Release.js +227 -0
  57. package/script/src/deps.js +9 -0
  58. package/script/src/parser.js +184 -0
  59. package/{umd → script}/test/changelog.custom.type.md +0 -1
  60. package/script/test/changelog.expected.linted.md +208 -0
  61. package/{umd → script}/test/changelog.expected.md +6 -4
  62. package/{umd → script}/test/changelog.md +7 -3
  63. package/{umd → script}/test/empty.expected.md +0 -1
  64. package/types/_dnt.polyfills.d.ts +11 -0
  65. package/types/_dnt.shims.d.ts +0 -4
  66. package/types/bin.d.ts +1 -1
  67. package/types/deps/deno.land/std@0.173.0/_util/asserts.d.ts +10 -0
  68. package/types/deps/deno.land/std@0.173.0/_util/os.d.ts +4 -0
  69. package/types/deps/deno.land/std@0.173.0/flags/mod.d.ts +166 -0
  70. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.d.ts +0 -0
  71. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_interface.d.ts +1 -1
  72. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.d.ts +0 -0
  73. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.d.ts +0 -0
  74. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.d.ts +10 -5
  75. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/mod.d.ts +0 -0
  76. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.d.ts +9 -5
  77. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.d.ts +0 -0
  78. package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.d.ts +7 -5
  79. package/types/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
  80. package/types/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.d.ts +0 -0
  81. package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.d.ts +0 -0
  82. package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.d.ts +0 -0
  83. package/types/mod.d.ts +1 -0
  84. package/types/src/Changelog.d.ts +1 -0
  85. package/types/src/Release.d.ts +2 -0
  86. package/types/src/deps.d.ts +1 -1
  87. package/esm/deps/deno_land/std_0.120.0/_util/assert.js +0 -13
  88. package/esm/deps/deno_land/std_0.120.0/path/_interface.js +0 -3
  89. package/esm/deps/deno_land/std_0.120.0/path/mod.js +0 -14
  90. package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +0 -5
  91. package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +0 -3
  92. package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +0 -50
  93. package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +0 -116
  94. package/umd/_dnt.shims.js +0 -76
  95. package/umd/bin.js +0 -145
  96. package/umd/deps/deno_land/std_0.120.0/_util/assert.js +0 -28
  97. package/umd/deps/deno_land/std_0.120.0/_util/os.js +0 -47
  98. package/umd/deps/deno_land/std_0.120.0/flags/mod.js +0 -269
  99. package/umd/deps/deno_land/std_0.120.0/path/_constants.js +0 -58
  100. package/umd/deps/deno_land/std_0.120.0/path/_interface.js +0 -14
  101. package/umd/deps/deno_land/std_0.120.0/path/_util.js +0 -134
  102. package/umd/deps/deno_land/std_0.120.0/path/common.js +0 -50
  103. package/umd/deps/deno_land/std_0.120.0/path/glob.js +0 -397
  104. package/umd/deps/deno_land/std_0.120.0/path/mod.js +0 -51
  105. package/umd/deps/deno_land/std_0.120.0/path/posix.js +0 -538
  106. package/umd/deps/deno_land/std_0.120.0/path/separator.js +0 -18
  107. package/umd/deps/deno_land/std_0.120.0/path/win32.js +0 -1008
  108. package/umd/deps/deno_land/std_0.51.0/fs/eol.js +0 -44
  109. package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +0 -262
  110. package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +0 -23
  111. package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +0 -1578
  112. package/umd/mod.js +0 -24
  113. package/umd/src/Change.js +0 -61
  114. package/umd/src/Changelog.js +0 -150
  115. package/umd/src/Release.js +0 -220
  116. package/umd/src/deps.js +0 -19
  117. package/umd/src/parser.js +0 -175
package/umd/mod.js DELETED
@@ -1,24 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./src/parser.js", "./src/Change.js", "./src/Changelog.js", "./src/Release.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Release = exports.parser = exports.Changelog = exports.Change = void 0;
16
- const parser_js_1 = __importDefault(require("./src/parser.js"));
17
- exports.parser = parser_js_1.default;
18
- const Change_js_1 = __importDefault(require("./src/Change.js"));
19
- exports.Change = Change_js_1.default;
20
- const Changelog_js_1 = __importDefault(require("./src/Changelog.js"));
21
- exports.Changelog = Changelog_js_1.default;
22
- const Release_js_1 = __importDefault(require("./src/Release.js"));
23
- exports.Release = Release_js_1.default;
24
- });
package/umd/src/Change.js DELETED
@@ -1,61 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- class Change {
13
- constructor(title, description = "") {
14
- Object.defineProperty(this, "title", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "description", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
26
- Object.defineProperty(this, "issues", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: []
31
- });
32
- this.title = Change.extractIssues(title, this.issues);
33
- this.description = Change.extractIssues(description, this.issues);
34
- }
35
- static extractIssues(text, issues) {
36
- return text
37
- .replace(/(^|[^\\])\[#(\d+)\](?=[^\(]|$)/g, (_, start, index) => {
38
- if (!issues.includes(index)) {
39
- issues.push(index);
40
- }
41
- return `${start}[#${index}]`;
42
- })
43
- .replace(/(^|[\s,])#(\d+)(?=[\s,\.]|$)/g, (_, start, index) => {
44
- if (!issues.includes(index)) {
45
- issues.push(index);
46
- }
47
- return `${start}[#${index}]`;
48
- });
49
- }
50
- toString() {
51
- let t = this.title.split("\n").map((line) => ` ${line}`.trimEnd());
52
- t[0] = "-" + t[0].substr(1);
53
- if (this.description) {
54
- t.push("");
55
- t = t.concat(this.description.split("\n").map((line) => ` ${line}`.trimEnd()));
56
- }
57
- return t.join("\n").trim();
58
- }
59
- }
60
- exports.default = Change;
61
- });
@@ -1,150 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./deps.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const deps_js_1 = require("./deps.js");
13
- class Changelog {
14
- constructor(title, description = "") {
15
- Object.defineProperty(this, "flag", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- Object.defineProperty(this, "title", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: void 0
26
- });
27
- Object.defineProperty(this, "description", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: void 0
32
- });
33
- Object.defineProperty(this, "head", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: "HEAD"
38
- });
39
- Object.defineProperty(this, "footer", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: void 0
44
- });
45
- Object.defineProperty(this, "url", {
46
- enumerable: true,
47
- configurable: true,
48
- writable: true,
49
- value: void 0
50
- });
51
- Object.defineProperty(this, "releases", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: []
56
- });
57
- Object.defineProperty(this, "tagNameBuilder", {
58
- enumerable: true,
59
- configurable: true,
60
- writable: true,
61
- value: void 0
62
- });
63
- this.title = title;
64
- this.description = description;
65
- }
66
- addRelease(release) {
67
- this.releases.push(release);
68
- this.sortReleases();
69
- release.changelog = this;
70
- return this;
71
- }
72
- findRelease(version) {
73
- if (!version) {
74
- return this.releases.find((release) => !release.version);
75
- }
76
- return this.releases.find((release) => release.version && (0, deps_js_1.eq)(release.version, version));
77
- }
78
- sortReleases() {
79
- this.releases.sort((a, b) => a.compare(b));
80
- }
81
- tagName(release) {
82
- if (this.tagNameBuilder) {
83
- return this.tagNameBuilder(release);
84
- }
85
- return `v${release.version}`;
86
- }
87
- toString() {
88
- const t = [];
89
- if (this.flag) {
90
- t.push(`<!-- ${this.flag} -->`);
91
- t.push("");
92
- }
93
- t.push(`# ${this.title}`);
94
- const links = [];
95
- const compareLinks = [];
96
- const description = this.description.trim() ||
97
- `All notable changes to this project will be documented in this file.
98
-
99
- The format is based on [Keep a Changelog](http://keepachangelog.com/)
100
- and this project adheres to [Semantic Versioning](http://semver.org/).`;
101
- if (description) {
102
- t.push("");
103
- t.push(description);
104
- }
105
- this.releases.forEach((release) => {
106
- t.push("");
107
- t.push(release.toString(this));
108
- release.getLinks(this).forEach((link) => {
109
- if (!links.includes(link)) {
110
- links.push(link);
111
- }
112
- });
113
- const compareLink = release.getCompareLink(this);
114
- if (compareLink) {
115
- compareLinks.push(compareLink);
116
- }
117
- });
118
- if (links.length) {
119
- t.push("");
120
- links.sort(compare);
121
- links.forEach((link) => t.push(link));
122
- }
123
- if (compareLinks.length) {
124
- t.push("");
125
- compareLinks.forEach((link) => t.push(link));
126
- }
127
- t.push("");
128
- if (this.footer) {
129
- t.push("---");
130
- t.push("");
131
- t.push(this.footer);
132
- t.push("");
133
- }
134
- return t.join("\n");
135
- }
136
- }
137
- exports.default = Changelog;
138
- function compare(a, b) {
139
- if (a === b) {
140
- return 0;
141
- }
142
- const reg = /^\[#(\d+)\]:/;
143
- const aNumber = a.match(reg);
144
- const bNumber = b.match(reg);
145
- if (aNumber && bNumber) {
146
- return parseInt(aNumber[1]) - parseInt(bNumber[1]);
147
- }
148
- return a < b ? -1 : 1;
149
- }
150
- });
@@ -1,220 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./deps.js", "./Change.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const deps_js_1 = require("./deps.js");
16
- const Change_js_1 = __importDefault(require("./Change.js"));
17
- class Release {
18
- constructor(version, date, description = "") {
19
- Object.defineProperty(this, "changelog", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "version", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- Object.defineProperty(this, "date", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: void 0
36
- });
37
- Object.defineProperty(this, "description", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- Object.defineProperty(this, "changes", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: void 0
48
- });
49
- this.setVersion(version);
50
- this.setDate(date);
51
- this.description = description;
52
- this.changes = new Map([
53
- ["added", []],
54
- ["changed", []],
55
- ["deprecated", []],
56
- ["removed", []],
57
- ["fixed", []],
58
- ["security", []],
59
- ]);
60
- }
61
- compare(release) {
62
- if (!this.version && release.version) {
63
- return -1;
64
- }
65
- if (!release.version) {
66
- return 1;
67
- }
68
- if (!this.date && release.date) {
69
- return -1;
70
- }
71
- if (!release.date) {
72
- return 1;
73
- }
74
- if (this.version && release.version) {
75
- return -this.version.compare(release.version);
76
- }
77
- return 0;
78
- }
79
- isEmpty() {
80
- if (this.description.trim()) {
81
- return false;
82
- }
83
- return Array.from(this.changes.values()).every((change) => !change.length);
84
- }
85
- setVersion(version) {
86
- if (typeof version === "string") {
87
- version = new deps_js_1.Semver(version);
88
- }
89
- this.version = version;
90
- //Re-sort the releases of the parent changelog
91
- if (this.changelog) {
92
- this.changelog.sortReleases();
93
- }
94
- }
95
- setDate(date) {
96
- if (typeof date === "string") {
97
- date = new Date(date);
98
- }
99
- this.date = date;
100
- }
101
- addChange(type, change) {
102
- if (!(change instanceof Change_js_1.default)) {
103
- change = new Change_js_1.default(change);
104
- }
105
- if (!this.changes.has(type)) {
106
- throw new Error("Invalid change type");
107
- }
108
- this.changes.get(type).push(change);
109
- return this;
110
- }
111
- added(change) {
112
- return this.addChange("added", change);
113
- }
114
- changed(change) {
115
- return this.addChange("changed", change);
116
- }
117
- deprecated(change) {
118
- return this.addChange("deprecated", change);
119
- }
120
- removed(change) {
121
- return this.addChange("removed", change);
122
- }
123
- fixed(change) {
124
- return this.addChange("fixed", change);
125
- }
126
- security(change) {
127
- return this.addChange("security", change);
128
- }
129
- toString(changelog) {
130
- let t = [];
131
- const hasCompareLink = this.getCompareLink(changelog) !== undefined;
132
- if (this.version) {
133
- if (hasCompareLink) {
134
- t.push(`## [${this.version}] - ${formatDate(this.date)}`);
135
- }
136
- else {
137
- t.push(`## ${this.version} - ${formatDate(this.date)}`);
138
- }
139
- }
140
- else {
141
- if (hasCompareLink) {
142
- t.push("## [Unreleased]");
143
- }
144
- else {
145
- t.push("## Unreleased");
146
- }
147
- }
148
- if (this.description.trim()) {
149
- t.push(this.description.trim());
150
- t.push("");
151
- }
152
- this.changes.forEach((changes, type) => {
153
- if (changes.length) {
154
- t.push(`### ${type[0].toUpperCase()}${type.substring(1)}`);
155
- t = t.concat(changes.map((change) => change.toString()));
156
- t.push("");
157
- }
158
- });
159
- return t.join("\n").trim();
160
- }
161
- getCompareLink(changelog) {
162
- if (!changelog?.url) {
163
- return;
164
- }
165
- const index = changelog.releases.indexOf(this);
166
- if (index === -1) {
167
- return;
168
- }
169
- let offset = 1;
170
- let previous = changelog.releases[index + offset];
171
- while (previous && !previous.date) {
172
- ++offset;
173
- previous = changelog.releases[index + offset];
174
- }
175
- if (!previous) {
176
- if (!this.version || !this.date) {
177
- return;
178
- }
179
- return `[${this.version}]: ${changelog.url}/releases/tag/${changelog.tagName(this)}`;
180
- }
181
- if (!this.version) {
182
- return `[Unreleased]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.head}`;
183
- }
184
- if (!this.date) {
185
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.head}`;
186
- }
187
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.tagName(this)}`;
188
- }
189
- getLinks(changelog) {
190
- const links = [];
191
- if (!changelog.url) {
192
- return links;
193
- }
194
- this.changes.forEach((changes) => changes.forEach((change) => {
195
- change.issues.forEach((issue) => {
196
- if (!links.includes(issue)) {
197
- links.push(`[#${issue}]: ${changelog.url}/issues/${issue}`);
198
- }
199
- });
200
- }));
201
- return links;
202
- }
203
- }
204
- exports.default = Release;
205
- function formatDate(date) {
206
- if (!date) {
207
- return "Unreleased";
208
- }
209
- const year = date.getUTCFullYear();
210
- let month = date.getUTCMonth() + 1;
211
- let day = date.getUTCDate();
212
- if (month < 10) {
213
- month = "0" + month;
214
- }
215
- if (day < 10) {
216
- day = "0" + day;
217
- }
218
- return `${year}-${month}-${day}`;
219
- }
220
- });
package/umd/src/deps.js DELETED
@@ -1,19 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "../deps/deno_land/x/semver_v1.4.0/mod.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.eq = exports.Semver = void 0;
16
- var mod_js_1 = require("../deps/deno_land/x/semver_v1.4.0/mod.js");
17
- Object.defineProperty(exports, "Semver", { enumerable: true, get: function () { return __importDefault(mod_js_1).default; } });
18
- Object.defineProperty(exports, "eq", { enumerable: true, get: function () { return mod_js_1.eq; } });
19
- });
package/umd/src/parser.js DELETED
@@ -1,175 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./Changelog.js", "./Release.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Changelog_js_1 = __importDefault(require("./Changelog.js"));
16
- const Release_js_1 = __importDefault(require("./Release.js"));
17
- const defaultOptions = {
18
- releaseCreator: (version, date, description) => new Release_js_1.default(version, date, description),
19
- };
20
- /** Parse a markdown string */
21
- function parser(markdown, options) {
22
- const opts = Object.assign({}, defaultOptions, options);
23
- const tokens = tokenize(markdown);
24
- try {
25
- return processTokens(tokens, opts);
26
- }
27
- catch (error) {
28
- throw new Error(`Parse error in the line ${tokens[0][0]}: ${error.message}`);
29
- }
30
- }
31
- exports.default = parser;
32
- /** Process an array of tokens to build the Changelog */
33
- function processTokens(tokens, opts) {
34
- const changelog = new Changelog_js_1.default("");
35
- changelog.flag = getContent(tokens, "flag");
36
- changelog.title = getContent(tokens, "h1", true);
37
- changelog.description = getContent(tokens, "p");
38
- //Releases
39
- let release;
40
- while ((release = getContent(tokens, "h2").toLowerCase())) {
41
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*([\d]{4}-[\d]{1,2}-[\d]{1,2})$/);
42
- if (matches) {
43
- release = opts.releaseCreator(matches[1], matches[2]);
44
- }
45
- else if (release.includes("unreleased")) {
46
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*unreleased$/);
47
- release = matches
48
- ? opts.releaseCreator(matches[1])
49
- : opts.releaseCreator();
50
- }
51
- else {
52
- throw new Error(`Syntax error in the release title`);
53
- }
54
- changelog.addRelease(release);
55
- release.description = getContent(tokens, "p");
56
- let type;
57
- while ((type = getContent(tokens, "h3").toLowerCase())) {
58
- let change;
59
- while ((change = getContent(tokens, "li"))) {
60
- release.addChange(type, change);
61
- }
62
- }
63
- }
64
- //Skip release links
65
- let link = getContent(tokens, "link");
66
- while (link) {
67
- if (!changelog.url) {
68
- const matches = link.match(/^\[.*\]\:\s*(http.*)\/compare\/.*$/);
69
- if (matches) {
70
- changelog.url = matches[1];
71
- }
72
- }
73
- link = getContent(tokens, "link");
74
- }
75
- //Footer
76
- if (getContent(tokens, "hr")) {
77
- changelog.footer = getContent(tokens, "p");
78
- }
79
- if (tokens.length) {
80
- throw new Error(`Unexpected content ${JSON.stringify(tokens)}`);
81
- }
82
- return changelog;
83
- }
84
- /** Returns the content of a token */
85
- function getContent(tokens, type, required = false) {
86
- if (!tokens[0] || tokens[0][1] !== type) {
87
- if (required) {
88
- throw new Error(`Required token missing in: "${tokens[0][0]}"`);
89
- }
90
- return "";
91
- }
92
- return tokens.shift()[2].join("\n");
93
- }
94
- /** Tokenize a markdown string */
95
- function tokenize(markdown) {
96
- const tokens = [];
97
- markdown
98
- .trim()
99
- .split("\n")
100
- .map((line, index, allLines) => {
101
- const lineNumber = index + 1;
102
- if (line.startsWith("---")) {
103
- return [lineNumber, "hr", ["-"]];
104
- }
105
- if (line.startsWith("# ")) {
106
- return [lineNumber, "h1", [line.substr(1).trim()]];
107
- }
108
- if (line.startsWith("## ")) {
109
- return [lineNumber, "h2", [line.substr(2).trim()]];
110
- }
111
- if (line.startsWith("### ")) {
112
- return [lineNumber, "h3", [line.substr(3).trim()]];
113
- }
114
- if (line.startsWith("-")) {
115
- return [lineNumber, "li", [line.substr(1).trim()]];
116
- }
117
- if (line.startsWith("*")) {
118
- return [lineNumber, "li", [line.substr(1).trim()]];
119
- }
120
- if (line.match(/^\[.*\]\:\s*http.*$/)) {
121
- return [lineNumber, "link", [line.trim()]];
122
- }
123
- if (line.match(/^\[.*\]\:$/)) {
124
- const nextLine = allLines[index + 1];
125
- if (nextLine && nextLine.match(/\s+http.*$/)) {
126
- // We found a multi-line link: treat it like a single line
127
- allLines[index + 1] = "";
128
- return [lineNumber, "link", [
129
- line.trim() + "\n" + nextLine.trimEnd(),
130
- ]];
131
- }
132
- }
133
- const result = line.match(/^<!--(.*)-->$/);
134
- if (result) {
135
- return [lineNumber, "flag", [result[1].trim()]];
136
- }
137
- return [lineNumber, "p", [line.trimEnd()]];
138
- })
139
- .forEach((line, index) => {
140
- const [lineNumber, type, [content]] = line;
141
- if (index > 0) {
142
- const prevType = tokens[0][1];
143
- if (type === "p") {
144
- if (prevType === "p") {
145
- return tokens[0][2].push(content);
146
- }
147
- if (prevType === "li") {
148
- return tokens[0][2].push(content.replace(/^\s\s/, ""));
149
- }
150
- }
151
- }
152
- tokens.unshift([lineNumber, type, [content]]);
153
- });
154
- return tokens
155
- .filter((token) => !isEmpty(token[2]))
156
- .map((token) => {
157
- const content = token[2];
158
- while (isEmpty(content[content.length - 1])) {
159
- content.pop();
160
- }
161
- while (isEmpty(content[0])) {
162
- content.shift();
163
- }
164
- return token;
165
- })
166
- .reverse();
167
- }
168
- /** Check if a string or array is empty */
169
- function isEmpty(val) {
170
- if (Array.isArray(val)) {
171
- val = val.join("");
172
- }
173
- return !val || val.trim() === "";
174
- }
175
- });