incr-regex-package
Version:
An incremental regular expression parser in JavaScript; useful for input validation, RegExp
70 lines (62 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2016, Nurul Choudhury
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
var MultiMask = exports.MultiMask = function () {
function MultiMask(m1, m2, m3) {
_classCallCheck(this, MultiMask);
var list = [m1, m2, m3];
this.multi = list.map(function (e) {
return { flag: true, element: e };
});
this.len = 0;
this.raw = '';
}
_createClass(MultiMask, [{
key: 'findTrue',
value: function findTrue() {
var res = this.multi.filter(function (e) {
return e.flag;
});
return { flag: res.length > 0, rest: res };
}
}, {
key: 'findLen',
value: function findLen() {
var length = this.length;
var res = this.multi.filter(function (e) {
return e.selection.end == length;
});
return { len: res.length, rest: res };
}
}, {
key: 'input',
value: function input(c) {
if (someTrue(this.multi, c)) {
this.length++;
this.raw = this;
return true;
}
return false;
}
}]);
return MultiMask;
}();