How to use the strip-indent function in strip-indent

To help you get started, we’ve selected a few strip-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 vadimdemedes / pastel / test / commands.js View on Github external
test('positional args', async t => {
	await build('positional-args');
	const helpOutput = await cli('positional-args', ['--help']);

	t.is(helpOutput, stripIndent(`
		cli  

		Positional args command

		Positionals:
		  message        Message                                                [string]
		  other-message  Other message                                          [string]

		Options:
		  --help     Show help                                                 [boolean]
		  --version  Show version number                                       [boolean]
	`).trim());

	const cmdOutput = await cli('positional-args', ['hello', 'world', 'something', 'else']);

	t.is(cmdOutput, stripIndent(`
github kentcdodds / css-in-js-precompiler / src / __tests__ / babel-plugin.js View on Github external
function transpile(source) {
  const {code} = babel.transform(stripIndent(source).trim(), {
    parserOpts: {parser: recast.parse},
    generatorOpts: {generator: recast.print, lineTerminator: '\n'},
    babelrc: false,
    plugins: [plugin],
  })
  return code
}
github resugar / resugar / test / support / check.js View on Github external
export function checkExample(name: string, options: Object={}) {
  let plugin = dirname(name);
  let directory = join('test/form', name);
  let expectedDir = join(directory, '_expected');
  let actualDir = join(directory, '_actual');
  let input = read(join(directory, 'main.js'));
  let actual = convert(stripIndent(input).trim(), options);

  mkdir(actualDir);
  write(join(actualDir, 'main.js'), actual.code);
  writeJSON(join(actualDir, 'metadata.json'), { [plugin]: actual.metadata[plugin] });
  writeJSON(join(actualDir, 'ast.json'), actual.ast);
  if (actual.warnings.length > 0) {
    writeJSON(join(actualDir, 'warnings.json'), actual.warnings);
  }

  let expectedCode = read(join(expectedDir, 'main.js'));
  let expectedMetadata = readOptionalJSON(join(expectedDir, 'metadata.json'));
  let expectedWarnings = readOptionalJSON(join(expectedDir, 'warnings.json'));

  strictEqual(actual.code, stripIndent(expectedCode).trim());

  deepEqual(actual.warnings, expectedWarnings || []);
github resugar / resugar / test / support / check.js View on Github external
let input = read(join(directory, 'main.js'));
  let actual = convert(stripIndent(input).trim(), options);

  mkdir(actualDir);
  write(join(actualDir, 'main.js'), actual.code);
  writeJSON(join(actualDir, 'metadata.json'), { [plugin]: actual.metadata[plugin] });
  writeJSON(join(actualDir, 'ast.json'), actual.ast);
  if (actual.warnings.length > 0) {
    writeJSON(join(actualDir, 'warnings.json'), actual.warnings);
  }

  let expectedCode = read(join(expectedDir, 'main.js'));
  let expectedMetadata = readOptionalJSON(join(expectedDir, 'metadata.json'));
  let expectedWarnings = readOptionalJSON(join(expectedDir, 'warnings.json'));

  strictEqual(actual.code, stripIndent(expectedCode).trim());

  deepEqual(actual.warnings, expectedWarnings || []);

  if (expectedMetadata) {
    for (let key in expectedMetadata) {
      deepEqual(
        actual.metadata[key],
        expectedMetadata[key]
      );
    }
  }

  deepEqual(
    cleanNode(actual.ast.program),
    cleanNode(parse(actual.code, BABEL_PARSE_OPTIONS).program),
    're-written AST should match re-written code'
github prisma / photonjs / packages / photon-generate / src / runtime / utils / dedent.ts View on Github external
export function dedent(str: string): string {
  console.log(str)
  return strip(str).trim()
}
github kaisermann / svelte-preprocess / src / autoProcess.ts View on Github external
if (preserve.includes(lang) || preserve.includes(alias)) {
      return;
    }

    if (lang === targetLanguage) {
      return { code: content, dependencies };
    }

    if (transformers[lang] === false || transformers[alias] === false) {
      throwUnsupportedError(alias, filename);
    }

    const transformed = await runTransformer(
      lang,
      getTransformerOptions(lang, alias),
      { content: stripIndent(content), filename },
    );

    return {
      ...transformed,
      dependencies: concat(dependencies, transformed.dependencies),
    };
  };
github lttb / postjss / src / common / parse-template-string.js View on Github external
export default async ({ strings, values, from, processCSS }) => {
  const data = stripIndent(strings.join(VAR)).trim().concat('\n')

  const { styles } = await processCSS({ data, from })

  let index = 0

  const getVal = (val) => {
    const [match, left, right] = (val.match(placeholderRe) || [])

    if (!match) {
      return val
    }

    const body = values[index]
    index += 1

    return (left || right) && typeof body !== 'function'
github danreeves / react-tether / example / components / code.js View on Github external
const Code = ({
  children,
  className,
}: {
  children: React.Node,
  className: string,
}) => (
  <pre>    {strip(children)
      .replace(/^\n*/, '')
      .replace(/\s*\n*$/, '')}
  </pre>
);
github prisma / prisma2 / cli / cli / src / utils.ts View on Github external
export function format(input: string = ''): string {
  return dedent(input).trimRight() + '\n'
}
github doczjs / docz / core / docz-utils / src / jsx.ts View on Github external
export const sanitizeCode = (code: string) => {
  const trimmed = strip(code).trim()
  const newCode =
    trimmed.startsWith('{') && trimmed.endsWith('}')
      ? trimmed.substr(1, trimmed.length - 2).trim()
      : trimmed

  return escapeJS(strip(newCode))
}

strip-indent

Strip leading whitespace from each line in a string

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular strip-indent functions