UNPKG

rh-regexp

Version:

```shell npm install rh-regexp ```

2 lines (1 loc) 4.92 kB
"use strict";function e(e,t){const{min:r=4,max:n=15}=t;return e.length>=r&&e.length<n}Object.defineProperty(exports,"__esModule",{value:!0});var t=Object.freeze({__proto__:null,_length_:e,charCount:function(e,t){const{min:r=4,max:n=15,reg:o=/\*/}=t;let u=e.length,s=0;for(;u--;)if(new RegExp(o).test(e))s++;else if(s>=n)return!1;return s>=r},typeCount:function(e,t){const{regs:r=[/[a-z]/,/[A-Z]/,/[0-9]/,/[_]/],min:n=3,max:o=15}=t;let u=r.length,s=0;for(;u--;)if(new RegExp(r[u]).test(e))s++;else if(s>=o)return!1;return s>=n},phone:function(e){return/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(e)},seKeyboard:function(e,t){const{max:r=4}=t,n=[["1!","2@","3#","4$","5%","6^","7&","8*","9(","0)","-_","=+"],["q","w","e","r","t","y","u","i","o","p","{[","]}","\\|"],["a","s","d","f","g","h","j","k","l",";:","'\""],["z","x","c","v","b","n","m",",<",".>","/?"]];function o(e){let t=4,r=-2;for(;t--;)for(r=n[t].length;r--;){const o=n[t][r].toLowerCase(),u=o.length||0;if(e==o[0]||u>1&&e==o[1])return[r,t]}return[-2,-2]}let u=1,s=-2,c=-2,i=0,f=e.length;if(f<r)return!0;for(;f--;){const t=o(e[f]),n=t[0],p=t[1],m=(a=c,g=n,h=p,(l=s)<0||a<0||g<0||h<0||l==g&&a==h?0:l==g&&a==h+1?1:l+1==g&&a==h?2:l==g&&a+1==h?3:l==g+1&&a==h?4:0);if(0!=i||s==n&&c==p||(i=m),s<0||c<0||0==i||m!=i||s==n&&c==p)u=1,i=0,s=n,c=p;else if(i==m&&0!=m&&(u++,s=n,c=p),u>=r)return!1}var l,a,g,h;return!0},number:function(e){return 0!==e.length&&/^[0-9]*$/.test(e)},seNumber:function(e,t){const{min:r=0,max:n=4}=t;let o=e.length,u=0;for(;o--;)if(new RegExp(/[0-9]/).test(e[o])?u++:u=0,u>=n||u<r)return!1;return!0},seOrderNumber:function(e,t){const{min:r=0,max:n=4}=t;let o=e.length,u=0,s="-2",c=0;for(;o--;){const t=e[o],i=Number(t);if(isNaN(i))u=0,s="-2",c=0;else if(Number(s)-1===i&&1===c&&u++,Number(s)-1===i&&1!==c&&(c=1,u=2),Number(s)+1===i&&2===c&&u++,Number(s)+1===i&&2!==c&&(c=2,u=2),0===u&&u++,s=t,u>=n||u<r)return!1}return!0},numbersAsc:function(e,t){const{min:r=-1,max:n=4}=t;let o=e.length,u=0,s="-2";for(;o--;){const t=e[o],c=Number(t);if(isNaN(c))u=0,s="-2";else if(Number(s)-1!==c?u=1:u++,s=t,u>=n||u<r)return!1}return!0},numbersDesc:function(e,t){const{min:r=-1,max:n=4}=t;let o=e.length,u=0,s="-2";for(;o--;){const t=e[o],c=Number(t);if(isNaN(c))u=0,s="-2";else if(Number(s)+1!==c?u=1:u++,s=t,u>=n||u<r)return!1}return!0},lowLetter:function(e){return 0!==e.length&&/[a-z]/.test(e)},uppLetter:function(e){return 0!==e.length&&/[A-Z]/.test(e)},letterBegin:function(e){return new RegExp(/^[a-zA-Z]/).test(e)},letterEnd:function(e){return new RegExp(/[a-zA-Z]$/).test(e)},letter:function(e,t){const{max:r=4}=t;let n=0,o=e.length;for(;o--;)if(new RegExp(/[a-zA-Z]/).test(e[o])?n++:n=0,n>=r)return!1;return!0},seLetter:function(e,t){const{max:r=4}=t;let n=0,o=-1e3,u=0,s=e.length;for(;s--;){const t=e[s],c=t.charCodeAt(0);if(c<65||c>122||c<97&&c>90)n=0,o=t.charCodeAt(0);else if((o-1===c&&1===u||o+1===c&&2===u)&&n++,o+1===c&&2!==u&&(u=2,n=2),o-1===c&&1!==u&&(u=1,n=2),o=t.charCodeAt(0),n>=r)return!1}return!0},seLetterAsc:function(e,t){const{max:r=4}=t;let n=0,o="z",u=e.length;for(;u--;){const t=e[u],s=t.charCodeAt(0);if(s<65||s>122||s<97&&s>90)n=0,o="z";else if(o.charCodeAt(0)-1!==s?n=1:n++,o=t,n>=r)return!1}return!0},seLetterDesc:function(e,t){const{max:r=4}=t;let n=0,o="z",u=e.length;for(;u--;){const t=e[u],s=t.charCodeAt(0);if(s<65||s>122||s<97&&s>90)n=0,o="z";else if(o.charCodeAt(0)+1!==s?n=1:n++,o=t,n>=r)return!1}return!0},seLetterIgCase:function(e,t){const{max:r=4}=t;let n=0,o=-1e3,u=0,s=e.length;for(;s--;){const t=e[s],c=t.toUpperCase().charCodeAt(0);if(c<65||c>122||c<97&&c>90)n=0,o=t.toUpperCase().charCodeAt(0);else if((o-1===c&&1===u||o+1===c&&2===u)&&n++,o+1===c&&2!==u&&(u=2,n=2),o-1===c&&1!==u&&(u=1,n=2),o=t.toUpperCase().charCodeAt(0),n>=r)return!1}return!0},seLetterIgCaseAsc:function(e,t){const{max:r=4}=t;let n=0,o="Z",u=e.length;for(;u--;){const t=e[u],s=t.toUpperCase().charCodeAt(0);if(s<65||s>90)n=0,o="Z";else if(o.toUpperCase().charCodeAt(0)-1!==s?n=1:n++,o=t,n>=r)return!1}return!0},seLetterIgCaseDesc:function(e,t){const{max:r=4}=t;let n=0,o="Z";const u=e.split("")||[];let s=u.length;for(;s--;){const e=u[s],t=e.toUpperCase().charCodeAt(0);if(t<65||t>90)n=0,o="Z";else if(o.toUpperCase().charCodeAt(0)+1!==t?n=1:n++,o=e,n>=r)return!1}return!0},required:function(e){return e.length>0}});function r(r,n,o){const u=o;let s={min:void 0,max:void 0,reg:n};return"string"==typeof u?(Object.keys(t).includes(u)||"length"===u)&&(s.type=u):s={...s,...u},!(s.type&&"length"===s.type&&!e(r,s))&&(!(s.type&&t[s.type]&&!t[s.type](r,s))&&!(!s.type&&s.reg&&!new RegExp(s.reg).test(r)))}exports.RegExpCount=function(e,t=!1,n=/[0-9a-zA-Z_]/){return function(o){let u=1;const s=[];for(Array.isArray(e)?u=e.length:e=[e];u--;)r(o,n,e[u])===t&&s.push(e[u]);return s}},exports.RegExps=function(e,t=/[0-9a-zA-Z_]/){return function(n){let o=1;if(!Array.isArray(e))return r(n,t,e);for(o=e.length;o--;)if(!r(n,t,e[o]))return!1;return!0}};