conventional-commits-parser 5.0.0 → 6.0.0

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.
package/README.md CHANGED
@@ -1,7 +1,144 @@
1
- # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coverage-image]][coverage-url]
1
+ # conventional-commits-parser
2
2
 
3
- > Parse raw conventional commits
3
+ [![ESM-only package][package]][package-url]
4
+ [![NPM version][npm]][npm-url]
5
+ [![Node version][node]][node-url]
6
+ [![Dependencies status][deps]][deps-url]
7
+ [![Install size][size]][size-url]
8
+ [![Build status][build]][build-url]
9
+ [![Coverage status][coverage]][coverage-url]
4
10
 
11
+ [package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
12
+ [package-url]: https://nodejs.org/api/esm.html
13
+
14
+ [npm]: https://img.shields.io/npm/v/conventional-commits-parser.svg
15
+ [npm-url]: https://npmjs.com/package/conventional-commits-parser
16
+
17
+ [node]: https://img.shields.io/node/v/conventional-commits-parser.svg
18
+ [node-url]: https://nodejs.org
19
+
20
+ [deps]: https://img.shields.io/librariesio/release/npm/conventional-commits-parser
21
+ [deps-url]: https://libraries.io/npm/conventional-commits-parser/tree
22
+
23
+ [size]: https://packagephobia.com/badge?p=conventional-commits-parser
24
+ [size-url]: https://packagephobia.com/result?p=conventional-commits-parser
25
+
26
+ [build]: https://img.shields.io/github/actions/workflow/status/conventional-changelog/conventional-changelog/tests.yaml?branch=master
27
+ [build-url]: https://github.com/conventional-changelog/conventional-changelog/actions
28
+
29
+ [coverage]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
30
+ [coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
31
+
32
+ Parse raw conventional commits.
33
+
34
+ <hr />
35
+ <a href="#install">Install</a>
36
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
37
+ <a href="#usage">Usage</a>
38
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
39
+ <a href="#conventional-commit-message-format">Message format</a>
40
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
41
+ <a href="#api">API</a>
42
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
43
+ <a href="#cli">CLI</a>
44
+ <br />
45
+ <hr />
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ # pnpm
51
+ pnpm add conventional-commits-parser
52
+ # yarn
53
+ yarn add conventional-commits-parser
54
+ # npm
55
+ npm i conventional-commits-parser
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ ```js
61
+ import {
62
+ CommitParser,
63
+ parseCommits,
64
+ parseCommitsStream
65
+ } from 'conventional-commits-parser'
66
+ import { pipeline } from 'stream/promises'
67
+ import { Readable } from 'stream'
68
+
69
+ const rawCommitMessage = 'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
70
+
71
+ // to parse raw commit message manually:
72
+ const parser = new CommitParser(options)
73
+
74
+ console.log(parser.parse(rawCommitMessage))
75
+
76
+ // to parse raw commit messages async iterables:
77
+ await pipeline(
78
+ [rawCommitMessage],
79
+ parseCommits(options),
80
+ async function* (parsedCommits) {
81
+ for await (const commit of parsedCommits) {
82
+ console.log(commit)
83
+ }
84
+ }
85
+ )
86
+
87
+ // to parse raw commit messages streams:
88
+ Readable.from([rawCommitMessage])
89
+ .pipe(parseCommitsStream(options))
90
+ .on('data', commit => console.log(commit))
91
+ ```
92
+
93
+ Parser expects raw commit message. Examples:
94
+
95
+ ```js
96
+ 'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
97
+ 'feat(ng-list): Allow custom separator\nbla bla bla\n\nBREAKING CHANGE: some breaking change.\nThanks @stevemao\n'
98
+ ```
99
+
100
+ It will return parsed commit object. Examples:
101
+
102
+ ```js
103
+ {
104
+ type: 'feat',
105
+ scope: 'scope',
106
+ subject: 'broadcast $destroy event on scope destruction',
107
+ merge: null,
108
+ header: 'feat(scope): broadcast $destroy event on scope destruction',
109
+ body: null,
110
+ footer: 'Closes #1',
111
+ notes: [],
112
+ references:
113
+ [{
114
+ action: 'Closes',
115
+ owner: null,
116
+ repository: null,
117
+ issue: '1',
118
+ raw: '#1',
119
+ prefix: '#'
120
+ }],
121
+ mentions: [],
122
+ revert: null
123
+ }
124
+ {
125
+ type: 'feat',
126
+ scope: 'ng-list',
127
+ subject: 'Allow custom separator',
128
+ merge: null,
129
+ header: 'feat(ng-list): Allow custom separator',
130
+ body: 'bla bla bla',
131
+ footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao',
132
+ notes:
133
+ [{
134
+ title: 'BREAKING CHANGE',
135
+ text: 'some breaking change.\nThanks @stevemao'
136
+ }],
137
+ references: [],
138
+ mentions: ['stevemao'],
139
+ revert: null
140
+ }
141
+ ```
5
142
 
6
143
  ## Conventional Commit Message Format
7
144
 
@@ -56,78 +193,26 @@ Tests are added for these
56
193
 
57
194
  Then `sideNotes` will be `It should warn the correct unfound file names.\nAlso it should continue if one file cannot be found.\nTests are added for these`. You can customize the `fieldPattern`.
58
195
 
196
+ ## API
59
197
 
60
- ## Install
61
-
62
- ```sh
63
- $ npm install --save conventional-commits-parser
64
- ```
65
-
198
+ ### `new CommitParser(options?: ParserOptions)`
66
199
 
67
- ## Usage
200
+ Creates parser instance with `parse` method.
68
201
 
69
- ```js
70
- var conventionalCommitsParser = require('conventional-commits-parser');
202
+ ### `parseCommits(options?: ParserOptions)`
71
203
 
72
- conventionalCommitsParser(options);
73
- ```
204
+ Create async generator function to parse async iterable of raw commits. If there is any malformed commits it will be gracefully ignored (an empty data will be emitted so down async iterable can notice).
74
205
 
75
- It returns a transform stream and expects an upstream that looks something like this:
206
+ ### `parseCommitsStream(options?: ParserOptions)`
76
207
 
77
- ```
78
- 'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
79
- 'feat(ng-list): Allow custom separator\nbla bla bla\n\nBREAKING CHANGE: some breaking change.\nThanks @stevemao\n'
80
- ```
208
+ Creates an transform stream. If there is any malformed commits it will be gracefully ignored (an empty data will be emitted so down stream can notice).
81
209
 
82
- Each chunk should be a commit. The downstream will look something like this:
210
+ ### ParserOptions
83
211
 
84
- ```js
85
- { type: 'feat',
86
- scope: 'scope',
87
- subject: 'broadcast $destroy event on scope destruction',
88
- merge: null,
89
- header: 'feat(scope): broadcast $destroy event on scope destruction',
90
- body: null,
91
- footer: 'Closes #1',
92
- notes: [],
93
- references:
94
- [ { action: 'Closes',
95
- owner: null,
96
- repository: null,
97
- issue: '1',
98
- raw: '#1',
99
- prefix: '#' } ],
100
- mentions: [],
101
- revert: null }
102
- { type: 'feat',
103
- scope: 'ng-list',
104
- subject: 'Allow custom separator',
105
- merge: null,
106
- header: 'feat(ng-list): Allow custom separator',
107
- body: 'bla bla bla',
108
- footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao',
109
- notes:
110
- [ { title: 'BREAKING CHANGE',
111
- text: 'some breaking change.\nThanks @stevemao' } ],
112
- references: [],
113
- mentions: [ 'stevemao' ],
114
- revert: null }
115
- ```
116
-
117
-
118
- ## API
119
-
120
- ### conventionalCommitsParser([options])
121
-
122
- Returns an transform stream. If there is any malformed commits it will be gracefully ignored (an empty data will be emitted so down stream can notice).
212
+ #### mergePattern
123
213
 
124
- #### options
125
-
126
- Type: `object`
127
-
128
- ##### mergePattern
129
-
130
- Type: `regex` or `string` Default: null
214
+ Type: `RegExp`
215
+ Default: null
131
216
 
132
217
  Pattern to match merge headers. EG: branch merge, GitHub or GitLab like pull requests headers. When a merge header is parsed, the next line is used for conventional header parsing.
133
218
 
@@ -148,85 +233,82 @@ We can parse it with these options and the default headerPattern:
148
233
  }
149
234
  ```
150
235
 
151
- ##### mergeCorrespondence
236
+ #### mergeCorrespondence
152
237
 
153
- Type: `array` of `string` or `string` Default: null
238
+ Type: `string[]`,
239
+ Default: null
154
240
 
155
241
  Used to define what capturing group of `mergePattern`.
156
242
 
157
- If it's a `string` it will be converted to an `array` separated by a comma.
243
+ #### headerPattern
158
244
 
159
- ##### headerPattern
160
-
161
- Type: `regex` or `string` Default: `/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/`
245
+ Type: `RegExp`,
246
+ Default: `/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/`
162
247
 
163
248
  Used to match header pattern.
164
249
 
165
- ##### headerCorrespondence
250
+ #### headerCorrespondence
166
251
 
167
- Type: `array` of `string` or `string` Default `['type', 'scope', 'subject']`
252
+ Type: `string[]`,
253
+ Default `['type', 'scope', 'subject']`
168
254
 
169
- Used to define what capturing group of `headerPattern` captures what header part. The order of the array should correspond to the order of `headerPattern`'s capturing group. If the part is not captured it is `null`. If it's a `string` it will be converted to an `array` separated by a comma.
255
+ Used to define what capturing group of `headerPattern` captures what header part. The order of the array should correspond to the order of `headerPattern`'s capturing group. If the part is not captured it is `null`.
170
256
 
171
- ##### referenceActions
257
+ #### referenceActions
172
258
 
173
- Type: `array` of `string` or `string` Default:
174
- `[
175
- 'close',
176
- 'closes',
177
- 'closed',
178
- 'fix',
179
- 'fixes',
180
- 'fixed',
181
- 'resolve',
182
- 'resolves',
183
- 'resolved'
184
- ]`
259
+ Type: `string[]`,
260
+ Default: `['close', 'closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved']`
185
261
 
186
- Keywords to reference an issue. This value is case **insensitive**. If it's a `string` it will be converted to an `array` separated by a comma.
262
+ Keywords to reference an issue. This value is case **insensitive**.
187
263
 
188
264
  Set it to `null` to reference an issue without any action.
189
265
 
190
- ##### issuePrefixes
266
+ #### issuePrefixes
191
267
 
192
- Type: `array` of `string` or `string` Default: `['#']`
268
+ Type: `string[]`,
269
+ Default: `['#']`
193
270
 
194
271
  The prefixes of an issue. EG: In `gh-123` `gh-` is the prefix.
195
272
 
196
- ##### issuePrefixesCaseSensitive
273
+ #### issuePrefixesCaseSensitive
197
274
 
198
- Type: `boolean` Default: false
275
+ Type: `boolean`,
276
+ Default: false
199
277
 
200
278
  Used to define if `issuePrefixes` should be considered case sensitive.
201
279
 
202
- ##### noteKeywords
280
+ #### noteKeywords
203
281
 
204
- Type: `array` of `string` or `string` Default: `['BREAKING CHANGE',
205
- 'BREAKING-CHANGE']`
282
+ Type: `string[]`,
283
+ Default: `['BREAKING CHANGE', 'BREAKING-CHANGE']`
206
284
 
207
- Keywords for important notes. This value is case **insensitive**. If it's a `string` it will be converted to an `array` separated by a comma.
285
+ Keywords for important notes. This value is case **insensitive**.
208
286
 
209
- ##### notesPattern
287
+ #### notesPattern
210
288
 
211
- Type: `function` Default: `noteKeywordsSelection => ^[\\s|*]*(' + noteKeywordsSelection + ')[:\\s]+(.*)` where `noteKeywordsSelection` is `join(noteKeywords, '|')`
289
+ Type: `function`,
290
+ Default: `noteKeywordsSelection => ^[\\s|*]*(' + noteKeywordsSelection + ')[:\\s]+(.*)` where `noteKeywordsSelection` is `join(noteKeywords, '|')`
212
291
 
213
292
  A function that takes `noteKeywordsSelection` and returns a `RegExp` to be matched against the notes.
214
293
 
215
- ##### fieldPattern
294
+ #### fieldPattern
216
295
 
217
- Type: `regex` or `string` Default: `/^-(.*?)-$/`
296
+ Type: `RegExp`,
297
+ Default: `/^-(.*?)-$/`
218
298
 
219
299
  Pattern to match other fields.
220
300
 
221
- ##### revertPattern
301
+ #### revertPattern
222
302
 
223
- Type: `regex` or `string` Default: `/^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./`
303
+ Type: `RegExp`,
304
+ Default: `/^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./`
224
305
 
225
306
  Pattern to match what this commit reverts.
226
307
 
227
- ##### revertCorrespondence
308
+ #### revertCorrespondence
228
309
 
229
- Type: `array` of `string` or `string` Default: `['header', 'hash']`
310
+ Type: `string[]`,
311
+ Default: `['header', 'hash']`
230
312
 
231
313
  Used to define what capturing group of `revertPattern` captures what reverted commit fields. The order of the array should correspond to the order of `revertPattern`'s capturing group.
232
314
 
@@ -251,48 +333,31 @@ If configured correctly, the parsed result would be
251
333
 
252
334
  It implies that this commit reverts a commit with header `'throw an error if a callback is passed'` and hash `'9bb4d6c'`.
253
335
 
254
- If it's a `string` it will be converted to an `array` separated by a comma.
255
-
256
- ##### commentChar
336
+ #### commentChar
257
337
 
258
- Type: `string` or `null` Default: null
338
+ Type: `string` or `null`,
339
+ Default: null
259
340
 
260
341
  What commentChar to use. By default it is `null`, so no comments are stripped.
261
342
  Set to `#` if you pass the contents of `.git/COMMIT_EDITMSG` directly.
262
343
 
263
344
  If you have configured the git commentchar via `git config core.commentchar` you'll want to pass what you have set there.
264
345
 
265
- ##### warn
266
-
267
- Type: `function` or `boolean` Default: `function() {}`
346
+ #### warn
268
347
 
269
- What warn function to use. For example, `console.warn.bind(console)` or `grunt.log.writeln`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict).
270
-
271
- ### conventionalCommitsParser.sync(commit, [options])
272
-
273
- The sync version. Useful when parsing a single commit. Returns the result.
274
-
275
- #### commit
276
-
277
- A single commit to be parsed.
278
-
279
- #### options
280
-
281
- Same as the `options` of `conventionalCommitsParser`.
348
+ Type: `function` or `boolean`,
349
+ Default: `() => {}`
282
350
 
351
+ What warn function to use. For example, `console.warn.bind(console)`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict).
283
352
 
284
353
  ## CLI
285
354
 
286
355
  You can use cli to practice writing commit messages or parse messages from files. Note: the sample output might be different. It's just for demonstration purposes.
287
356
 
288
- ```sh
289
- $ npm install --global conventional-commits-parser
290
- ```
291
-
292
357
  If you run `conventional-commits-parser` without any arguments
293
358
 
294
359
  ```sh
295
- $ conventional-commits-parser
360
+ $ conventional-commits-parser --help # for more details
296
361
  ```
297
362
 
298
363
  You will enter an interactive shell. To show your parsed output enter "return" three times (or enter your specified separator).
@@ -367,17 +432,6 @@ Will be printed out.
367
432
 
368
433
  You can specify one or more files. The output array will be in order of the input file paths. If you specify more than one separator, the last one will be used.
369
434
 
370
-
371
435
  ## License
372
436
 
373
437
  MIT © [Steve Mao](https://github.com/stevemao)
374
-
375
-
376
- [npm-image]: https://badge.fury.io/js/conventional-commits-parser.svg
377
- [npm-url]: https://npmjs.org/package/conventional-commits-parser
378
- [travis-image]: https://travis-ci.org/conventional-changelog/conventional-commits-parser.svg?branch=master
379
- [travis-url]: https://travis-ci.org/conventional-changelog/conventional-commits-parser
380
- [daviddm-image]: https://david-dm.org/conventional-changelog/conventional-commits-parser.svg?theme=shields.io
381
- [daviddm-url]: https://david-dm.org/conventional-changelog/conventional-commits-parser
382
- [coverage-image]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
383
- [coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
@@ -0,0 +1,40 @@
1
+ import type { ParserOptions, Commit } from './types.js';
2
+ /**
3
+ * Helper to create commit object.
4
+ * @param initialData - Initial commit data.
5
+ * @returns Commit object with empty data.
6
+ */
7
+ export declare function createCommitObject(initialData?: Partial<Commit>): Commit;
8
+ /**
9
+ * Commit message parser.
10
+ */
11
+ export declare class CommitParser {
12
+ private readonly options;
13
+ private readonly regexes;
14
+ private lines;
15
+ private lineIndex;
16
+ private commit;
17
+ constructor(options?: ParserOptions);
18
+ private currentLine;
19
+ private nextLine;
20
+ private isLineAvailable;
21
+ private parseReference;
22
+ private parseReferences;
23
+ private skipEmptyLines;
24
+ private parseMerge;
25
+ private parseHeader;
26
+ private parseMeta;
27
+ private parseNotes;
28
+ private parseBodyAndFooter;
29
+ private parseBreakingHeader;
30
+ private parseMentions;
31
+ private parseRevert;
32
+ private cleanupCommit;
33
+ /**
34
+ * Parse commit message string into an object.
35
+ * @param input - Commit message string.
36
+ * @returns Commit object.
37
+ */
38
+ parse(input: string): Commit;
39
+ }
40
+ //# sourceMappingURL=CommitParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommitParser.d.ts","sourceRoot":"","sources":["../src/CommitParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAKb,MAAM,EACP,MAAM,YAAY,CAAA;AAWnB;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,OAAO,CAAC,MAAM,CAAM,GAAG,MAAM,CAa5E;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,SAAS,CAAI;IACrB,OAAO,CAAC,MAAM,CAAuB;gBAEzB,OAAO,GAAE,aAAkB;IAQvC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,cAAc;IAsCtB,OAAO,CAAC,eAAe;IAqCvB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU;IAuBlB,OAAO,CAAC,WAAW;IA+BnB,OAAO,CAAC,SAAS;IAmCjB,OAAO,CAAC,UAAU;IAsDlB,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,aAAa;IAgBrB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM;CA2CpB"}