validator.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isFunction = isFunction;
  6. exports.isPlainObject = isPlainObject;
  7. exports.isPromise = isPromise;
  8. exports.isDef = isDef;
  9. exports.isObj = isObj;
  10. exports.isNumber = isNumber;
  11. exports.isBoolean = isBoolean;
  12. exports.isImageUrl = isImageUrl;
  13. exports.isVideoUrl = isVideoUrl;
  14. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15. function isFunction(val) {
  16. return typeof val === "function";
  17. }
  18. function isPlainObject(val) {
  19. return val !== null && _typeof(val) === "object" && !Array.isArray(val);
  20. }
  21. function isPromise(val) {
  22. return isPlainObject(val) && isFunction(val.then) && isFunction(val["catch"]);
  23. }
  24. function isDef(value) {
  25. return value !== undefined && value !== null;
  26. }
  27. function isObj(x) {
  28. var type = _typeof(x);
  29. return x !== null && (type === "object" || type === "function");
  30. }
  31. function isNumber(value) {
  32. return /^\d+(\.\d+)?$/.test(value);
  33. }
  34. function isBoolean(value) {
  35. return typeof value === "boolean";
  36. }
  37. var IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
  38. var VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i;
  39. function isImageUrl(url) {
  40. return IMAGE_REGEXP.test(url);
  41. }
  42. function isVideoUrl(url) {
  43. return VIDEO_REGEXP.test(url);
  44. }