UNPKG

dtable-utils

Version:

dtable common utils

61 lines (52 loc) 1.79 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _typeof = require('@babel/runtime/helpers/typeof'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); /** * Generate a random string of specified length. * @param {number} keyLength * @returns random code, string */ var generatorBase64Code = function generatorBase64Code() { var keyLength = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4; var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789'; var key = ''; for (var i = 0; i < keyLength; i++) { key += possible.charAt(Math.floor(Math.random() * possible.length)); } return key; }; /** * Check whether the given value is empty * @param {any} val * @returns bool */ var isEmpty = function isEmpty(val) { if (val === null || val === undefined) return true; if (val.length !== undefined) return val.length === 0; if (val instanceof Date) return false; if (_typeof__default["default"](val) === 'object') return Object.keys(val).length === 0; return false; }; /** * Check whether the object is empty. * The true will be returned if the "obj" is invalid. * @param {object} obj * @returns bool */ var isEmptyObject = function isEmptyObject(obj) { var name; // eslint-disable-next-line for (name in obj) { return false; } return true; }; var hasOwnProperty = function hasOwnProperty(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); }; exports.generatorBase64Code = generatorBase64Code; exports.hasOwnProperty = hasOwnProperty; exports.isEmpty = isEmpty; exports.isEmptyObject = isEmptyObject;