@zentered/issue-forms-body-parser 1.1.4 → 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 +16 -0
- package/package.json +1 -1
- package/src/parse.js +16 -0
- package/test/parse-issue.test.js +6 -1
package/dist/index.js
CHANGED
|
@@ -53187,6 +53187,7 @@ function formatInTimeZone(date, timeZone, formatStr, options) {
|
|
|
53187
53187
|
|
|
53188
53188
|
|
|
53189
53189
|
|
|
53190
|
+
|
|
53190
53191
|
// if the system time is not UTC, we need to convert it to UTC
|
|
53191
53192
|
|
|
53192
53193
|
const loc = 'UTC'
|
|
@@ -53203,6 +53204,18 @@ const commonDateFormats = [
|
|
|
53203
53204
|
|
|
53204
53205
|
const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
|
|
53205
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
|
+
}
|
|
53218
|
+
|
|
53206
53219
|
function parse_parseDate(text) {
|
|
53207
53220
|
const match = commonDateFormats.map((format) => {
|
|
53208
53221
|
return (0,date_fns.isMatch)(text, format)
|
|
@@ -53297,6 +53310,9 @@ async function parseMD(body) {
|
|
|
53297
53310
|
if (time) {
|
|
53298
53311
|
obj.time = time
|
|
53299
53312
|
}
|
|
53313
|
+
if (obj.id === 'duration') {
|
|
53314
|
+
obj.duration = parseDuration(obj.text)
|
|
53315
|
+
}
|
|
53300
53316
|
}
|
|
53301
53317
|
r.push(obj)
|
|
53302
53318
|
}
|
package/package.json
CHANGED
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'
|
|
@@ -22,6 +23,18 @@ const commonDateFormats = [
|
|
|
22
23
|
|
|
23
24
|
const commonTimeFormats = ['HH:mm', 'HH.mm', 'hh:mm a', 'hh:mm A']
|
|
24
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
|
+
}
|
|
37
|
+
|
|
25
38
|
function parseDate(text) {
|
|
26
39
|
const match = commonDateFormats.map((format) => {
|
|
27
40
|
return isMatch(text, format)
|
|
@@ -116,6 +129,9 @@ export default async function parseMD(body) {
|
|
|
116
129
|
if (time) {
|
|
117
130
|
obj.time = time
|
|
118
131
|
}
|
|
132
|
+
if (obj.id === 'duration') {
|
|
133
|
+
obj.duration = parseDuration(obj.text)
|
|
134
|
+
}
|
|
119
135
|
}
|
|
120
136
|
r.push(obj)
|
|
121
137
|
}
|
package/test/parse-issue.test.js
CHANGED
|
@@ -26,7 +26,12 @@ test('parse(md) should parse GitHub Issue Form data into useful, structured data
|
|
|
26
26
|
date: '2022-03-11'
|
|
27
27
|
},
|
|
28
28
|
{ id: 'time', title: 'Time', text: '16:00\n', time: '16:00' },
|
|
29
|
-
{
|
|
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',
|