all files / packages/links-ext/services/links/ native-link.js

50% Statements 9/18
0% Branches 0/2
16.67% Functions 1/6
50% Lines 9/18
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                                                                                    
var _ = require('lodash');
 
/**
 * @dgService getNativeTypeLink
 * @description returns native type link or empty string
 */
module.exports = function nativeLink(log) {
    var NATIVE_TYPES = [
        'arguments', 'Array', 'ArrayBuffer', 'Boolean', 'DataView', 'Date', 'Error', 'EvalError', 'Float32Array',
        'Float64Array', 'Function', 'Generator', 'GeneratorFunction', 'Infinity', 'Int16Array', 'Int32Array',
        'Int8Array', 'InternalError', 'Intl', 'Intl.Collator', 'Intl.DateTimeFormat', 'Intl.NumberFormat', 'Iterator',
        'JSON', 'Map', 'Math', 'NaN', 'null', 'Number', 'Object', 'ParallelArray', 'Promise', 'Proxy', 'RangeError',
        'ReferenceError', 'Reflect', 'RegExp', 'SIMD', 'SIMD.Float32x4', 'SIMD.Float64x2', 'SIMD.Int16x8',
        'SIMD.Int32x4', 'SIMD.Int8x16', 'Set', 'StopIteration', 'String', 'Symbol', 'SyntaxError', 'TypeError',
        'TypedArray', 'URIError', 'Uint16Array', 'Uint32Array', 'Uint8Array', 'Uint8ClampedArray', 'WeakMap',
        'WeakSet', 'undefined'
    ];
 
    var BASE_URL = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/${component}';
 
    function getEntry (types, component) {
        var component = component.match(/^([^\s\(\)\[\]]+)/)[1].toLowerCase();
        return _.find(types, function (type) {
            return type.toLowerCase() === component;
        });
    }
 
    function checkApplicability (component) {
        var res = false;
        if (component) {
            res = !!getEntry(this.types, component);
        }
        return res;
    }
 
    function makeUrl (component) {
        return _.template(this.baseUrl)({component: getEntry(this.types, component)});
    }
 
    function makeTitle (component, title) {
        return getEntry(this.types, component);
    }
 
    return {
        baseUrl: BASE_URL,
        types: NATIVE_TYPES,
        test: checkApplicability,
        url: makeUrl,
        title: makeTitle
    };
};