validator.js 1.4 KB

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