-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.js
152 lines (111 loc) · 3.82 KB
/
utils.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const moment = require('moment');
const textMiner = require('text-miner');
const formatDate = (date) => {
let formattedDate
// date = "Present", "2018", "Dec 2018"
if (date === 'Present') {
formattedDate = moment().format()
} else {
formattedDate = moment(date, 'MMMY').format()
}
return formattedDate
}
const getDurationInDays = (formattedStartDate, formattedEndDate) => {
if (!formattedStartDate || !formattedEndDate) return null
// +1 to include the start date
return moment(formattedEndDate).diff(moment(formattedStartDate), 'days') + 1
}
const getLocationFromText = async (text) => {
// Text is something like: Amsterdam Area, Netherlands
if (!text) return null
const cleanText = text.replace(' Area', '')
const city = (cleanText) ? cleanText.split(', ')[0] : null
const country = (cleanText) ? cleanText.split(', ')[1] : null
return {
city,
country
}
}
const getCleanText = async (text) => {
const regexRemoveMultipleSpaces = / +/g
const regexRemoveLineBreaks = /(\r\n\t|\n|\r\t)/gm
if (!text) return null
const cleanText = text
.replace(regexRemoveLineBreaks, '')
.replace(regexRemoveMultipleSpaces, ' ')
.replace('...', '')
.replace('See more', '')
.replace('See less', '')
.trim()
return cleanText
}
const isPeriod = (type, text) => {
if (type === 'experience') {
const words = ['mês', 'ano', 'anos', 'meses', 'anos', 'momento'];
const excludeWords = ['Temporário'];
return words.filter(word => text.indexOf(word) !== -1 && !excludeWords.includes(word)).length !== 0;
}else if (type === 'education'){
const words = ['-'];
return words.filter(word => text.indexOf(word) !== -1).length !== 0;
}
return false;
}
const returnDetailsByExperience = (type, array) => {
if (type === 'experience') {
if (array.length === 1) {
const [item] = array;
return isPeriod(type, item) ? { company: '', ...getDates(type, item), location: '' } : { company: item, ...getDates(type, ''), location: '' };
} else if (array.length === 2) {
const [first, second] = array;
if (isPeriod(type ,first)) {
return {company: '', ...getDates(type, first), location: second }
} else if (isPeriod(type, second)) {
return { company: first, ...getDates(type, second), location: '' }
} else {
return { company: first, ...getDates(type, ''), location: second }
}
} else if (array.length === 3) {
const [first, second, third] = array;
return { company: first, ...getDates(type, second), location: third }
}
}else if (type === 'education') {
if (array.length === 1) {
const [item] = array;
return isPeriod(type, item) ? { degreeName: '', ...getDates(type, item)} : { degreeName: item, ...getDates(type, '')};
} else {
const [first, second] = array;
return { degreeName: first, ...getDates(type, second)}
}
}
return null;
}
const getDates = (type, period) => {
if(type === 'experience'){
if(!period || period.length === 0){
return { startDate: '', endDate: '', endDateIsPresent: false }
}
const [startDate, end] = period.split('-');
const [ endDate, duration] = end.split('·');
return { startDate, endDate, endDateIsPresent: end && end.includes('momento') }
}else if(type === 'education'){
if(!period || period.length === 0){
return { startDate: '', endDate: '', }
}
const [startDate, end] = period.split('-');
const [ endDate, duration] = end.split('·');
return { startDate, endDate }
}
}
const academicExperienceIsValid = (experience)=>{
const { startDate, endDate, ...remainingData } = experience;
return false;
}
module.exports = {
formatDate,
getDurationInDays,
getCleanText,
getLocationFromText,
isPeriod,
returnDetailsByExperience,
academicExperienceIsValid
}