weex-flymeui
Version:
A Flyme Style UI library based on Weex for Creator.
65 lines (61 loc) • 1.5 kB
JavaScript
/**
* Created by Tw93 on 2017/6/26.
*/
const Utils = {
/**
* 对象类型
* @memberOf Utils
* @param obj
* @returns {string}
* @private
*/
_typeof: function (obj) {
return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
},
/**
* 判断 obj 是否为 `object`
* @memberOf Utils
* @param obj
* @returns {boolean}
* @example
*
* const { Utils } = require('@ali/wxv-bridge');
* const { isPlainObject } = Utils;
* console.log(isPlainObject({})); // true
* console.log(isPlainObject('')); // false
*/
isPlainObject: function (obj) {
return Utils._typeof(obj) === 'object';
},
/**
* 判断 obj 是否为 `string`
* @memberOf Utils
* @param obj
* @returns {boolean}
* @example
*
* const { Utils } = require('@ali/wxv-bridge');
* const { isString } = Utils;
* console.log(isString({})); // false
* console.log(isString('')); // true
*/
isString: function (obj) {
return typeof (obj) === 'string';
},
/**
* 判断 obj 是否为 `非空数组`
* @memberOf Utils
* @param obj
* @returns {boolean}
* @example
*
* const { Utils } = require('@ali/wxv-bridge');
* const { isNonEmptyArray } = Utils;
* console.log(isNonEmptyArray([])); // false
* console.log(isNonEmptyArray([1,1,1,1])); // true
*/
isNonEmptyArray: function (obj) {
return obj && obj.length > 0 && Array.isArray(obj) && typeof obj !== 'undefined';
}
};
export default Utils;