@quantlab/handsontable
Version:
Spreadsheet-like data grid editor that provides copy/paste functionality compatible with Excel/Google Docs
80 lines (69 loc) • 1.87 kB
JavaScript
;
exports.__esModule = true;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.stringify = stringify;
exports.isDefined = isDefined;
exports.isUndefined = isUndefined;
exports.isEmpty = isEmpty;
exports.isRegExp = isRegExp;
/**
* Converts any value to string.
*
* @param {*} value
* @returns {String}
*/
function stringify(value) {
var result = void 0;
switch (typeof value === 'undefined' ? 'undefined' : _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}
*/
function isDefined(variable) {
return typeof variable !== 'undefined';
}
/**
* Checks if given variable is undefined.
*
* @param {*} variable Variable to check.
* @returns {Boolean}
*/
function isUndefined(variable) {
return typeof variable === 'undefined';
}
/**
* Check if given variable is null, empty string or undefined.
*
* @param {*} variable Variable to check.
* @returns {Boolean}
*/
function isEmpty(variable) {
return variable === null || variable === '' || isUndefined(variable);
}
/**
* Check if given variable is a regular expression.
*
* @param {*} variable Variable to check.
* @returns {Boolean}
*/
function isRegExp(variable) {
return Object.prototype.toString.call(variable) === '[object RegExp]';
}