1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-10 02:16:40 +02:00
TableFilter/src/types.js

93 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-08 07:26:52 +02:00
import {root} from './root';
2014-11-16 01:29:07 +01:00
/**
* Types utilities
*/
2015-05-30 14:23:33 +02:00
const UNDEFINED = void 0;
2014-11-16 01:29:07 +01:00
2015-05-30 14:23:33 +02:00
export default {
/**
* Check if argument is an object or a global object
2015-05-30 14:23:33 +02:00
* @param {String or Object} v
* @return {Boolean}
*/
isObj(v) {
2015-05-30 14:23:33 +02:00
let isO = false;
if (typeof v === 'string') {
2016-05-08 07:26:52 +02:00
if (root[v] && typeof root[v] === 'object') {
2015-05-30 14:23:33 +02:00
isO = true;
}
} else {
if (v && typeof v === 'object') {
2015-05-30 14:23:33 +02:00
isO = true;
}
2014-11-16 01:29:07 +01:00
}
2015-05-30 14:23:33 +02:00
return isO;
},
2014-11-16 01:29:07 +01:00
2015-05-30 14:23:33 +02:00
/**
* Check if argument is a function
2015-05-30 14:23:33 +02:00
* @param {Function} fn
* @return {Boolean}
*/
isFn(fn) {
2015-05-30 14:23:33 +02:00
return (fn && fn.constructor == Function);
},
2014-11-16 01:29:07 +01:00
2015-05-30 14:23:33 +02:00
/**
* Check if argument is an array
2015-05-30 14:23:33 +02:00
* @param {Array} obj
* @return {Boolean}
*/
isArray(obj) {
2015-05-30 14:23:33 +02:00
return (obj && obj.constructor == Array);
},
2014-11-16 01:29:07 +01:00
/**
* Check argument is a string
* @param {String} val Value
* @returns {Boolean}
*/
isString(val) {
return Object.prototype.toString.call(val) === '[object String]';
},
/**
* Check argument is a number
* @param {Number} val
* @returns {Boolean}
*/
isNumber(val) {
return Object.prototype.toString.call(val) === '[object Number]';
},
2015-05-30 14:23:33 +02:00
/**
* Determine if argument is undefined
2015-05-30 14:23:33 +02:00
* @param {Any} o
* @return {Boolean}
*/
isUndef(o) {
2016-02-16 08:41:47 +01:00
return o === UNDEFINED;
},
2014-11-16 01:29:07 +01:00
/**
* Determine if argument is null
* @param {Any} o
* @return {Boolean}
*/
isNull(o) {
return o === null;
2015-06-14 04:44:02 +02:00
},
/**
* Determine if argument is empty (undefined, null or empty string)
* @param {Any} o
* @return {Boolean}
*/
isEmpty(o) {
return this.isUndef(o) || this.isNull(o) || o.length === 0;
}
2015-05-30 14:23:33 +02:00
};