-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeDepositAutomaticallyRenewed.ts
45 lines (41 loc) · 1.08 KB
/
timeDepositAutomaticallyRenewed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as z from 'zod'
import { extract } from './extract'
import { Parser } from './parser'
/**
* 定期預金自動継続のご案内
*/
const timeDepositAutomaticallyRenewedSchema = z.object({
type: z.literal('timeDepositAutomaticallyRenewed'),
/**
* 定期契約番号
*/
number: z.string(),
/**
* 継続日
*/
renewalDate: z.string(),
})
export type TimeDepositAutomaticallyRenewed = z.infer<
typeof timeDepositAutomaticallyRenewedSchema
>
export const timeDepositAutomaticallyRenewedParser: Parser<TimeDepositAutomaticallyRenewed> = ({
subject,
text,
}) => {
if (subject !== '定期預金自動継続のご案内') {
return
}
const number = extract(text, /定期契約番号: (?<number>\d+)/)
.map(_ => _.number)
.pop()
const renewalDate = extract(
text,
/継続日: (?<year>\d{4})\/(?<month>\d{2})\/(?<day>\d{2})/,
)
.map(_ => `${_.year}-${_.month}-${_.day}`)
.pop()
if (typeof number === 'string' && typeof renewalDate === 'string') {
return { type: 'timeDepositAutomaticallyRenewed', number, renewalDate }
}
return
}