/** * Converts any value to string. * * @param {*} value * @returns {String} */ export function stringify(value) { let result; switch (typeof value) { case 'string': case 'number': result = `${value}`; break; case 'object': result = value === null ? '' : value.toString(); break; case 'undefined': result = ''; break; default: result = value.toString(); break; } return result; } /** * Checks if given variable is defined. * * @param {*} variable Variable to check. * @returns {Boolean} */ export function isDefined(variable) { return typeof variable !== 'undefined'; } /** * Checks if given variable is undefined. * * @param {*} variable Variable to check. * @returns {Boolean} */ export function isUndefined(variable) { return typeof variable === 'undefined'; } /** * Check if given variable is null, empty string or undefined. * * @param {*} variable Variable to check. * @returns {Boolean} */ export function isEmpty(variable) { return variable === null || variable === '' || isUndefined(variable); } /** * Check if given variable is a regular expression. * * @param {*} variable Variable to check. * @returns {Boolean} */ export function isRegExp(variable) { return Object.prototype.toString.call(variable) === '[object RegExp]'; }