Code coverage report for src/enc.js

Statements: 76.19% (48 / 63)      Branches: 64.29% (18 / 28)      Functions: 66.67% (10 / 15)      Lines: 76.19% (48 / 63)      Ignored: none     

All files » src/ » enc.js
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95  1 1 1 1 1                   1   1 4629 4629   1   1 243 984 171     72   1   1 163 163 1467 393       1   1                 1   1 242 242 2178 576     242   1   1 50 117 117 117 117   117     1   1         1   1 1 1 2 2 2     1    
// utility for enc
var consts_1 = require('./consts');
var vlEncDef = require('./encdef');
var util = require('./util');
var schema_1 = require('./schema/schema');
function countRetinal(enc) {
    var count = 0;
    if (enc.color)
        count++;
    if (enc.size)
        count++;
    if (enc.shape)
        count++;
    return count;
}
exports.countRetinal = countRetinal;
;
function has(enc, encType) {
    var fieldDef = enc && enc[encType];
    return fieldDef && fieldDef.name;
}
exports.has = has;
;
function isAggregate(enc) {
    for (var k in enc) {
        if (has(enc, k) && enc[k].aggregate) {
            return true;
        }
    }
    return false;
}
exports.isAggregate = isAggregate;
;
function forEach(enc, f) {
    var i = 0;
    schema_1.encTypes.forEach(function (k) {
        if (has(enc, k)) {
            f(enc[k], k, i++);
        }
    });
}
exports.forEach = forEach;
;
function map(enc, f) {
    var arr = [];
    schema_1.encTypes.forEach(function (k) {
        if (has(enc, k)) {
            arr.push(f(enc[k], k, enc));
        }
    });
    return arr;
}
exports.map = map;
;
function reduce(enc, f, init) {
    var r = init;
    schema_1.encTypes.forEach(function (k) {
        if (has(enc, k)) {
            r = f(r, enc[k], k, enc);
        }
    });
    return r;
}
exports.reduce = reduce;
;
function fields(enc) {
    return reduce(enc, function (m, field) {
        var fieldList = m[field.name] = m[field.name] || [], containsType = fieldList.containsType = fieldList.containsType || {};
        Eif (fieldList.indexOf(field) === -1) {
            fieldList.push(field);
            containsType[field.type] = true;
        }
        return m;
    }, {});
}
exports.fields = fields;
;
function shorthand(enc) {
    return map(enc, function (field, et) {
        return et + consts_1.Shorthand.Assign + vlEncDef.shorthand(field);
    }).join(consts_1.Shorthand.Delim);
}
exports.shorthand = shorthand;
;
function fromShorthand(shorthand) {
    var enc = util.isArray(shorthand) ? shorthand : shorthand.split(consts_1.Shorthand.Delim);
    return enc.reduce(function (m, e) {
        var split = e.split(consts_1.Shorthand.Assign), enctype = split[0].trim(), field = split[1];
        m[enctype] = vlEncDef.fromShorthand(field);
        return m;
    }, {});
}
exports.fromShorthand = fromShorthand;
;
//# sourceMappingURL=enc.js.map