정규표현식으로 콤마 제거




/* array comma 제거 */

function util_uncomma(str) {

    str = String(str);

    return str.replace(/[^\d]+/g, '');

}


정규표현식으로 공백 제거




/* 공백 제거 */

function util_trim(str) {

return ifnull(str).replace(/\s/g,"");

}

문장내에 HASH TAG, AT을 a tag로 변환




/* 문장안에 hashtag, at을 a tag 로 변환 */

function util_convert_to_hash_tag(str) {

var inputString = str;

inputString = inputString.replace(/#[^#\s]+|@[^@\s]+/gm, function (tag){

return (tag.indexOf('#')== 0) ? '<a href="' + context + '/search/tags/?keyword=' + encodeURIComponent(tag.replace('#','')) + '">' + tag + '</a>' : '<a href="' + context + '/' + tag.replace('@','') + '">' + tag + '</a>';

});

return inputString;

}


정규표현식으로 코딩해본것임

주소창 URL 바꾸기


/* change URL */


function util_change_url (title, change_url) {

// pushState() 메서드는 state object, title URL 변수를 가진다. -https://developer.mozilla.org/ko/docs/Web/API/History_API

    if (typeof (history.pushState) != "undefined") {

        var obj = { Title: "", ChangeUrl: change_url };

        history.pushState(obj, obj.Title, obj.ChangeUrl);

    } else {

        //alert("Browser does not support HTML5.");

    }

}

UNIX TIME 으로 날짜 상태 표현




/* 유닉스 타임 날짜 계산 */


function util_convert_to_millis(time){

// ex) time value = 1481521584.676

var currentTime = new Date().getTime()/1000;

var inputTime = time;

var diffTime = currentTime - inputTime;

var postTime;

switch(true) {

case diffTime < 60: 

postTime = '방금'; 

break;

case diffTime < 3600: 

postTime = parseInt(diffTime/60) +'분 전'; 

break;

case diffTime < 86400: 

postTime = parseInt(diffTime/3600) + '시간 전'; 

break;

case diffTime < 604800: 

postTime = parseInt(diffTime/86400) + '일 전'; 

break;

case diffTime > 604800:

var date = new Date(time*1000);

postTime = date.getFullYear() + "/" + date.getMonth() + "/" + date.getDate(); 

break;

}

return postTime;

}



+ Recent posts