All files formatting.js

25.31% Statements 20/79
100% Branches 5/5
50% Functions 1/2
25.31% Lines 20/79

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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 801x 1x 1x 1x 3x 3x 2x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 3x 1x                                                                                                                       1x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatFilters = exports.formatBitrate = void 0;
const regexp_1 = require("./regexp");
function formatBitrate(bitrate) {
    if (typeof bitrate === 'number') {
        if (bitrate < 1024) {
            // Assume the user means kbps
            return `${bitrate}k`;
        }
        else {
            return `${bitrate}`;
        }
    }
    else {
        return bitrate;
    }
}
exports.formatBitrate = formatBitrate;
function formatFilters(specs) {
    /* Filter syntax:
  
        filter := inputs? filterspec outputs?
        
        inputs := input inputs?
        input := '[' input-name ']'
  
        outputs := output outputs?
        output := '[' output-name ']'
  
        filterspec := filter-name ('=' filterargs)?
        filterargs := filterarg (':' filterargs)?
        filterarg := arg-value | (arg-name '=' arg-value)
     */
    return specs.map((spec) => {
        if (typeof spec === 'string') {
            return spec;
        }
        if (spec.input) {
            spec.inputs = [spec.input];
        }
        let inputs = (spec.inputs || []).map((stream) => stream.replace(regexp_1.streamRegexp, '[$1]')).join('');
        let options = '';
        if (spec.options) {
            if (typeof spec.options === 'string') {
                options = `=${spec.options}`;
            }
            else if (Array.isArray(spec.options)) {
                let optionStrings = spec.options
                    .map((option) => {
                    if (option.match(regexp_1.filterNeedsEscapeRegexp)) {
                        return `'${option}'`;
                    }
                    else {
                        return option;
                    }
                });
                options = `=${optionStrings.join(':')}`;
            }
            else {
                let optionStrings = Object.entries(spec.options)
                    .map(([key, value]) => {
                    if (value.match(regexp_1.filterNeedsEscapeRegexp)) {
                        value = `'${value}'`;
                    }
                    return `${key}=${value}`;
                });
                options = `=${optionStrings.join(':')}`;
            }
        }
        let filter = `${spec.filter}${options}`;
        if (spec.output) {
            spec.outputs = [spec.output];
        }
        let outputs = (spec.outputs || []).map((stream) => stream.replace(regexp_1.streamRegexp, '[$1]')).join('');
        return `${inputs}${filter}${outputs}`;
    });
}
exports.formatFilters = formatFilters;