xliff-generator
Version:
A simple module to create xliff files
39 lines (38 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("../errors");
const _1 = require("./");
class CreateFromCsvConfigValidator {
/**
* @param config {CreateFromCsvConfig} instance to validate
* @throws {ValidationError} will be thrown if an error during the validation occured
*/
validate(config) {
if (this.isNullOrUndefined(config.csvComment) || !this.hasZeroOrOneCharacter(config.csvComment)) {
throw new errors_1.ValidationError('Value for parameter \'csvCommet\' contains more than one character');
}
if (this.isNullOrUndefined(config.csvDelimiter) || !this.hasExactlyOneCharacter(config.csvDelimiter)) {
throw new errors_1.ValidationError('Value for parameter \'csvDelimiter\' contains not exaclty one character');
}
if (this.isNullOrUndefined(config.csvEscape) || !this.hasExactlyOneCharacter(config.csvEscape)) {
throw new errors_1.ValidationError('Value for parameter \'csvEscape\' contains not exaclty one character');
}
if (this.isNullOrUndefined(config.csvQuote) || !this.hasExactlyOneCharacter(config.csvQuote)) {
throw new errors_1.ValidationError('Value for parameter \'csvQuote\' contains not exaclty one character');
}
const langOptionsValidator = new _1.LanguageOptionsValidator();
langOptionsValidator.validate(config.languageOptions);
const productNameValidator = new _1.ProductNameValidator();
productNameValidator.validate(config.productName);
}
isNullOrUndefined(value) {
return value === null || value === undefined;
}
hasZeroOrOneCharacter(value) {
return value.length === 0 || this.hasExactlyOneCharacter(value);
}
hasExactlyOneCharacter(value) {
return value.length === 1;
}
}
exports.CreateFromCsvConfigValidator = CreateFromCsvConfigValidator;