validate.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. isDate: () => isDate,
  21. isDef: () => isDef,
  22. isFunction: () => isFunction,
  23. isIOS: () => isIOS,
  24. isMobile: () => isMobile,
  25. isNumeric: () => isNumeric,
  26. isObject: () => isObject,
  27. isPromise: () => isPromise
  28. });
  29. module.exports = __toCommonJS(stdin_exports);
  30. var import_basic = require("./basic");
  31. const isDef = (val) => val !== void 0 && val !== null;
  32. const isFunction = (val) => typeof val === "function";
  33. const isObject = (val) => val !== null && typeof val === "object";
  34. const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
  35. const isDate = (val) => Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
  36. function isMobile(value) {
  37. value = value.replace(/[^-|\d]/g, "");
  38. return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value);
  39. }
  40. const isNumeric = (val) => typeof val === "number" || /^\d+(\.\d+)?$/.test(val);
  41. const isIOS = () => import_basic.inBrowser ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;