types.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * @Author: daidai
  3. * @Date: 2021-12-14 09:15:11
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-04-25 10:11:04
  6. * @FilePath: \web-pc\src\lib\types.js
  7. */
  8. export function hasOwn(obj, key) {
  9. return hasOwnProperty.call(obj, key);
  10. };
  11. export function isVNode(node) {
  12. return node !== null && typeof node === 'object' && hasOwn(node, 'componentOptions');
  13. };
  14. // 是否字符串
  15. export function isString2(str) {
  16. return (typeof str == 'string') && str.constructor == String;
  17. }
  18. export function isString(obj) {
  19. return Object.prototype.toString.call(obj) === '[object String]';
  20. }
  21. export function isObject(obj) {
  22. return Object.prototype.toString.call(obj) === '[object Object]';
  23. }
  24. export function isNumber(obj) {
  25. return Object.prototype.toString.call(obj) === '[object Number]';
  26. }
  27. // 是否完整的
  28. export function isDef(val) {
  29. return val !== undefined && val !== null;
  30. }
  31. //
  32. export function isKorean(text) {
  33. const reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi;
  34. return reg.test(text);
  35. }
  36. export function isHtmlElement(node) {
  37. return node && node.nodeType === Node.ELEMENT_NODE;
  38. }
  39. export const isUndefined = (val) => {
  40. return val === void 0;
  41. };