diff --git a/lib/index.js b/lib/index.js index 31ce7ff..ee2aada 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,16 +49,30 @@ return tag } - return str.replace(/\[(\d+;)?(\d+)*m/g, function(match, b1, b2) { - var i, code, res = '' - if (b2 == '' || b2 == null) b2 = '0' - for (i = 1; i < arguments.length - 2; i++) { - if (!arguments[i]) continue - code = parseInt(arguments[i]) - res += tag(code) + function validateString(string) { + var strArray = string.split('[') + if (strArray.length === 0) return false + for (var item in strArray) { + if (strArray[item].length > 10) { + return false + } } - return res - }) + tag() + return true + } + + if (validateString(str)) { + return str.replace(/\[(\d+;)?(\d+)*m/g, function(match, b1, b2) { + var i, code, res = '' + if (b2 == '' || b2 == null) b2 = '0' + for (i = 1; i < arguments.length - 2; i++) { + if (!arguments[i]) continue + code = parseInt(arguments[i]) + res += tag(code) + } + return res + }) + tag() + } + return null } /* not implemented: