@zentered/issue-forms-body-parser 1.1.2 → 1.2.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/dist/index.js CHANGED
@@ -51888,9 +51888,25 @@ function getDateTimeFormat(timeZone) {
51888
51888
  return dtfCache[timeZone]
51889
51889
  }
51890
51890
 
51891
+ ;// CONCATENATED MODULE: ./node_modules/date-fns-tz/esm/_lib/newDateUTC/index.js
51892
+ /**
51893
+ * Use instead of `new Date(Date.UTC(...))` to support years below 100 which doesn't work
51894
+ * otherwise due to the nature of the
51895
+ * [`Date` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years.
51896
+ *
51897
+ * For `Date.UTC(...)`, use `newDateUTC(...).getTime()`.
51898
+ */
51899
+ function newDateUTC(fullYear, month, day, hour, minute, second, millisecond) {
51900
+ var utcDate = new Date(0)
51901
+ utcDate.setUTCFullYear(fullYear, month, day)
51902
+ utcDate.setUTCHours(hour, minute, second, millisecond)
51903
+ return utcDate
51904
+ }
51905
+
51891
51906
  ;// CONCATENATED MODULE: ./node_modules/date-fns-tz/esm/_lib/tzParseTimezone/index.js
51892
51907
 
51893
51908
 
51909
+
51894
51910
  var MILLISECONDS_IN_HOUR = 3600000
51895
51911
  var MILLISECONDS_IN_MINUTE = 60000
51896
51912
 
@@ -51961,23 +51977,30 @@ function tzParseTimezone(timezoneString, date, isUtcDate) {
51961
51977
  }
51962
51978
 
51963
51979
  function toUtcDate(date) {
51964
- return new Date(
51965
- Date.UTC(
51966
- date.getFullYear(),
51967
- date.getMonth(),
51968
- date.getDate(),
51969
- date.getHours(),
51970
- date.getMinutes(),
51971
- date.getSeconds(),
51972
- date.getMilliseconds()
51973
- )
51980
+ return newDateUTC(
51981
+ date.getFullYear(),
51982
+ date.getMonth(),
51983
+ date.getDate(),
51984
+ date.getHours(),
51985
+ date.getMinutes(),
51986
+ date.getSeconds(),
51987
+ date.getMilliseconds()
51974
51988
  )
51975
51989
  }
51976
51990
 
51977
51991
  function calcOffset(date, timezoneString) {
51978
51992
  var tokens = tzTokenizeDate(date, timezoneString)
51979
51993
 
51980
- var asUTC = Date.UTC(tokens[0], tokens[1] - 1, tokens[2], tokens[3] % 24, tokens[4], tokens[5])
51994
+ // ms dropped because it's not provided by tzTokenizeDate
51995
+ var asUTC = newDateUTC(
51996
+ tokens[0],
51997
+ tokens[1] - 1,
51998
+ tokens[2],
51999
+ tokens[3] % 24,
52000
+ tokens[4],
52001
+ tokens[5],
52002
+ 0
52003
+ ).getTime()
51981
52004
 
51982
52005
  var asTS = date.getTime()
51983
52006
  var over = asTS % 1000
@@ -52013,10 +52036,7 @@ function fixOffset(date, offset, timezoneString) {
52013
52036
  }
52014
52037
 
52015
52038
  function validateTimezone(hours, minutes) {
52016
- return (
52017
- (hours === 12 && (minutes == null || minutes === 0)) ||
52018
- (-11 <= hours && hours <= 11 && (minutes == null || (0 <= minutes && minutes < 59)))
52019
- )
52039
+ return -23 <= hours && hours <= 23 && (minutes == null || (0 <= minutes && minutes <= 59))
52020
52040
  }
52021
52041
 
52022
52042
  var validIANATimezoneCache = {}
@@ -52497,6 +52517,7 @@ function validateTime(hours, minutes, seconds) {
52497
52517
 
52498
52518
 
52499
52519
 
52520
+
52500
52521
  /**
52501
52522
  * @name zonedTimeToUtc
52502
52523
  * @category Time Zone Helpers
@@ -52530,7 +52551,7 @@ function zonedTimeToUtc(date, timeZone, options) {
52530
52551
 
52531
52552
  var d = toDate(date, options)
52532
52553
 
52533
- var utc = Date.UTC(
52554
+ var utc = newDateUTC(
52534
52555
  d.getFullYear(),
52535
52556
  d.getMonth(),
52536
52557
  d.getDate(),
@@ -52538,7 +52559,7 @@ function zonedTimeToUtc(date, timeZone, options) {
52538
52559
  d.getMinutes(),
52539
52560
  d.getSeconds(),
52540
52561
  d.getMilliseconds()
52541
- )
52562
+ ).getTime()
52542
52563
 
52543
52564
  var offsetMilliseconds = tzParseTimezone(timeZone, new Date(utc))
52544
52565
 
@@ -52705,7 +52726,7 @@ function formatTimezone(offset, dirtyDelimeter) {
52705
52726
  var sign = offset > 0 ? '-' : '+'
52706
52727
  var absOffset = Math.abs(offset)
52707
52728
  var hours = addLeadingZeros(Math.floor(absOffset / 60), 2)
52708
- var minutes = addLeadingZeros(absOffset % 60, 2)
52729
+ var minutes = addLeadingZeros(Math.floor(absOffset % 60), 2)
52709
52730
  return sign + hours + delimeter + minutes
52710
52731
  }
52711
52732
 
@@ -53166,6 +53187,7 @@ function formatInTimeZone(date, timeZone, formatStr, options) {
53166
53187
 
53167
53188
 
53168
53189
 
53190
+
53169
53191
  // if the system time is not UTC, we need to convert it to UTC
53170
53192
 
53171
53193
  const loc = 'UTC'
@@ -53180,17 +53202,30 @@ const commonDateFormats = [
53180
53202
  'dd.MM.yy'
53181
53203
  ]
53182
53204
 
53183
- const commonTimeFormats = ['HH:mm', 'hh:mm a', 'hh:mm A']
53205
+ const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
53206
+
53207
+ function parseDuration(text) {
53208
+ const duration = {
53209
+ hours: 0,
53210
+ minutes: 0
53211
+ }
53212
+
53213
+ const pieces = text.replace('m', '').split('h')
53214
+ duration.hours = parseInt(pieces[0]) ? parseInt(pieces[0]) : 0
53215
+ duration.minutes = parseInt(pieces[1]) ? parseInt(pieces[1]) : 0
53216
+ return duration
53217
+ }
53184
53218
 
53185
53219
  function parse_parseDate(text) {
53186
53220
  const match = commonDateFormats.map((format) => {
53187
53221
  return (0,date_fns.isMatch)(text, format)
53188
53222
  })
53189
53223
  if (match.indexOf(true) > -1) {
53190
- return zonedTimeToUtc(
53224
+ const date = zonedTimeToUtc(
53191
53225
  (0,date_fns.parse)(text, commonDateFormats[match.indexOf(true)], new Date()),
53192
53226
  loc
53193
53227
  ).toJSON()
53228
+ return date.split('T')[0]
53194
53229
  } else {
53195
53230
  return null
53196
53231
  }
@@ -53252,10 +53287,12 @@ async function parseMD(body) {
53252
53287
  const current = tokens.children[idx]
53253
53288
  const hasNext = idx + 1 < tokens.children.length
53254
53289
 
53255
- const obj = {}
53256
53290
  if (current.type === 'heading') {
53257
- obj.id = slugify(current.children[0].value)
53258
- obj.title = current.children[0].value
53291
+ // issue-form answers start with a h3 heading, ignore everything else
53292
+ const obj = {
53293
+ id: slugify(current.children[0].value),
53294
+ title: current.children[0].value
53295
+ }
53259
53296
  if (hasNext) {
53260
53297
  const next = tokens.children[idx + 1]
53261
53298
  if (next.type === 'list') {
@@ -53273,9 +53310,12 @@ async function parseMD(body) {
53273
53310
  if (time) {
53274
53311
  obj.time = time
53275
53312
  }
53313
+ if (obj.id === 'duration') {
53314
+ obj.duration = parseDuration(obj.text)
53315
+ }
53276
53316
  }
53317
+ r.push(obj)
53277
53318
  }
53278
- r.push(obj)
53279
53319
  }
53280
53320
 
53281
53321
  return r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zentered/issue-forms-body-parser",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "description": "Parser for GitHub Issue Form body, also available as GitHub Action",
6
6
  "keywords": [
@@ -55,10 +55,10 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@actions/core": "^1.6.0",
58
- "@actions/github": "^5.0.0",
58
+ "@actions/github": "^5.0.1",
59
59
  "@sindresorhus/slugify": "^2.1.0",
60
60
  "date-fns": "^2.28.0",
61
- "date-fns-tz": "^1.3.0",
61
+ "date-fns-tz": "^1.3.3",
62
62
  "remark-gfm": "^3.0.1",
63
63
  "remark-parse": "^10.0.1",
64
64
  "remark-stringify": "^10.0.2",
@@ -68,15 +68,15 @@
68
68
  "@commitlint/config-conventional": "^16.2.1",
69
69
  "@vercel/ncc": "^0.33.3",
70
70
  "commitlint": "^16.2.3",
71
- "eslint": "^8.11.0",
71
+ "eslint": "^8.12.0",
72
72
  "eslint-plugin-json": "^3.1.0",
73
73
  "eslint-plugin-node": "^11.1.0",
74
74
  "husky": "^7.0.4",
75
75
  "license-checker": "^25.0.1",
76
76
  "npm-run-all": "^4.1.5",
77
77
  "pinst": "^3.0.0",
78
- "prettier": "^2.6.0",
79
- "tap": "^16.0.0"
78
+ "prettier": "^2.6.2",
79
+ "tap": "^16.0.1"
80
80
  },
81
81
  "release": {
82
82
  "branches": [
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
+
9
10
  // if the system time is not UTC, we need to convert it to UTC
10
11
  import { zonedTimeToUtc, formatInTimeZone } from 'date-fns-tz/esm'
11
12
  const loc = 'UTC'
@@ -20,17 +21,30 @@ const commonDateFormats = [
20
21
  'dd.MM.yy'
21
22
  ]
22
23
 
23
- const commonTimeFormats = ['HH:mm', 'hh:mm a', 'hh:mm A']
24
+ const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
25
+
26
+ function parseDuration(text) {
27
+ const duration = {
28
+ hours: 0,
29
+ minutes: 0
30
+ }
31
+
32
+ const pieces = text.replace('m', '').split('h')
33
+ duration.hours = parseInt(pieces[0]) ? parseInt(pieces[0]) : 0
34
+ duration.minutes = parseInt(pieces[1]) ? parseInt(pieces[1]) : 0
35
+ return duration
36
+ }
24
37
 
25
38
  function parseDate(text) {
26
39
  const match = commonDateFormats.map((format) => {
27
40
  return isMatch(text, format)
28
41
  })
29
42
  if (match.indexOf(true) > -1) {
30
- return zonedTimeToUtc(
43
+ const date = zonedTimeToUtc(
31
44
  parse(text, commonDateFormats[match.indexOf(true)], new Date()),
32
45
  loc
33
46
  ).toJSON()
47
+ return date.split('T')[0]
34
48
  } else {
35
49
  return null
36
50
  }
@@ -92,10 +106,12 @@ export default async function parseMD(body) {
92
106
  const current = tokens.children[idx]
93
107
  const hasNext = idx + 1 < tokens.children.length
94
108
 
95
- const obj = {}
96
109
  if (current.type === 'heading') {
97
- obj.id = slugify(current.children[0].value)
98
- obj.title = current.children[0].value
110
+ // issue-form answers start with a h3 heading, ignore everything else
111
+ const obj = {
112
+ id: slugify(current.children[0].value),
113
+ title: current.children[0].value
114
+ }
99
115
  if (hasNext) {
100
116
  const next = tokens.children[idx + 1]
101
117
  if (next.type === 'list') {
@@ -113,9 +129,12 @@ export default async function parseMD(body) {
113
129
  if (time) {
114
130
  obj.time = time
115
131
  }
132
+ if (obj.id === 'duration') {
133
+ obj.duration = parseDuration(obj.text)
134
+ }
116
135
  }
136
+ r.push(obj)
117
137
  }
118
- r.push(obj)
119
138
  }
120
139
 
121
140
  return r
@@ -23,10 +23,15 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
23
23
  id: 'date',
24
24
  title: 'Date',
25
25
  text: '11.03.2022\n',
26
- date: '2022-03-11T00:00:00.000Z'
26
+ date: '2022-03-11'
27
27
  },
28
28
  { id: 'time', title: 'Time', text: '16:00\n', time: '16:00' },
29
- { id: 'duration', title: 'Duration', text: '2h\n' },
29
+ {
30
+ id: 'duration',
31
+ title: 'Duration',
32
+ text: '2h\n',
33
+ duration: { hours: 2, minutes: 0 }
34
+ },
30
35
  {
31
36
  id: 'list-item-checked',
32
37
  title: 'List Item Checked',
@@ -90,3 +95,15 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
90
95
  // console.log(JSON.stringify(actual, null, 0))
91
96
  t.deepEqual(actual, expected)
92
97
  })
98
+
99
+ test('parse(md) return nothing', async (t) => {
100
+ const expected = []
101
+
102
+ const md = await readFile(
103
+ join(process.cwd(), 'test', 'test-issue-2.md'),
104
+ 'utf8'
105
+ )
106
+ const actual = await fn(md)
107
+ // console.log(JSON.stringify(actual, null, 0))
108
+ t.deepEqual(actual, expected)
109
+ })
@@ -0,0 +1,10 @@
1
+ ---
2
+ startDate: 10.03.2022
3
+ startTime: 10.00
4
+ duration: 1h
5
+ location: online
6
+ ---
7
+
8
+ Let's chat about tech, coding and Cyprus.
9
+
10
+ https://discord.gg/qA7wHjbs?event=948887583507755048