all files / lib/UrlGenerator/ UrlGeneratorNamedParamPart.js

100% Statements 10/10
100% Branches 6/6
100% Functions 2/2
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                  21× 21×               34×     30×     22×        
'use strict';
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
let UrlGeneratorNamedParamPart = class UrlGeneratorNamedParamPart {
    /**
     * @param {string} paramName
     * @param {Function} translate
    */
    constructor(paramName, translate) {
        this.paramName = paramName;
        this.translate = translate;
    }
 
    /**
     * @param {Object} args
     * @returns {string}
    */
    generate(args) {
        if (args[this.paramName] == null) {
            throw new Error(`Missing param name: "${ this.paramName }"`);
        }
 
        if (this.paramName === 'controller' || this.paramName === 'action') {
            return this.translate(args[this.paramName]);
        }
 
        return args[this.paramName];
    }
 
};
exports.default = UrlGeneratorNamedParamPart;
//# sourceMappingURL=UrlGeneratorNamedParamPart.js.map