Skip to content

Instantly share code, notes, and snippets.

@lexuschert
Last active December 13, 2019 06:38
Show Gist options
  • Save lexuschert/9fe197ab91d534c88d277db05133f830 to your computer and use it in GitHub Desktop.
Save lexuschert/9fe197ab91d534c88d277db05133f830 to your computer and use it in GitHub Desktop.
Js utils
function replaceEntities(str) {
return se('<textarea>' + ((str || '').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')) + '</textarea>').value;
}
function clean(str) {
return str ? (str+'').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;') : '';
}
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