Ver Fonte

正则类型检测兼容浏览器

kindring há 1 ano atrás
pai
commit
b2fa6a6942
2 ficheiros alterados com 5 adições e 4 exclusões
  1. 3 2
      lib/fieldCheck.js
  2. 2 2
      src/fieldCheck.js

+ 3 - 2
lib/fieldCheck.js

@@ -86,7 +86,7 @@ var FieldCheck = function () {
       try {
         for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
           var field = _step2.value;
-          if (typeof field !== 'string' && !(field instanceof RegExp)) {
+          if (typeof field !== 'string' && !this._isRegExp(field)) {
             throw new Error('checkFields item is not string or RegExp');
           }
         }
@@ -125,13 +125,14 @@ var FieldCheck = function () {
   }, {
     key: "getRuleItem",
     value: function getRuleItem(field) {
+      var _this = this;
       return _classPrivateFieldGet(this, _ruleItems).find(function (item) {
         var _iterator4 = _createForOfIteratorHelper(item.checkFields),
           _step4;
         try {
           for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
             var _matchKey = _step4.value;
-            if (_matchKey instanceof RegExp) {
+            if (_this._isRegExp(_matchKey)) {
               if (_matchKey.test(field)) {
                 return true;
               }

+ 2 - 2
src/fieldCheck.js

@@ -146,7 +146,7 @@ class FieldCheck{
         }
         //  检测checkFields中的每一项是否为字符串或者正则
         for(let field of checkFields){
-            if(typeof field !== 'string' && !(field instanceof RegExp)){
+            if(typeof field !== 'string' && !this._isRegExp(field)){
                 throw new Error('checkFields item is not string or RegExp');
             }
         }
@@ -192,7 +192,7 @@ class FieldCheck{
             // 判断是否为正则
             for (const _matchKey of item.checkFields) {
                 // 判断是否为正则
-                if (_matchKey instanceof RegExp) {
+                if (this._isRegExp(_matchKey)) {
                     // console.log(`使用正则进行匹配,${_matchKey.test(key)}`);
                     if (_matchKey.test(field)) {
                         // console.log(`通过正则匹配规则成功,${_matchKey.test(key)}`);