How to use min-indent - 1 common examples

To help you get started, we’ve selected a few min-indent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dylang / logging / src / formatters / format-color / format-any / format-error.ts View on Github external
if (!filename || filename.endsWith('node_modules/babel-register/lib/node.js')) {
        return chalk.gray(stackLine.trim());
    }

    if (!existsSync(filename)) {
        return chalk.gray(stackLine.trim()); // + ` (${filename} not found)`;
    }
    const lineNumber = parseInt(lineAsString, 10) - 1;

    const fileContents = readFileSync(filename, { encoding: 'UTF-8' }).toString() + '//EOF';
    const lines = fileContents.split('\n');
    const linesAbove = !lines[lineNumber - 2] ? 1 : 2;
    const linesBelow = !lines[lineNumber + 2] ? 1 : 2;
    const linesToShow = lines.slice(lineNumber - linesAbove, lineNumber + linesBelow + 1).join('\n');
    const unIndentCount = minIndent(linesToShow);
    const modifiedFileContents = [
        ...lines.slice(0, lineNumber - linesAbove),
        stripIndent(linesToShow),
        ...lines.slice(lineNumber + linesBelow)
    ].join('\n');
    const annotatedCode = codeFrameColumns(
        modifiedFileContents,
        { start: { line: lineNumber + 1, column: parseInt(character, 10) - unIndentCount } },
        {
            forceColor: true,
            highlightCode: true,
            linesAbove,
            linesBelow,
            message
        }
    );

min-indent

Get the shortest leading whitespace from lines in a string

MIT
Latest version published 4 years ago

Package Health Score

68 / 100
Full package analysis

Popular min-indent functions