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.
Last updated 6 years ago by rubennorte .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install jest-docblock 
SYNC missed versions from official npm registry.

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.

A docblock looks like this:

/**
 * Stuff goes here!
 */

Docblocks can contain pragmas, which are words prefixed by @:

/**
 * Pragma incoming!
 *
 * @flow
 */

Pragmas can also take arguments:

/**
 * Check this out:
 *
 * @myPragma it is so cool
 */

jest-docblock can:

  • extract the docblock from some code as a string
  • parse a docblock string's pragmas into an object
  • print an object and some comments back to a string

Installation

# with yarn
$ yarn add jest-docblock
# with npm
$ npm install jest-docblock

Usage

const code = `
/**
 * Everything is awesome!
 *
 * @everything is:awesome
 * @flow
 */

 export const everything = Object.create(null);
 export default function isAwesome(something) {
   return something === everything;
 }
`;

const {
  extract,
  strip,
  parse,
  parseWithComments,
  print,
} = require('jest-docblock');

const docblock = extract(code);
console.log(docblock); // "/**\n * Everything is awesome!\n * \n * @everything is:awesome\n * @flow\n */"

const stripped = strip(code);
console.log(stripped); // "export const everything = Object.create(null);\n export default function isAwesome(something) {\n return something === everything;\n }"

const pragmas = parse(docblock);
console.log(pragmas); // { everything: "is:awesome", flow: "" }

const parsed = parseWithComments(docblock);
console.log(parsed); // { comments: "Everything is awesome!", pragmas: { everything: "is:awesome", flow: "" } }

console.log(print({pragmas, comments: 'hi!'})); // /**\n * hi!\n *\n * @everything is:awesome\n * @flow\n */;

API Documentation

extract(contents: string): string

Extracts a docblock from some file contents. Returns the docblock contained in contents. If contents did not contain a docblock, it will return the empty string ("").

strip(contents: string): string

Strips the top docblock from a file and return the result. If a file does not have a docblock at the top, then return the file unchanged.

parse(docblock: string): {[key: string]: string | string[] }

Parses the pragmas in a docblock string into an object whose keys are the pragma tags and whose values are the arguments to those pragmas.

parseWithComments(docblock: string): { comments: string, pragmas: {[key: string]: string | string[]} }

Similar to parse except this method also returns the comments from the docblock. Useful when used with print().

print({ comments?: string, pragmas?: {[key: string]: string | string[]} }): string

Prints an object of key-value pairs back into a docblock. If comments are provided, they will be positioned on the top of the docblock.

Current Tags

  • 29.4.3                                ...           latest (2 years ago)
  • 29.0.0-alpha.3                                ...           next (2 years ago)

105 Versions

  • 29.4.3                                ...           2 years ago
  • 29.4.2                                ...           2 years ago
  • 29.2.0                                ...           2 years ago
  • 29.0.0                                ...           2 years ago
  • 29.0.0-alpha.3                                ...           2 years ago
  • 29.0.0-alpha.2                                ...           2 years ago
  • 29.0.0-alpha.0                                ...           2 years ago
  • 28.1.1                                ...           3 years ago
  • 28.0.2                                ...           3 years ago
  • 28.0.0                                ...           3 years ago
  • 28.0.0-alpha.6                                ...           3 years ago
  • 28.0.0-alpha.3                                ...           3 years ago
  • 28.0.0-alpha.0                                ...           3 years ago
  • 27.5.1                                ...           3 years ago
  • 27.5.0                                ...           3 years ago
  • 27.4.0                                ...           3 years ago
  • 27.0.6                                ...           3 years ago
  • 27.0.1                                ...           4 years ago
  • 27.0.0-next.10                                ...           4 years ago
  • 27.0.0-next.0                                ...           4 years ago
  • 26.0.0                                ...           5 years ago
  • 26.0.0-alpha.0                                ...           5 years ago
  • 25.3.0                                ...           5 years ago
  • 25.2.6                                ...           5 years ago
  • 25.2.3                                ...           5 years ago
  • 25.2.1-alpha.2                                ...           5 years ago
  • 25.2.1-alpha.1                                ...           5 years ago
  • 25.2.0                                ...           5 years ago
  • 25.2.0-alpha.86                                ...           5 years ago
  • 25.1.0                                ...           5 years ago
  • 25.0.0                                ...           5 years ago
  • 24.9.0                                ...           5 years ago
  • 24.3.0                                ...           6 years ago
  • 24.2.0-alpha.0                                ...           6 years ago
  • 24.2.0 [deprecated]           ...           6 years ago
  • 24.0.0                                ...           6 years ago
  • 24.0.0-alpha.16                                ...           6 years ago
  • 24.0.0-alpha.15                                ...           6 years ago
  • 24.0.0-alpha.13                                ...           6 years ago
  • 24.0.0-alpha.12                                ...           6 years ago
  • 24.0.0-alpha.11                                ...           6 years ago
  • 24.0.0-alpha.10                                ...           6 years ago
  • 24.0.0-alpha.9                                ...           6 years ago
  • 24.0.0-alpha.7                                ...           6 years ago
  • 24.0.0-alpha.6                                ...           6 years ago
  • 24.0.0-alpha.5                                ...           6 years ago
  • 24.0.0-alpha.4                                ...           6 years ago
  • 24.0.0-alpha.2                                ...           6 years ago
  • 24.0.0-alpha.1                                ...           6 years ago
  • 24.0.0-alpha.0                                ...           6 years ago
  • 23.2.0                                ...           6 years ago
  • 23.0.1                                ...           7 years ago
  • 22.4.3                                ...           7 years ago
  • 22.4.0                                ...           7 years ago
  • 22.2.2                                ...           7 years ago
  • 22.2.0                                ...           7 years ago
  • 22.1.0                                ...           7 years ago
  • 22.0.6                                ...           7 years ago
  • 22.0.3                                ...           7 years ago
  • 22.0.2                                ...           7 years ago
  • 22.0.1                                ...           7 years ago
  • 22.0.0                                ...           7 years ago
  • 21.3.0-beta.15                                ...           7 years ago
  • 21.3.0-beta.14                                ...           7 years ago
  • 21.3.0-beta.13                                ...           7 years ago
  • 21.3.0-beta.12                                ...           7 years ago
  • 21.3.0-beta.11                                ...           7 years ago
  • 21.3.0-beta.10                                ...           7 years ago
  • 21.3.0-beta.9                                ...           7 years ago
  • 21.3.0-beta.8                                ...           7 years ago
  • 21.3.0-beta.7                                ...           7 years ago
  • 21.3.0-beta.6                                ...           7 years ago
  • 21.3.0-beta.5                                ...           7 years ago
  • 21.3.0-beta.4                                ...           7 years ago
  • 21.3.0-beta.3                                ...           7 years ago
  • 21.3.0-beta.2                                ...           7 years ago
  • 21.3.0-beta.1                                ...           7 years ago
  • 21.3.0-alpha.eff7a1cf                                ...           7 years ago
  • 21.3.0-alpha.1e3ee68e                                ...           7 years ago
  • 21.2.0                                ...           7 years ago
  • 21.1.0                                ...           7 years ago
  • 21.0.2                                ...           7 years ago
  • 21.0.0                                ...           7 years ago
  • 21.0.0-beta.1                                ...           7 years ago
  • 21.0.0-alpha.2                                ...           7 years ago
  • 21.0.0-alpha.1                                ...           7 years ago
  • 20.1.0-echo.1                                ...           7 years ago
  • 20.1.0-delta.5                                ...           7 years ago
  • 20.1.0-delta.4                                ...           7 years ago
  • 20.1.0-delta.3                                ...           7 years ago
  • 20.1.0-delta.2                                ...           7 years ago
  • 20.1.0-delta.1                                ...           7 years ago
  • 20.1.0-chi.1                                ...           7 years ago
  • 20.1.0-beta.1                                ...           7 years ago
  • 20.1.0-alpha.3                                ...           7 years ago
  • 20.1.0-alpha.2                                ...           7 years ago
  • 20.1.0-alpha.1                                ...           7 years ago
  • 20.0.3                                ...           8 years ago
  • 20.0.2                                ...           8 years ago
  • 20.0.1                                ...           8 years ago
  • 20.0.0                                ...           8 years ago
  • 19.3.0-alpha.85402254                                ...           8 years ago
  • 19.2.0-alpha.993e64af                                ...           8 years ago
  • 19.1.0-alpha.eed82034                                ...           8 years ago
  • 0.0.0                                ...           8 years ago
Downloads
Today 0
This Week 0
This Month 25
Last Day 0
Last Week 25
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |