# All files / infrastructure/angular angular-version.util.ts

100% Statements 28/28
62.5% Branches 5/8
100% Functions 8/8
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    591x

    1x
    1x

    1x
    1x
    1x

    1x

    1x
    4x

    1x
    2x

    2x
    2x
    2x
    1x

    2x

    1x

    1x
    1x

    1x

    1x
    1x

    1x
    1x
    1x

    1x

    1x
     import * as semver from 'semver';
    import { IAngularApi } from './angular-api.util';

    export class AngularVersionUtil {
        private static readonly CorePackage = '@angular/core';

        private static instance: AngularVersionUtil;
        private constructor() {}
        public static getInstance() {
            Eif (!AngularVersionUtil.instance) {
                AngularVersionUtil.instance = new AngularVersionUtil();
            }
            return AngularVersionUtil.instance;
        }

        public cleanVersion(version: string): string {
            return version
                .replace('~', '')
                .replace('^', '')
                .replace('=', '')
                .replace('<', '')
                .replace('>', '');
        }

        public getAngularVersionOfProject(packageData): string {
            let _result = '';

            Eif (packageData.dependencies) {
                let angularCore = packageData.dependencies[AngularVersionUtil.CorePackage];
                if (angularCore) {
                    _result = this.cleanVersion(angularCore);
                }
            }

            return _result;
        }

        private isAngularVersionArchived(version: string): boolean {
            let result;

            try {
                result = semver.compare(version, '2.4.10') <= 0;
            } catch (e) {}

            return result;
        }

        public prefixOfficialDoc(version: string): string {
            return this.isAngularVersionArchived(version) ? 'v2.' : '';
        }

        public getApiLink(api: IAngularApi, angularVersion: string): string {
            let angularDocPrefix = this.prefixOfficialDoc(angularVersion);
            return `https://${angularDocPrefix}angular.io/${api.path}`;
        }
    }

    export default AngularVersionUtil.getInstance();