forked from soy0ka/dimibob-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (43 loc) · 1.57 KB
/
index.js
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
46
47
48
49
const parser = require('@dimigo/excel')
const template = require('./result')
const exceptions = ['2종과일', '2종시리얼']
const day = ['mon', 'tue', 'wed', 'thr', 'fri', 'sat', 'sun']
const type = (index) =>
index < 22
? 'breakfast'
: index < 33 ? 'lunch' : 'dinner'
function BufferCheck (pathOrBuffer) {
return parser[pathOrBuffer instanceof Buffer ? 'parseXlsx' : 'parseXlsxFile'](pathOrBuffer)
}
async function parse (pathOrBuffer) {
const excel = await BufferCheck(pathOrBuffer)
const sheet = excel.get('sheet1')
const result = Object.assign({}, template)
const datas = sheet.toArray()
const year = datas[2][0].replace('년','')
const dates = []
for(const date of datas[3].slice(1)){
if (!date) continue
const temp = year + '-' + date.replace('월','-').replace('일','')
dates.push(temp)
}
for (const index in datas) {
if (index < +4 || index > 40) continue
if (index < 22 && index > 14) continue
if (index < 33 && index > 29) continue
const dayDatas = datas[index]
for (const date in dayDatas) {
const dayData = dayDatas[date]
if (!dayData) continue
if (/\*$|조 식|중 식|석 식|<국없는날>/g.test(dayData)) continue
const dayParsed =
!exceptions.find((v) => dayData.includes(v))
? dayData.replace(/\d+|\(|\)|\.|ㆍ/g, '')
: dayData
result[day[date - 1]][type(index)].push(dayParsed)
result[day[date - 1]]['date'] = (dates[date - 1])
}
}
return result
}
module.exports = { parse }