@zentered/issue-forms-body-parser 1.1.3 → 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
@@ -53187,6 +53203,8 @@ function formatInTimeZone(date, timeZone, formatStr, options) {
53187
53203
 
53188
53204
 
53189
53205
 
53206
+
53207
+
53190
53208
  // if the system time is not UTC, we need to convert it to UTC
53191
53209
 
53192
53210
  const loc = 'UTC'
@@ -53201,17 +53219,30 @@ const commonDateFormats = [
53201
53219
  'dd.MM.yy'
53202
53220
  ]
53203
53221
 
53204
- const commonTimeFormats = ['HH:mm', 'hh:mm a', 'hh:mm A']
53222
+ const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
53223
+
53224
+ function parseDuration(text) {
53225
+ const duration = {
53226
+ hours: 0,
53227
+ minutes: 0
53228
+ }
53229
+
53230
+ const pieces = text.replace('m', '').split('h')
53231
+ duration.hours = parseInt(pieces[0]) ? parseInt(pieces[0]) : 0
53232
+ duration.minutes = parseInt(pieces[1]) ? parseInt(pieces[1]) : 0
53233
+ return duration
53234
+ }
53205
53235
 
53206
53236
  function parse_parseDate(text) {
53207
53237
  const match = commonDateFormats.map((format) => {
53208
53238
  return (0,date_fns.isMatch)(text, format)
53209
53239
  })
53210
53240
  if (match.indexOf(true) > -1) {
53211
- return zonedTimeToUtc(
53241
+ const date = zonedTimeToUtc(
53212
53242
  (0,date_fns.parse)(text, commonDateFormats[match.indexOf(true)], new Date()),
53213
53243
  loc
53214
53244
  ).toJSON()
53245
+ return date.split('T')[0]
53215
53246
  } else {
53216
53247
  return null
53217
53248
  }
@@ -53284,10 +53315,11 @@ async function parseMD(body) {
53284
53315
  if (next.type === 'list') {
53285
53316
  obj.list = parseList(next).flat()
53286
53317
  }
53287
- obj.text = await unified()
53318
+ const text = await unified()
53288
53319
  .use(remarkGfm)
53289
53320
  .use(remark_stringify)
53290
53321
  .stringify(next)
53322
+ obj.text = stripFinalNewline(text)
53291
53323
  const date = parse_parseDate(obj.text)
53292
53324
  const time = parse_parseTime(obj.text)
53293
53325
  if (date) {
@@ -53296,6 +53328,9 @@ async function parseMD(body) {
53296
53328
  if (time) {
53297
53329
  obj.time = time
53298
53330
  }
53331
+ if (obj.id === 'duration') {
53332
+ obj.duration = parseDuration(obj.text)
53333
+ }
53299
53334
  }
53300
53335
  r.push(obj)
53301
53336
  }
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.1.3",
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,8 @@ 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'
10
+
9
11
  // if the system time is not UTC, we need to convert it to UTC
10
12
  import { zonedTimeToUtc, formatInTimeZone } from 'date-fns-tz/esm'
11
13
  const loc = 'UTC'
@@ -20,17 +22,30 @@ const commonDateFormats = [
20
22
  'dd.MM.yy'
21
23
  ]
22
24
 
23
- const commonTimeFormats = ['HH:mm', 'hh:mm a', 'hh:mm A']
25
+ const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
26
+
27
+ function parseDuration(text) {
28
+ const duration = {
29
+ hours: 0,
30
+ minutes: 0
31
+ }
32
+
33
+ const pieces = text.replace('m', '').split('h')
34
+ duration.hours = parseInt(pieces[0]) ? parseInt(pieces[0]) : 0
35
+ duration.minutes = parseInt(pieces[1]) ? parseInt(pieces[1]) : 0
36
+ return duration
37
+ }
24
38
 
25
39
  function parseDate(text) {
26
40
  const match = commonDateFormats.map((format) => {
27
41
  return isMatch(text, format)
28
42
  })
29
43
  if (match.indexOf(true) > -1) {
30
- return zonedTimeToUtc(
44
+ const date = zonedTimeToUtc(
31
45
  parse(text, commonDateFormats[match.indexOf(true)], new Date()),
32
46
  loc
33
47
  ).toJSON()
48
+ return date.split('T')[0]
34
49
  } else {
35
50
  return null
36
51
  }
@@ -103,10 +118,11 @@ export default async function parseMD(body) {
103
118
  if (next.type === 'list') {
104
119
  obj.list = parseList(next).flat()
105
120
  }
106
- obj.text = await unified()
121
+ const text = await unified()
107
122
  .use(remarkGfm)
108
123
  .use(remarkStringify)
109
124
  .stringify(next)
125
+ obj.text = stripFinalNewline(text)
110
126
  const date = parseDate(obj.text)
111
127
  const time = parseTime(obj.text)
112
128
  if (date) {
@@ -115,6 +131,9 @@ export default async function parseMD(body) {
115
131
  if (time) {
116
132
  obj.time = time
117
133
  }
134
+ if (obj.id === 'duration') {
135
+ obj.duration = parseDuration(obj.text)
136
+ }
118
137
  }
119
138
  r.push(obj)
120
139
  }
@@ -12,21 +12,26 @@ 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',
26
- date: '2022-03-11T00:00:00.000Z'
25
+ text: '11.03.2022',
26
+ date: '2022-03-11'
27
+ },
28
+ { id: 'time', title: 'Time', text: '16:00', time: '16:00' },
29
+ {
30
+ id: 'duration',
31
+ title: 'Duration',
32
+ text: '2h',
33
+ duration: { hours: 2, minutes: 0 }
27
34
  },
28
- { id: 'time', title: 'Time', text: '16:00\n', time: '16:00' },
29
- { id: 'duration', title: 'Duration', text: '2h\n' },
30
35
  {
31
36
  id: 'list-item-checked',
32
37
  title: 'List Item Checked',
@@ -36,7 +41,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
36
41
  text: "I agree to follow this project's\nCode of Conduct"
37
42
  }
38
43
  ],
39
- 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)"
40
45
  },
41
46
  {
42
47
  id: 'list-item-unchecked',
@@ -47,7 +52,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
47
52
  text: "I agree to follow this project's\nCode of Conduct"
48
53
  }
49
54
  ],
50
- 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)"
51
56
  },
52
57
  {
53
58
  id: 'mixed-task-list',
@@ -59,7 +64,7 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
59
64
  { checked: true, text: 'checked 3' },
60
65
  { checked: false, text: 'unchecked 2' }
61
66
  ],
62
- 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'
63
68
  },
64
69
  {
65
70
  id: 'complex-list',
@@ -68,17 +73,17 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
68
73
  { checked: null, text: 'one' },
69
74
  { checked: null, text: 'two' }
70
75
  ],
71
- 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'
72
77
  },
73
78
  {
74
79
  id: 'repositories',
75
80
  title: 'Repositories',
76
- 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```'
77
82
  },
78
83
  {
79
84
  id: 'visibility',
80
85
  title: 'Visibility',
81
- text: 'Internal\n'
86
+ text: 'Internal'
82
87
  }
83
88
  ]
84
89