validate.mjs 864 B

12345678910111213141516171819202122
  1. import { inBrowser } from "./basic.mjs";
  2. const isDef = (val) => val !== void 0 && val !== null;
  3. const isFunction = (val) => typeof val === "function";
  4. const isObject = (val) => val !== null && typeof val === "object";
  5. const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
  6. const isDate = (val) => Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
  7. function isMobile(value) {
  8. value = value.replace(/[^-|\d]/g, "");
  9. return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value);
  10. }
  11. const isNumeric = (val) => typeof val === "number" || /^\d+(\.\d+)?$/.test(val);
  12. const isIOS = () => inBrowser ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;
  13. export {
  14. isDate,
  15. isDef,
  16. isFunction,
  17. isIOS,
  18. isMobile,
  19. isNumeric,
  20. isObject,
  21. isPromise
  22. };