Last active
December 13, 2019 06:38
-
-
Save lexuschert/9fe197ab91d534c88d277db05133f830 to your computer and use it in GitHub Desktop.
Js utils
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
function replaceEntities(str) { | |
return se('<textarea>' + ((str || '').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')) + '</textarea>').value; | |
} | |
function clean(str) { | |
return str ? (str+'').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') : ''; | |
} | |
function unclean(str) { | |
return replaceEntities((str+'').replace(/\t/g, "\n")); | |
} | |
function rand(mi, ma) { | |
return Math.random() * (ma - mi + 1) + mi; | |
} | |
function isUndefined(obj) { | |
return typeof obj === 'undefined' | |
}; | |
function isFunction(obj) { | |
return Object.prototype.toString.call(obj) === '[object Function]'; | |
} | |
function isString(obj) { | |
return typeof obj === 'string'; | |
} | |
function isArray(obj) { | |
return Object.prototype.toString.call(obj) === '[object Array]'; | |
} | |
function isObject(obj) { | |
return Object.prototype.toString.call(obj) === '[object Object]' && !(browser.msie8 && obj && obj.item !== 'undefined' && obj.namedItem !== 'undefined'); | |
} | |
function isEmpty(o) { | |
if(Object.prototype.toString.call(o) !== '[object Object]') {return false;} for(var i in o){ if(o.hasOwnProperty(i)){return false;} } return true; | |
} | |
function isNumeric(value) { | |
return !isNaN(value); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment