Node.js
JavaScript를 서버에서도 사용할 수 있도록 만든 프로그램
Homework, Facade Pattern, Early return
Facade Pattern
최소한의 API만 공개
Early return
소거법을 사용하여 빠르게 return (if구문에 사용)
프로젝트에 대한 상세 설명이 담겨있는 파일
yarn init 을 하면 파일이 생성
-dependencies: 프로덕트 환경에서 응용 프로그램에 필요한 패키지
-devDependencies: 로컬 개발 및 테스트에만 필요한 패키지
{
"name": "01-05-token-count-api-facade-import",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module"
}
//주민번호 가운데가 ”-”로 구성
function checkHyphen(num) {
if (num.includes("-") === false) {
console.log("에러 발생!!! 형식이 올바르지 않습니다!!!");
return false;
} else {
return true;
}
}
//주민번호는 앞 6자리, 뒤 7자리로 구성 => num을 slice로 자르기
// 함수의 활용을 잘 모르겠다면, RunJs로 확인
function checkDigits(num) {
const frontDigits = num.substring(0, 6);
const lastDigits = num.slice(7);
if (
frontDigits.length > 6 ||
frontDigits.length < 6 ||
lastDigits.length > 7 ||
lastDigits.length < 7
) {
console.log("에러 발생!!! 개수를 제대로 입력해 주세요!!!"); //early exit pattern(early return) , 먼저 종료시켜 버리기
즉 소거법으로 먼저 진행 , 이 방법으로 가급적 진행하기
return false;
} else {
return true;
}
}
//뒤 7자리 중, 끝 6자리는 *로 변경
function checkLastDigits(num) {
//함수이름 바꾸기, 뒷자리 별만들어주기
const stars = num.substring(0, 8);
console.log(stars + "******");
}
function customRegistrationNumber(num) {
checkHyphen(num);
checkDigits(num);
checkLastDigits(num);
}
customRegistrationNumber("210510-1010101");
customRegistrationNumber("210510-1010101010101");
customRegistrationNumber("2105101010101");
New Terminal 명령어
- ls 리스트 보기
- cli : command line interface
- cd : change directory 폴더 안으로 들어가기
- pwd : print working directory 현재 위치
- node : 해당 파일 런
git으로 보내기
- git add .
- git commit -m "메세지 작성"
- git push origin master
console.log(String(Math.floor(Math.random() * 1000000).padStart(6,"0")))
🥥 꿀팁