| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * 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]';
- }
|