How to use the jest-docblock.parseWithComments function in jest-docblock

To help you get started, we’ve selected a few jest-docblock 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 brodybits / prettierx / src / language-js / pragma.js View on Github external
function insertPragma(text) {
  const parsedDocblock = docblock.parseWithComments(docblock.extract(text));
  const pragmas = Object.assign({ format: "" }, parsedDocblock.pragmas);
  const newDocblock = docblock
    .print({
      pragmas,
      comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
    })
    .replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  const strippedText = docblock.strip(text);
  const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  return newDocblock + separatingNewlines + strippedText;
}
github dangmai / prettier-plugin-apex / src / pragma.js View on Github external
function insertPragma(text) {
  const parsedDocblock = docblock.parseWithComments(docblock.extract(text));
  const pragmas = { format: "", ...parsedDocblock.pragmas };
  const newDocblock = docblock
    .print({
      pragmas,
      comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, ""), // remove leading newlines
    })
    .replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  const strippedText = docblock.strip(text);
  const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  return newDocblock + separatingNewlines + strippedText;
}
github wix / stylable / packages / core / src / cssdocs.ts View on Github external
export function getCssDocsForSymbol(meta: StylableMeta, symbol: StylableSymbol): CssDoc | null {
    let commentNode;

    if (symbol._kind === 'class' || symbol._kind === 'element') {
        commentNode =
            meta.simpleSelectors[symbol.name] && meta.simpleSelectors[symbol.name].node.prev();
    } else if (symbol._kind === 'var') {
        commentNode = symbol.node.prev();
    }

    if (commentNode && commentNode.type === 'comment') {
        const { comments, pragmas } = parseWithComments(extract(commentNode.toString()));
        const res: CssDoc = {
            description: comments,
            tags: {}
        };

        for (const [pragmaName, pragmaValue] of Object.entries(pragmas)) {
            res.tags[pragmaName] = Array.isArray(pragmaValue) ? pragmaValue.join(' ') : pragmaValue;
        }

        return res;
    }

    return null;
}

jest-docblock

`jest-docblock` is a package that can extract and parse a specially-formatted comment called a "docblock" at the top of a file.

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis

Similar packages