Skip to content

Instantly share code, notes, and snippets.

View sonbyungjun's full-sized avatar
😃

byungjun son sonbyungjun

😃
View GitHub Profile
@sonbyungjun
sonbyungjun / viewKorean.ts
Created June 2, 2020 02:40
Typescript(Javascript) conversion of amount into Korean Function (타입스크립트(자바스크립트) 금액 한글로 변환 함수)
export const viewKorean = (num: any): string => {
num = parseInt((num + '').replace(/[^0-9]/g, ''), 10) + '';
if (num == '0') return '영';
let number = ['영', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'];
let unit = ['', '만', '억', '조'];
let smallUnit = ['천', '백', '십', ''];
let result = [];
let unitCnt = Math.ceil(num.length / 4);
num = num.padStart(unitCnt * 4, '0');
let regexp = /[\w\W]{4}/g;
@sonbyungjun
sonbyungjun / search.ts
Created June 2, 2020 02:37
Typescript(Javascript) Array Object Value Search Function (타입스크립트(자바스크립트) 배열 객체 값 검색 함수)
export function search(nameKey: any, myArray: any, attribute: string){
for (let i=0; i < myArray.length; i++) {
if (myArray[i][attribute] === nameKey) {
return myArray[i];
}
}
}
@sonbyungjun
sonbyungjun / emailSecurity.ts
Created June 2, 2020 02:33
Typescript(Javascript) Email Security Function (타입스크립트(자바스크립트) 이메일 블러처리 함수)
export function emailSecurity(userEmail: string){
const id = userEmail.split('@')[0];
const mail = userEmail.split('@')[1];
const maskingId = function(id: string) {
let splitId = id.substring(0,4);
for(let i = 4; i < id.length; i++) {
splitId += '*';
}
return splitId;
};
@sonbyungjun
sonbyungjun / duplicateCheck.ts
Created June 2, 2020 02:32
TypeScript(Javascript) duplicateCheck Function (타입스크립트(자바스크립) 중복체크 함수)
export function duplicateCheck(array: any[]) {
return array.reduce((t, a) => {
t[a] = (t[a] || 0) + 1;
return t
}, {})
}
@sonbyungjun
sonbyungjun / paginate.ts
Last active June 2, 2020 02:31
TypeScript(Javascript) Paginate Calculation Function (타입스크립트(자바스크립트) 페이지네이션 계산 함수)
export const paginate = (array: any, index: any, size: any) => {
// transform values
index = Math.abs(parseInt(index));
index = index > 0 ? index - 1 : index;
size = parseInt(size);
size = size < 1 ? 1 : size;
// filter
return [
...array.filter((value: any, n: any) => {
@sonbyungjun
sonbyungjun / detail.ts
Created April 3, 2020 09:29
로직 클래스화 예제 코드
class Detail {
private link;
constructor(link) {
this.link = link;
}
public async detail(id: any): Promise {
return new Promise(async resolve => {