All files Uri.js

100% Statements 17/17
100% Branches 4/4
100% Functions 7/7
100% Lines 17/17
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                      723x 723x   6x     717x 717x 4302x 4302x     717x               1x       1257x 1256x   1x       11647x 11091x   556x       518x       4x          
import {
    splitUri,
    forEachPartName,
    getRegExp,
    getPartConstructor
} from './utils.js';
import RouterError from './RouterError.js';
 
export default class Uri {
    constructor (rawUri) {
        let splittedUri;
        try {
            splittedUri = splitUri(rawUri, this._getRegExp());
        } catch(error) {
            this._handleError(error);
        }
 
        const parsedUri = {};
        forEachPartName((partName) => {
            const PartConstructor = getPartConstructor(partName);
            parsedUri[partName] = new PartConstructor(splittedUri[partName]);
        });
 
        this._value = {
            rawUri,
            splittedUri,
            parsedUri
        };
    }
 
    getRawUri () {
        return this._value.rawUri;
    }
 
    getSplittedUri (partName) {
        if (partName) {
            return this._value.splittedUri[partName];
        }
        return this._value.splittedUri;
    }
 
    getParsedUri (partName) {
        if (partName) {
            return this._value.parsedUri[partName];
        }
        return this._value.parsedUri;
    }
 
    _getRegExp () {
        return getRegExp('uri');
    }
 
    _handleError (error) {
        throw new RouterError(RouterError[error.code], {
            entity: 'URI'
        });
    }
}