@zentered/issue-forms-body-parser 1.2.0 → 1.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.
package/README.md CHANGED
@@ -77,7 +77,7 @@ to structured, usable data:
77
77
  "id": "date",
78
78
  "title": "Date",
79
79
  "text": "11.03.2022\n",
80
- "date": "2022-03-11T00:00:00.000Z"
80
+ "date": "2022-03-11"
81
81
  },
82
82
  { "id": "time", "title": "Time", "text": "16:00\n", "time": "16:00" }
83
83
  ]
@@ -86,6 +86,14 @@ to structured, usable data:
86
86
  See more examples in [md test cases](./test/test-issue-1.md) and
87
87
  [test results](./test/parse-issue-test.md]).
88
88
 
89
+ ### Parsers
90
+
91
+ - `date`: checks if the value matches a [common date format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parse.js#L14) and returns a formatted `date` field (in UTC).
92
+ - `time`: checks if the value matches a [common time format](https://github.com/zentered/issue-forms-body-parser/blob/main/src/parse.js#L24) and returns a formatted `time` field.
93
+ - `lists`: automatically returns lists as arrays
94
+ - `duration`: currently only the format `XXhYYm` is supported as duration, ie. `1h30m` returns a `duration` object with `hours` and `minutes`.
95
+
96
+
89
97
  ## Installation & Usage
90
98
 
91
99
  ### GitHub Actions
@@ -101,7 +109,7 @@ jobs:
101
109
  steps:
102
110
  - name: Issue Forms Body Parser
103
111
  id: parse
104
- uses: zentered/issue-forms-body-parser@1.0.0
112
+ uses: zentered/issue-forms-body-parser@v1.2.0
105
113
  - run: echo "${{ JSON.stringify(steps.parse.outputs.data) }}"
106
114
  ```
107
115
 
package/dist/index.js CHANGED
@@ -51789,6 +51789,22 @@ function remarkStringify(options) {
51789
51789
 
51790
51790
  // EXTERNAL MODULE: ./node_modules/date-fns/index.js
51791
51791
  var date_fns = __nccwpck_require__(3314);
51792
+ ;// CONCATENATED MODULE: ./node_modules/strip-final-newline/index.js
51793
+ function stripFinalNewline(input) {
51794
+ const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
51795
+ const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
51796
+
51797
+ if (input[input.length - 1] === LF) {
51798
+ input = input.slice(0, -1);
51799
+ }
51800
+
51801
+ if (input[input.length - 1] === CR) {
51802
+ input = input.slice(0, -1);
51803
+ }
51804
+
51805
+ return input;
51806
+ }
51807
+
51792
51808
  // EXTERNAL MODULE: ./node_modules/date-fns/_lib/cloneObject/index.js
51793
51809
  var cloneObject = __nccwpck_require__(7934);
51794
51810
  // EXTERNAL MODULE: ./node_modules/date-fns/_lib/toInteger/index.js
@@ -53188,6 +53204,7 @@ function formatInTimeZone(date, timeZone, formatStr, options) {
53188
53204
 
53189
53205
 
53190
53206
 
53207
+
53191
53208
  // if the system time is not UTC, we need to convert it to UTC
53192
53209
 
53193
53210
  const loc = 'UTC'
@@ -53298,10 +53315,11 @@ async function parseMD(body) {
53298
53315
  if (next.type === 'list') {
53299
53316
  obj.list = parseList(next).flat()
53300
53317
  }
53301
- obj.text = await unified()
53318
+ const text = await unified()
53302
53319
  .use(remarkGfm)
53303
53320
  .use(remark_stringify)
53304
53321
  .stringify(next)
53322
+ obj.text = stripFinalNewline(text)
53305
53323
  const date = parse_parseDate(obj.text)
53306
53324
  const time = parse_parseTime(obj.text)
53307
53325
  if (date) {
package/dist/licenses.txt CHANGED
@@ -1429,6 +1429,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1429
1429
  THE SOFTWARE.
1430
1430
 
1431
1431
 
1432
+ strip-final-newline
1433
+ MIT
1434
+ MIT License
1435
+
1436
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
1437
+
1438
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1439
+
1440
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1441
+
1442
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1443
+
1444
+
1432
1445
  tr46
1433
1446
  MIT
1434
1447
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zentered/issue-forms-body-parser",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "description": "Parser for GitHub Issue Form body, also available as GitHub Action",
6
6
  "keywords": [
@@ -62,6 +62,7 @@
62
62
  "remark-gfm": "^3.0.1",
63
63
  "remark-parse": "^10.0.1",
64
64
  "remark-stringify": "^10.0.2",
65
+ "strip-final-newline": "^3.0.0",
65
66
  "unified": "^10.1.2"
66
67
  },
67
68
  "devDependencies": {
package/src/parse.js CHANGED
@@ -6,6 +6,7 @@ import remarkGfm from 'remark-gfm'
6
6
  import slugify from '@sindresorhus/slugify'
7
7
  import remarkStringify from 'remark-stringify'
8
8
  import { parse, isMatch } from 'date-fns'
9
+ import stripFinalNewline from 'strip-final-newline'
9
10
 
10
11
  // if the system time is not UTC, we need to convert it to UTC
11
12
  import { zonedTimeToUtc, formatInTimeZone } from 'date-fns-tz/esm'
@@ -117,10 +118,11 @@ export default async function parseMD(body) {
117
118
  if (next.type === 'list') {
118
119
  obj.list = parseList(next).flat()
119
120
  }
120
- obj.text = await unified()
121
+ const text = await unified()
121
122
  .use(remarkGfm)
122
123
  .use(remarkStringify)
123
124
  .stringify(next)
125
+ obj.text = stripFinalNewline(text)
124
126
  const date = parseDate(obj.text)
125
127
  const time = parseTime(obj.text)
126
128
  if (date) {
@@ -12,24 +12,24 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
12
12
  {
13
13
  id: 'event-description',
14
14
  title: 'Event Description',
15
- text: "Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed\nCDC (Cyprus Developer Community).\n"
15
+ text: "Let's meet for coffee and chat about tech, coding, Cyprus and the newly formed\nCDC (Cyprus Developer Community)."
16
16
  },
17
17
  {
18
18
  id: 'location',
19
19
  title: 'Location',
20
- text: '[Cafe Nero Finikoudes, Larnaka](https://goo.gl/maps/Bzjxdeat3BSdsUSVA)\n'
20
+ text: '[Cafe Nero Finikoudes, Larnaka](https://goo.gl/maps/Bzjxdeat3BSdsUSVA)'
21
21
  },
22
22
  {
23
23
  id: 'date',
24
24
  title: 'Date',
25
- text: '11.03.2022\n',
25
+ text: '11.03.2022',
26
26
  date: '2022-03-11'
27
27
  },
28
- { id: 'time', title: 'Time', text: '16:00\n', time: '16:00' },
28
+ { id: 'time', title: 'Time', text: '16:00', time: '16:00' },
29
29
  {
30
30
  id: 'duration',
31
31
  title: 'Duration',
32
- text: '2h\n',
32
+ text: '2h',
33
33
  duration: { hours: 2, minutes: 0 }
34
34
  },
35
35
  {
@@ -41,7 +41,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
41
41
  text: "I agree to follow this project's\nCode of Conduct"
42
42
  }
43
43
  ],
44
- text: "* [x] I agree to follow this project's\n [Code of Conduct](https://berlincodeofconduct.org)\n"
44
+ text: "* [x] I agree to follow this project's\n [Code of Conduct](https://berlincodeofconduct.org)"
45
45
  },
46
46
  {
47
47
  id: 'list-item-unchecked',
@@ -52,7 +52,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
52
52
  text: "I agree to follow this project's\nCode of Conduct"
53
53
  }
54
54
  ],
55
- text: "* [ ] I agree to follow this project's\n [Code of Conduct](https://berlincodeofconduct.org)\n"
55
+ text: "* [ ] I agree to follow this project's\n [Code of Conduct](https://berlincodeofconduct.org)"
56
56
  },
57
57
  {
58
58
  id: 'mixed-task-list',
@@ -64,7 +64,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
64
64
  { checked: true, text: 'checked 3' },
65
65
  { checked: false, text: 'unchecked 2' }
66
66
  ],
67
- text: '* [x] checked\n* [ ] unchecked\n* [x] checked 2\n* [x] checked 3\n* [ ] unchecked 2\n'
67
+ text: '* [x] checked\n* [ ] unchecked\n* [x] checked 2\n* [x] checked 3\n* [ ] unchecked 2'
68
68
  },
69
69
  {
70
70
  id: 'complex-list',
@@ -73,17 +73,17 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
73
73
  { checked: null, text: 'one' },
74
74
  { checked: null, text: 'two' }
75
75
  ],
76
- text: '* one\n* two\n * three\n * four\n 1. five\n 2. six\n'
76
+ text: '* one\n* two\n * three\n * four\n 1. five\n 2. six'
77
77
  },
78
78
  {
79
79
  id: 'repositories',
80
80
  title: 'Repositories',
81
- text: '```csv\nhttps://example.com/repository-1\nhttps://example.com/repository-2\n```\n'
81
+ text: '```csv\nhttps://example.com/repository-1\nhttps://example.com/repository-2\n```'
82
82
  },
83
83
  {
84
84
  id: 'visibility',
85
85
  title: 'Visibility',
86
- text: 'Internal\n'
86
+ text: 'Internal'
87
87
  }
88
88
  ]
89
89