validator.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // eslint-disable-next-line @typescript-eslint/ban-types
  5. function isFunction(val) {
  6. return typeof val === 'function';
  7. }
  8. exports.isFunction = isFunction;
  9. function isPlainObject(val) {
  10. return val !== null && typeof val === 'object' && !Array.isArray(val);
  11. }
  12. exports.isPlainObject = isPlainObject;
  13. function isPromise(val) {
  14. return isPlainObject(val) && isFunction(val.then) && isFunction(val.catch);
  15. }
  16. exports.isPromise = isPromise;
  17. function isDef(value) {
  18. return value !== undefined && value !== null;
  19. }
  20. exports.isDef = isDef;
  21. function isObj(x) {
  22. var type = typeof x;
  23. return x !== null && (type === 'object' || type === 'function');
  24. }
  25. exports.isObj = isObj;
  26. function isNumber(value) {
  27. return /^\d+(\.\d+)?$/.test(value);
  28. }
  29. exports.isNumber = isNumber;
  30. function isBoolean(value) {
  31. return typeof value === 'boolean';
  32. }
  33. exports.isBoolean = isBoolean;
  34. var IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
  35. var VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i;
  36. function isImageUrl(url) {
  37. return IMAGE_REGEXP.test(url);
  38. }
  39. exports.isImageUrl = isImageUrl;
  40. function isVideoUrl(url) {
  41. return VIDEO_REGEXP.test(url);
  42. }
  43. exports.isVideoUrl = isVideoUrl;