All files TemplateUri.js

100% Statements 11/11
100% Branches 4/4
100% Functions 4/4
100% Lines 11/11
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 35                204x 202x   202x 202x 116x 255x   116x 2x           203x       2x 2x            
import {
    getRegExp
} from './utils.js';
import Uri from './Uri.js';
import RouterError from './RouterError.js';
 
export default class TemplateUri extends Uri {
    constructor (rawUri, routeName) {
        super(rawUri);
        this._routeName = routeName;
 
        const parsedPathArray = this._value.parsedUri.path.toArray();
        if (parsedPathArray.length > 1) {
            const emptyPathComponentIndex = parsedPathArray.findIndex((component) => {
                return !component;
            });
            if (emptyPathComponentIndex !== -1) {
                throw new RouterError(RouterError.PATH_COMPONENT_EXPECTED, {routeName});
            }
        }
    }
 
    _getRegExp () {
        return getRegExp('template');
    }
 
    _handleError (error) {
        const routeName = this._routeName;
        throw new RouterError(RouterError[error.code], {
            entity: 'URI template',
            routeName
        });
    }
}