UNPKG

imagemagick-async

Version:
120 lines (102 loc) 2.5 kB
let Path = require('path'); let PathParts = __dirname.split(Path.sep); let index = PathParts.indexOf('imagemagick-async'); let RootDir = PathParts.slice(0, index + 1).join(Path.sep); let Err = require(Path.join(RootDir, 'error.js')); let Validate = require(Path.join(RootDir, 'validate.js')); let Filepath = require(Path.join(RootDir, 'filepath.js')).Filepath; let ComposeBaseClass = require(Path.join(Filepath.ModComposeDir(), 'composebaseclass.js')).ComposeBaseClass; //------------------------------ class Exclusion extends ComposeBaseClass { constructor(builder) { super(builder); } /** * @override */ static get Builder() { class Builder { constructor() { this.name = 'Exclusion'; this.args = {}; } /** * @param {string} str */ source1(str) { this.args.source1 = str; return this; } /** * @param {string} str */ source2(str) { this.args.source2 = str; return this; } build() { return new Exclusion(this); } } return new Builder(); } /** * @returns {Array<string|number>} Returns an array of image magick arguments associated with this layer. */ Args() { return [this.args.source1, this.args.source2, '-compose', 'Minus_Src', '-composite']; } /** * @override */ Errors() { let params = Exclusion.Parameters(); let errors = []; let prefix = 'EXCLUSION_COMPOSE_MOD_ERROR'; let source1Err = Err.ErrorMessage.Builder .prefix(prefix) .varName('Source 1') .condition( new Err.StringCondition.Builder(this.args.source1) .isempty(false) .isWhitespace(false) .build() ) .build() .String(); if (source1Err) errors.push(source1Err); let source2Err = Err.ErrorMessage.Builder .prefix(prefix) .varName('Source 2') .condition( new Err.StringCondition.Builder(this.args.source2) .isempty(false) .isWhitespace(false) .build() ) .build() .String(); if (source2Err) errors.push(source2Err); return errors; } /** * @override */ static Parameters() { return { source1: { type: 'string', required: true }, source2: { type: 'string', required: true }, }; } } //------------------------- // EXPORTS exports.Exclusion = Exclusion;