All files / src/modules/interfaces commands.js

89.47% Statements 17/19
90.9% Branches 10/11
100% Functions 1/1
89.47% Lines 17/19

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 2040x 40x 768x 9216x 9216x 9216x     9216x 9216x 9216x 9216x 9216x 9216x 9216x 9216x 768x 768x 40x  
'use strict';
module.exports = ({ definitions }) => {
    const commands = definitions.map((definition) => {
        const command = definition.value;
        const match = /^(?:[a-z]+(?:-[a-z]+)*)\/([a-z]+(?:-[a-z]+)*)\.js$/u.exec(definition.relativePath);
        if (!match) {
            throw new TypeError(`Command definition must be in one group directory: ${definition.relativePath}`);
        }
        const [, commandName] = match;
        return Object.freeze({
            formatText: command.formatText,
            ...(command.prepareOutput === undefined ? {} : { prepareOutput: command.prepareOutput }),
            ...(command.loadFormatData === undefined ? {} : { loadFormatData: command.loadFormatData }),
            ...(command.formatCsv === undefined ? {} : { formatCsv: command.formatCsv }),
            name: commandName, operation: definition.name,
        });
    }).sort((left, right) => left.name.localeCompare(right.name, 'en'));
    return { definitions: Object.freeze(commands) };
};