listoperate 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/index.js ADDED
@@ -0,0 +1 @@
1
+ import list from"./lib/list";import portlist from"./lib/portlist";import vlanlist from"./lib/vlanlist";const funcsObjs=[list,portlist,vlanlist];export default{install(o){funcsObjs.forEach(e=>{Object.keys(e).forEach(t=>o.prototype[t]=e[t])}),o.getInstance=(t,e)=>{var l=new(o.extend(t))({el:document.createElement("div")});let n;return(n=document.querySelector(e))?(n.appendChild(l.$el),l):(console.log("Selector '"+e+"' not found while instantiating component '"+t.name+"'!"),null)}}};
package/lib/list.js ADDED
@@ -0,0 +1 @@
1
+ let num_reg="-?\\d+",range_reg="("+num_reg+")(-("+num_reg+"))?",rangeReg=new RegExp("^"+range_reg+"$"),listReg=new RegExp("^("+range_reg+"(,"+range_reg+")*)?$");function listElementPosGet(e,t,r){r=r||num_reg;let l=new RegExp("^"+num_reg+"$");if(!l.test(e))return console.log("'"+e+"' is not a valid number!"),null;if(!t)return[Number(e)-1,Number(e)+1,Number(e)];let n=t.replace(/\s/g,"");if(!listReg.test(n))return console.log("The format of map '"+t+"' is incorrect!"),null;if(""===n)return console.log("The map '"+t+"' is empty!"),null;var i=n.split(","),s=Number(e);let u=!1,o=null,g=null;for(let e=0;e<i.length;e++){rangeReg.test(i[e]);var f=Number(RegExp.$1),a=""!==RegExp.$2?Number(RegExp.$3):f;if(u)return g=f,[o,g,s];if(f<=s&&s<=a){if(f<s&&(o=s-1),s<a?g=s+1:e<i.length-1&&(u=!0),!u)return[o,g,s]}else o=a}return console.log("'"+e+"' is not in valid range '"+n+"'!"),null}function listPosGet(e){return[Number(e)-1,Number(e)+1,Number(e)]}function listCompare(e,t){return e-t}function listAdd(t,e,r,l){if(t=t.replace(/\s/g,""),!listReg.test(t))return console.log("List '"+t+"' format error!"),"";l=l||num_reg;let n=new RegExp("^"+num_reg+"$");if(!n.test(e))return console.log("'"+e+"' is not a valid number!"),null;r=r||listPosGet;var i,s=Number(e);if(!(i=r(s)))return t;if(""===t)return s;let u=t.split(",");for(let e=0;e<u.length;e++){rangeReg.test(u[e]);var o=Number(RegExp.$1),g=""!==RegExp.$2?Number(RegExp.$3):o;if(!r(o))return"";if(o!==g&&!r(g))return"";if(o<=s&&s<=g)return t;if(s<o)return 0===e?o===i[1]?u[e]=s+"-"+g:u.unshift(s):a===i[0]&&o===i[1]?u.splice(e-1,2,f+"-"+g):a===i[0]?u[e-1]=f+"-"+s:o===i[1]?u[e]=s+"-"+g:u.splice(e,0,s),u.join(",");if(!(e<u.length-1))return g===i[0]?u[e]=o+"-"+s:u.push(s),u.join(",");var f=o,a=g}}function listOperate(e,t,r,l,o,g,n=!1){r=r||"",e=(e=e||"").toString().replace(/\s/g,""),r=r.toString().replace(/\s/g,"");var f=n?[]:"";if(""===e&&""===r)return f;var a,p,c,m="("+(l=l||num_reg)+")(-("+l+"))?";let i=new RegExp("^("+m+"(,"+m+")*)?$");if(!i.test(e))return console.log("List '"+e+"' format error!"),f;if(!i.test(r))return console.log("List '"+r+"' format error!"),f;if(o=o||listPosGet,g=g||listCompare,"∪"!==t&&"∩"!==t&&"-"!==t)return console.log("Operation parameter '"+t+"' is not supported!"),f;let h;if(""===e){if("∩"===t||"-"===t)return f;h=[r]}else if(""===r){if("∩"===t)return f;h=[e]}else switch(t){case"∪":h=[[e,r].join(",")];break;case"∩":case"-":h=[e,r]}let R=[],E,b,x,$;for(let u=0;u<h.length+(1<h.length&&("∩"===t||"-"===t)?1:0);u++){let i;$=u<h.length?(i="∪",h[u].split(",")):(i=t,x=E,b);let s=0;for(let r=0;r<$.length;r++){let l,n;if(u<h.length){let e=new RegExp("^"+m+"$");e.test($[r]),l=RegExp.$1,n=""!==RegExp.$2?RegExp.$3:l}else l=$[r][0],n=$[r][1];if(0<(a=g(l,n))&&(p=l,l=n,n=p),a=!a,!(c=o(l)))return f;let t=c;if(!a&&!(t=o(n)))return f;if(0===r&&u<h.length)x=[[l,n]];else{u<h.length&&(s=0);let r;for(let e=1;e<=(a?1:2);e++){var d=1===e?l:n,v=1===e?c:t;for(r=s;r<x.length;r++){var _=x[r][0],k=x[r][1],N=!g(_,k);if(u<h.length){if(!o(_))return f;if(!N&&!o(k))return f}var A,w,y=g(d,_),C=g(d,k);if(0<=y&&C<=0){if("∪"===i||"∩"===i)break;N?x.splice(r,1):y?(C?x.splice(r,1,[_,v[0]],[v[1],k]):x[r]=[_,v[0]],r++):x[r]=[v[1],k];break}if(y<0){if("∩"===i||"-"===i)break;C=!g(_,v[1]);0===r?C?x[r]=[d,k]:x.unshift([d,d]):(y=!g(w,v[0]))&&C?(x.splice(r-1,2,[A,k]),r--):y?(x[r-1]=[A,d],r--):C?x[r]=[d,k]:x.splice(r,0,[d,d]);break}if(!(r<x.length-1)){"∪"===i?g(k,v[0])?(x.push([d,d]),r++):x[r]=[_,d]:r++;break}"∪"===i&&(A=_,w=k)}if("∪"===i||"-"===i)2===e&&s<r&&("∪"===i?x.splice(s,r-s+1,[x[s][0],x[r][1]]):"-"===i&&x.splice(s,r-s));else if("∩"===i)if(1===e)r<x.length&&a&&0<=g(l,x[r][0])&&R.push([l,n]);else{let t=s;var D=t<x.length&&0<=g(l,x[t][0]);if(D&&t===r)R.push([l,n]);else{if(D&&(R.push([l,x[t][1]]),t++),t<r)for(let e=t;e<r;e++)R.push(x[e]);r<x.length&&0<=g(n,x[r][0])&&R.push([x[r][0],n])}}1!==e&&"∪"!==i&&"∩"!==i||(s=r)}}}u<h.length?u?b=x:E=x:"∩"===i&&(x=R)}$=[];let s=[];for(let r=0;r<x.length;r++)if(n){let e=o(x[r][0]),t=e[2];for(;;){if(s.push(t),0<=g(t,x[r][1])||null===(e=o(t)))break;t=e[1]}}else $.push(g(x[r][0],x[r][1])?x[r][0]+"-"+x[r][1]:x[r][0]);return n?s:$.join(",")}function listUnion(e,t=""){return listOperate(e,"∪",t)}function listDiff(e,t=""){return listOperate(e,"-",t)}function listInt(e,t=""){return listOperate(e,"∩",t)}function listToArray(e){return listOperate(e,"∪","",null,null,null,!0)}function listFromArray(t,r){if(!Array.isArray(t))return console.log("'"+t+"' is not an array"),"";r=r||listUnion;let l="";for(let e=0;e<t.length;e++)l=r(l,t[e]);return l}function listAddDelCalc(e,t,r,l,n,i,s,u,o){switch(s=s||listUnion,u=u||listDiff,o=o||listInt,e){case"=":l=u(i=s(t),r),n=u(r,i);break;case"+":l=u(t,r),n=o(u(n,t),r),i=u(s(r,l),n);break;case"-":n=o(t,r),l=u(u(l,t),r),i=u(s(r,l),n)}return{add:l,del:n,new:i}}function listElementCheck(t,e,r,l){l=l||num_reg;let n=new RegExp("^"+num_reg+"$");if(!n.test(t))return"'"+t+"' is not a valid number!";let i=r.replace(/\s/g,"");if(!listReg.test(i))return"The format of "+e+" map '"+r+"' is incorrect!";i;var s=i.split(",");for(let e=0;e<s.length;e++){rangeReg.test(s[e]);var u=Number(RegExp.$1),o=""!==RegExp.$2?Number(RegExp.$3):u;if(u<=t&&t<=o)return null}return"'"+t+"' is not in valid "+e+" range '"+r+"'!"}function listCheck(e,t,l,r){let n=e.replace(/\s/g,"");var i="("+(r=r||num_reg)+")(-("+r+"))?";let s=new RegExp("^("+i+"(,"+i+")*)?$");if(t&&(t+=" "),!s.test(n))return"The format of "+t+"list '"+e+"' is incorrect!";if(""===n)return null;if(l){var u=n.split(",");for(let r=0;r<u.length;r++){let e=new RegExp("^"+i+"$");e.test(u[r]);var o=RegExp.$1,g=""!==RegExp.$2?RegExp.$3:o;let t;if(t=l(o))return t;if(o!==g&&(t=l(g)))return t}}return null}export default{listAdd:listUnion,listDel:listDiff,listFilter:listInt,listFromArray:listFromArray,listToArray:listToArray,listAddDelCalc:listAddDelCalc,listCheck:listCheck};export{listElementPosGet,listOperate,listElementCheck};
@@ -0,0 +1 @@
1
+ import list,{listOperate}from"./list";var listCheck=list.listCheck,listFromArray=list.listFromArray,listAddDelCalc=list.listAddDelCalc;let portMap=[],slotPortRange_reg="(\\d{1,2})(-(\\d{1,2}))?",slotPortRangeReg=new RegExp("^"+slotPortRange_reg+"$"),portMapReg=new RegExp("^([A-Za-z]"+slotPortRange_reg+"(,"+slotPortRange_reg+")*)?$"),port_reg="[A-Za-z]\\d{1,2}\\/\\d{1,2}",portRange_reg="("+port_reg+")(-("+port_reg+"))?",portReg=new RegExp("^"+port_reg+"$"),portRangeReg=new RegExp("^"+portRange_reg+"$"),portlistReg=new RegExp("^("+portRange_reg+"(,"+portRange_reg+")*)?$");function setPortMap(t){portMap=t}function portAll(){if(!Array.isArray(portMap)||0===portMap.length)return console.log("Invalid port map!"),"";let e=null,o=null;for(let r=0;r<portMap.length;r++){let t=portMap[r].replace(/\s/g,"");if(!portMapReg.test(t))return console.log("The port range format "+portMap[r]+" in slot "+r+" is incorrect!"),"";var l;""!==t&&(null===e&&(slotPortRangeReg.test(t.slice(1).split(",")[0]),e=t[0]+r+"/"+RegExp.$1),l=t.slice(1).split(","),slotPortRangeReg.test(l[l.length-1]),o=t[0]+r+"/"+(""===RegExp.$2?RegExp.$1:RegExp.$3))}return e===o?e:e+"-"+o}function portlistPosGet(o){if(o=o.replace(/\s/g,""),!portReg.test(o))return console.log("Port '"+o+"' format error!"),null;if(!Array.isArray(portMap)||0===portMap.length)return console.log("Invalid port map!"),null;let t=o.split("/");var l=Number(t[0].slice(1)),p=Number(t[1]);if(l<0||l>portMap.length-1)return console.log("The slot '"+l+"' where the port '"+o+"' is located does not exist!"),null;let i=portMap[l].replace(/\s/g,"");if(!portMapReg.test(i))return console.log("The port range format '"+portMap[l]+"' of the slot '"+l+"' where the port '"+o+"' is located is incorrect!"),null;if(""===i)return null;if(i[0]!==o[0])return console.log("The type of port '"+o+"' should be '"+i[0]+"'!"),null;let s=!1,n=null,a=null;for(let e=0;e<portMap.length;e++){let r=portMap[e].replace(/\s/g,"");if(!portMapReg.test(r))return console.log("The port range format "+portMap[e]+" in slot "+e+" is incorrect!"),null;if(""!==r){var g=r.slice(1).split(",");for(let t=0;t<g.length;t++){slotPortRangeReg.test(g[t]);var u=Number(RegExp.$1),f=""!==RegExp.$2?Number(RegExp.$3):u;if(s)return a=r[0]+e+"/"+u,[n,a,o];if(e===l&&u<=p&&p<=f){if(u<p&&(n=i[0]+l+"/"+(p-1)),p<f?a=i[0]+l+"/"+(p+1):(e<portMap.length-1||t<g.length-1)&&(s=!0),!s)return[n,a,o]}else n=r[0]+e+"/"+f}}}return console.log("Port '"+o+"' is not in valid range '"+i[0]+l+"/"+i.slice(1)+"'!"),null}function portlistCompare(t,r){let e,o,l,p,i;return e=t.split("/"),o=Number(e[0].slice(1)),p=Number(e[1]),e=r.split("/"),l=Number(e[0].slice(1)),i=Number(e[1]),o!==l?o-l:p-i}function portlistAdd(i,s){if(i=i.replace(/\s/g,""),!portlistReg.test(i))return console.log("Port list '"+i+"' format error!"),"";var n;if(!(n=portlistPosGet(s=s.replace(/\s/g,""))))return i;if(""===i)return s;let t=s.split("/");var a=Number(t[0].slice(1)),g=Number(t[1]);let u=i.split(",");for(let p=0;p<u.length;p++){portRangeReg.test(u[p]);let t=RegExp.$1,r=""!==RegExp.$2?RegExp.$3:t;if(!portlistPosGet(t))return"";let e=t.split("/");var f=Number(e[0].slice(1)),c=Number(e[1]);let o=f,l=c;if(t!==r){if(!portlistPosGet(r))return"";let t=r.split("/");o=Number(t[0].slice(1)),l=Number(t[1])}if((f<a||a===f&&c<=g)&&(a<o||a===o&&g<=l))return i;if(a<f||a===f&&g<c)return 0===p?t===n[1]?u[p]=s+"-"+r:u.unshift(s):h===n[0]&&t===n[1]?u.splice(p-1,2,R+"-"+r):h===n[0]?u[p-1]=R+"-"+s:t===n[1]?u[p]=s+"-"+r:u.splice(p,0,s),u.join(",");if(!(p<u.length-1))return r===n[0]?u[p]=t+"-"+s:u.push(s),u.join(",");var R=t,h=r}}function portlistMerge(t,r=""){if(t=t.replace(/\s/g,""),r=r.replace(/\s/g,""),!portlistReg.test(t))return console.log("Port list '"+t+"' format error!"),"";if(!portlistReg.test(r))return console.log("Port list '"+r+"' format error!"),"";let e;if(""===t&&""===r)return"";e=""===r?t:""===t?r:t+","+r;let g,u=e.split(",");for(let r=0;r<u.length;r++){portRangeReg.test(u[r]);let o=RegExp.$1,l=""!==RegExp.$2?RegExp.$3:o;var f,c,R,h;if(!(f=portlistPosGet(o)))return"";let t=o.split("/"),p=Number(t[0].slice(1)),i=Number(t[1]),s=f,n=p,a=i;if(o!==l){if(!(s=portlistPosGet(l)))return"";let t=l.split("/");n=Number(t[0].slice(1)),a=Number(t[1])}if((p>n||p===n&&i>a)&&(c=o,R=p,h=i,o=l,p=n,i=a,l=c,n=R,a=h),0===r)g=[[o,p,i,l,n,a]];else{let r,e;for(let t=1;t<=2;t++){var m=1===t?o:l,d=1===t?p:n,P=1===t?i:a,M=1===t?f:s;for(r=1===t?0:e;r<g.length;r++){var A=g[r][0],b=g[r][1],x=g[r][2],N=g[r][3],v=g[r][4],C=g[r][5];if(!portlistPosGet(A))return"";if(A!==N&&!portlistPosGet(N))return"";if((b<d||d===b&&x<=P)&&(d<v||d===v&&P<=C))break;if(d<b||d===b&&P<x){0===r?A===M[1]?g[r]=[m,d,P,N,v,C]:g.unshift([m,d,P,m,d,P]):_===M[0]&&A===M[1]?(g.splice(r-1,2,[E,$,y,N,v,C]),r--):_===M[0]?(g[r-1]=[E,$,y,m,d,P],r--):A===M[1]?g[r]=[m,d,P,N,v,C]:g.splice(r,0,[m,d,P,m,d,P]);break}if(!(r<g.length-1)){N===M[0]?g[r]=[A,b,x,m,d,P]:(g.push([m,d,P,m,d,P]),r++);break}var E=A,$=b,y=x,_=N}1===t?e=r:e<r&&g.splice(e,r-e+1,[g[e][0],g[e][1],g[e][2],g[r][3],g[r][4],g[r][5]])}}}u=[];for(let t=0;t<g.length;t++)u.push(g[t][0]===g[t][3]?g[t][0]:g[t][0]+"-"+g[t][3]);return u.join(",")}function portlistUnion(t,r=""){return listOperate(t,"∪",r,port_reg,portlistPosGet,portlistCompare)}function portlistDiff(t,r=""){return listOperate(t,"-",r,port_reg,portlistPosGet,portlistCompare)}function portlistInt(t,r=""){return listOperate(t,"∩",r,port_reg,portlistPosGet,portlistCompare)}function portlistToArray(t){return listOperate(t,"∪","",port_reg,portlistPosGet,portlistCompare,!0)}function portlistFromArray(t){return listFromArray(t,portlistUnion)}function portlistAddDelCalc(t,r,e,o,l,p){return listAddDelCalc(t,r,e,o,l,p,portlistUnion,portlistDiff,portlistInt)}function portCheck(t){if(t=t.replace(/\s/g,""),!portReg.test(t))return"Port '"+t+"' format error!";if(!Array.isArray(portMap)||0===portMap.length)return"Invalid port map!";let r=t.split("/");var e=Number(r[0].slice(1)),o=Number(r[1]);if(e<0||e>portMap.length-1)return"The slot '"+e+"' where the port '"+t+"' is located does not exist!";let l=portMap[e].replace(/\s/g,"");if(!portMapReg.test(l))return"The port range format '"+portMap[e]+"' of the slot '"+e+"' where the port '"+t+"' is located is incorrect!";if(""===l)return"The slot '"+e+"' where the port '"+t+"' is located does not contain any ports!";if(l[0]!==t[0])return"The type of port '"+t+"' should be '"+l[0]+"'!";var p=l.slice(1).split(",");for(let t=0;t<p.length;t++){slotPortRangeReg.test(p[t]);var i=Number(RegExp.$1),s=""!==RegExp.$2?Number(RegExp.$3):i;if(i<=o&&o<=s)return null}return"Port '"+t+"' is not in valid range '"+l[0]+e+"/"+l.slice(1)+"'!"}function portlistCheck(t){return listCheck(t,"port",portCheck,port_reg)}export default{setPortMap:setPortMap,portAll:portAll,portlistAdd:portlistUnion,portlistDel:portlistDiff,portlistFilter:portlistInt,portlistFromArray:portlistFromArray,portlistToArray:portlistToArray,portlistAddDelCalc:portlistAddDelCalc,portCheck:portCheck,portlistCheck:portlistCheck};
@@ -0,0 +1 @@
1
+ import list,{listElementPosGet,listOperate,listElementCheck}from"./list";var listCheck=list.listCheck,listFromArray=list.listFromArray,listAddDelCalc=list.listAddDelCalc;let vlanMap="1-4094";function setVlantMap(l){vlanMap=l}function vlanAll(){return vlanMap}function vlanLocatGet(l){return listElementPosGet(l,vlanMap)}function vlanlistUnion(l,t=""){return listOperate(l,"∪",t,null,vlanLocatGet,null)}function vlanlistDiff(l,t=""){return listOperate(l,"-",t,null,vlanLocatGet,null)}function vlanlistInt(l,t=""){return listOperate(l,"∩",t,null,vlanLocatGet,null)}function vlanlistToArray(l){return listOperate(l,"∪","",null,vlanLocatGet,null,!0)}function vlanlistFromArray(l){return listFromArray(l,vlanlistUnion)}function vlanlistAddDelCalc(l,t,n,a,i,e){return listAddDelCalc(l,t,n,a,i,e,vlanlistUnion,vlanlistDiff,vlanlistInt)}function vlanCheck(l){return listElementCheck(l,"vlan",vlanMap)}function vlanlistCheck(l){return listCheck(l,"vlan",vlanCheck)}export default{setVlantMap:setVlantMap,vlanAll:vlanAll,vlanlistAdd:vlanlistUnion,vlanlistDel:vlanlistDiff,vlanlistFilter:vlanlistInt,vlanlistFromArray:vlanlistFromArray,vlanlistToArray:vlanlistToArray,vlanlistAddDelCalc:vlanlistAddDelCalc,vlanCheck:vlanCheck,vlanlistCheck:vlanlistCheck};
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "listoperate",
3
+ "version": "1.0.7",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC"
11
+ }