UNPKG

@badeball/cypress-cucumber-preprocessor

Version:

[![Build status](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml/badge.svg)](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml) [![Npm package weekly downloads](https://badgen.net/n

29 lines (28 loc) 873 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.minIndent = minIndent; exports.stripIndent = stripIndent; exports.indent = indent; function minIndent(content) { const match = content.match(/^[ \t]*(?=\S)/gm); if (!match) { return 0; } return match.reduce((r, a) => Math.min(r, a.length), Infinity); } function stripIndent(content) { const indent = minIndent(content); if (indent === 0) { return content; } const regex = new RegExp(`^[ \\t]{${indent}}`, "gm"); return content.replace(regex, ""); } function indent(string, options = {}) { const { count = 1, indent = " ", includeEmptyLines = false } = options; if (count === 0) { return string; } const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm; return string.replace(regex, indent.repeat(count)); }