Last active
July 23, 2020 14:29
-
-
Save amorfati0310/b9238b6812d0aedd34b6535dee6d7146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} from hours | |
* @param {number} to hours | |
* 문의 가능한 시간을 출력해주는 함수 ex) 0시 ~ 12시 | |
*/ | |
const availableTime = (from, to) => { | |
const ANY_TIME = 25; | |
const ANY_TIME_POSSIBLE = '언제나 가능'; | |
const NOT_SELECTED_TIME = '미설정'; | |
if ([from, to].some(num => isNaN(num))) { | |
console.error('잘못된 data가 들어왔습니다', from, to); | |
return NOT_SELECTED_TIME; | |
} | |
// 25시가 있거나 시간대가 같은 경우 ANY_TIME_POSSIBLE 출력 | |
if (from === ANY_TIME || to === ANY_TIME) { | |
return ANY_TIME_POSSIBLE; | |
} | |
return `${from}시 ~ ${to}시`; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reduce [].reduce(reducer, initValue)) | |
// 범용성 있는 reduce 함수 | |
const reduce = (reducer, acc, iter) => { | |
if (!iter) { | |
iter = acc[Symbol.iterator](); | |
acc = iter.next().value; | |
} | |
for (const val of iter) { | |
acc = reducer(acc, val); | |
} | |
return acc; | |
}; | |
// go는 첫번쨰 인자 그리고 다음 쭈욱 실행할 함수리스트를 받아서 실행하는 함수입니다. | |
const go = (...args) => reduce((a1, f) => f(a1), args); | |
// pipe는 일련의 실행될 묶음 함수를 반환해주는 함수입니다. | |
const pipe = (f1, ...fs) => (...as) => go(f1(...as), ...fs); | |
export { | |
reduce, | |
go, | |
pipe, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { go, pipe } from './fpHelper.js'; | |
const urlRegex = /((http|ftp|https):\/\/)?[-a-zA-Z0-9@:%.가-힣_\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%;_\+.~#?&//=/.가-힣]*)/g; | |
const fileExtensionRegex = /^.*\.(jpg|JPG|gif|GIF|doc|DOC|pdf|PDF|html|svg|HTML|hwp|php|jsp|py|txt|doc|docx|xls|xlsx|js|css|xml|java)$/ | |
const isNullStringValue = val => typeof val !== 'string' || val === ''; | |
const revisionSpaceToHtmlString = htmlString => htmlString.replace(/ /g, ' '); | |
const hasHttp = str => str.match(/^[http|https]+:\/\//); | |
const revisionHasNotHttp = url => { | |
return hasHttp(url) ? url : `http://${url}`; | |
}; | |
const makeLinkTagExceptFilteExtension = str => { | |
return fileExtensionRegex.test(str) ? str : go(str, revisionHasNotHttp, makeLinkTag); | |
} | |
const makeLinkTag = url => `<a class="text-underline" | |
href="${url}" | |
target="_blank" | |
rel="noopener noreferrer"> | |
${url} | |
</a>`; | |
const replaceUrlToLinkTag = str => { | |
return str.replace(urlRegex, makeLinkTagExceptFilteExtension); | |
}; | |
const makeLinkTagToUrl = string => isNullStringValue(string) | |
? '' | |
: go(string, revisionSpaceToHtmlString, replaceUrlToLinkTag | |
); | |
export default makeLinkTagToUrl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment