Function parseFileName

  • Parses a file name to determine if it's a parameterized command file.

    Parameterized command files are named using the following format:

    • [param] - A single parameter with no file extension
    • [param].ts - A single parameter
    • [...param].ts - A spread operator parameter

    Parameters

    • fileName: string

      The file name to parse.

    Returns {
        extension: string | undefined;
        paramName: string | undefined;
        spreadOperator: string | undefined;
    }

    Object containing the spread operator, parameter name, and file extension, if any.

    • extension: string | undefined
    • paramName: string | undefined
    • spreadOperator: string | undefined
    // A single parameter with no file extension
    parseFileName('[foo]');
    // => {
    // spreadOperator: undefined,
    // paramName: 'foo',
    // extension: undefined,
    // }

    // A single parameter
    parseFileName('[foo].ts');
    // => {
    // spreadOperator: undefined,
    // paramName: 'foo',
    // extension: '.ts',
    // }

    // A spread operator parameter
    parseFileName('[...foo].ts');
    // => {
    // spreadOperator: '...',
    // paramName: 'foo',
    // extension: '.ts',
    // }

    // Not a parameterized command file
    parseFileName('foo.ts');
    // => {
    // spreadOperator: undefined,
    // paramName: undefined,
    // extension: undefined,
    // }