calculate-items
Version:
Items calculation template
3 lines (2 loc) • 1.67 kB
JavaScript
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("lodash")):"function"==typeof define&&define.amd?define(["lodash"],i):(t="undefined"!=typeof globalThis?globalThis:t||self)["calculate-items/validator"]=i(t.lodash)}(this,(function(t){"use strict";return function(){function i(){}return i.isValidBrackets=function(t){for(var i=[],e={")":"(","]":"[","}":"{"},r=["(",")","[","]","{","}"],n=0,s=t;n<s.length;n++){var a=s[n];r.includes(a)&&(i.length>0&&e[a]===i[i.length-1]?i.pop():i.push(a))}return 0===i.length},i.isValidExpToParse=function(e){var r;if(t.isEmpty(t.trim(e))||(null===(r=t.trim(e))||void 0===r?void 0:r.length)<5)return!1;if(e.match(/[+\-*,\/]\s*$/g)||e.match(/^\s*[*\/]/g))return!1;if(e.match(/[*+\-/][+*\-/]/))return!1;if(e.match(/[a-zA-Z\u0430-\u044f]/)){if(!e.match(/[\w'`\\\/\u0430-\u044f\s.,\]\[]+\s*-\s*[\d()\]\[+\/*\-]+\s*\n*/g))return!1}else{if(e.match(/\s*[-,+]\s*$/))return!1;if(!e.match(/([\w)][*+-/][(\w])/g))return!1;if(e.replace(/\s*([+-/])\s*/g,"$1").match(/([^\d)][-*+/][^(\d])/g))return!1}if(!i.isValidBrackets(e))return!1;if(e.match(/\(/g)){if(!e.match(/(\([\d+\-*/]{3,}\))|(\[[\d,+\-*/]+])/g))return!1;if(e.match(/([^+\-/*\s]\s*\()|(\)\s*[^+\-/*\n\s])/g))return!1}else if(e.match(/\[/g)&&!e.match(/\[[\d,\s]+]/g))return!1;return!0},i.getInvalidMessage=function(i){if(t.isEmpty(t.trim(i))||i.match(/\s*\+\s*$/))return"Formatga mos matn kiritirsh zarur";if(!t.includes(i,"-"))return"Chiziqcha(-) belgisi bo'lishi shart";var e=t.split(i,"-"),r=t.nth(e,1);return!r||r&&!/\d+/g.test(r)?"Chiziqcha(-)ni o'ng tomonida raqam bo'lishi shart":void 0},i}()}));
//# sourceMappingURL=validator.umd.js.map