srt-validator
Version:
<h1 align="center">SrtValidator</h1>
58 lines (57 loc) • 2.58 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var base_1 = require("./base");
var error_code_1 = require("../utils/error-code");
var LineNumberValidator = /** @class */ (function (_super) {
__extends(LineNumberValidator, _super);
function LineNumberValidator(parsedJSON) {
var _this = _super.call(this, parsedJSON) || this;
_this.parsedJSON = parsedJSON;
_this.validator = 'LineNumberValidator';
return _this;
}
LineNumberValidator.prototype.validate = function () {
if (!this.parsedJSON.length) {
return this.result;
}
// need to start with 1
if (this.parsedJSON[0].sequenceNumber !== 1) {
this.addToResult({
errorCode: error_code_1.default.VALIDATOR_ERROR_SEQUENCE_NUMBER_START,
message: 'number of sequence need to start with 1',
lineNumber: this.parsedJSON[0].lineNumbers.chunkStart + 1,
validator: this.validator,
});
}
// start at index 1, because we already validated the first sequence
for (var i = 1; i < this.parsedJSON.length; i += 1) {
var _a = this.parsedJSON[i], sequenceNumber = _a.sequenceNumber, lineNumbers = _a.lineNumbers;
if (sequenceNumber !== i + 1) {
this.addToResult({
errorCode: error_code_1.default.VALIDATOR_ERROR_SEQUENCE_NUMBER_INCREMENT,
message: 'number of sequence need to increment by 1',
lineNumber: lineNumbers.chunkStart + 1,
validator: this.validator,
});
}
}
return this.result;
};
return LineNumberValidator;
}(base_1.default));
exports.default = LineNumberValidator;
;