UNPKG

srt-validator

Version:
68 lines (67 loc) 2.86 kB
"use strict"; 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 CaptionTimeSpanValidator = /** @class */ (function (_super) { __extends(CaptionTimeSpanValidator, _super); function CaptionTimeSpanValidator(parsedJSON) { var _this = _super.call(this, parsedJSON) || this; _this.parsedJSON = parsedJSON; _this.validator = 'CaptionTimeSpanValidator'; return _this; } CaptionTimeSpanValidator.prototype.validate = function () { var _this = this; if (!this.parsedJSON.length) { return this.result; } var previousEndTime = 0; this.parsedJSON .map(function (_a) { var _b = _a.time, start = _b.start, end = _b.end, lineNumbers = _a.lineNumbers; if (start >= end) { _this.addToResult({ errorCode: error_code_1.default.VALIDATOR_ERROR_START_TIME, message: 'start time should be less than end time', lineNumber: lineNumbers.timeSpan + 1, validator: _this.validator, }); } return { start: start, end: end, lineNumbers: lineNumbers }; }) .forEach(function (_a, index) { var start = _a.start, end = _a.end, lineNumbers = _a.lineNumbers; if (index === 0) { previousEndTime = end; return; } if (previousEndTime > start) { _this.addToResult({ errorCode: error_code_1.default.VALIDATOR_ERROR_END_TIME, message: 'start time should be less than previous end time', lineNumber: lineNumbers.timeSpan + 1, validator: _this.validator, }); } previousEndTime = end; }); return this.result; }; return CaptionTimeSpanValidator; }(base_1.default)); exports.default = CaptionTimeSpanValidator;