validator.js 1008B

1234567891011121314151617181920212223242526272829303132
  1. // eslint-disable-next-line @typescript-eslint/ban-types
  2. export function isFunction(val) {
  3. return typeof val === 'function';
  4. }
  5. export function isPlainObject(val) {
  6. return val !== null && typeof val === 'object' && !Array.isArray(val);
  7. }
  8. export function isPromise(val) {
  9. return isPlainObject(val) && isFunction(val.then) && isFunction(val.catch);
  10. }
  11. export function isDef(value) {
  12. return value !== undefined && value !== null;
  13. }
  14. export function isObj(x) {
  15. const type = typeof x;
  16. return x !== null && (type === 'object' || type === 'function');
  17. }
  18. export function isNumber(value) {
  19. return /^\d+(\.\d+)?$/.test(value);
  20. }
  21. export function isBoolean(value) {
  22. return typeof value === 'boolean';
  23. }
  24. const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
  25. const VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i;
  26. export function isImageUrl(url) {
  27. return IMAGE_REGEXP.test(url);
  28. }
  29. export function isVideoUrl(url) {
  30. return VIDEO_REGEXP.test(url);
  31. }