29.7.0 • Published 1 month ago

jest-docblock v29.7.0

Weekly downloads
11,302,702
License
MIT
Repository
github
Last release
1 month ago

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.

jest-runner@huyhpham/rn-linearchetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imagespecify-importsbabel-specify-imports@icanpm/api-masterreact-native-template-rfbaseairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdkgql_din_modjest-circus-allure-environment-custom-handlerbitget@olivervorasai/sliderreact-native-printer-brothers@ilya-matsuev/prettier-plugin-apexreact-native-shekhar-bridge-testwilscanner@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-testreact-native-slider-kfplginexpand-react-bridgeluminos-ui-coresklif-ui-kitsklif-api@everything-registry/sub-chunk-1955jawwy-sdkjawwy_gamification_release@314oner_npm/universal-components-libraryreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uireact-native-jawwy_samplelib-errorhexyun.helpershot-zone-vuekhaled-salem-custom-componentsgogency-test-2gogencygoogle-remakelancetyersemproj3iex-sdkiris-colorsjest-docblock-runnerjest-allure-circusjest-allure-prvjest-allure-runnerjest-circus-allure-environmentjest-circus-allure-playwright-environmentjest-circus-allure-reporterjest-runner-iansujordy-frijters-test-libmoonwalkerswap-default-token-listsnew-example-projectnka-gantt-task-reactnicholasbear_opensource_a1markdown-links-ymobtimer-api2microend-componentmpesa-cookiempesa-cookie-jarjulien-easy-modaljrennsoh88-react-native-scroll-indicatormy-prettiernative-date-picker-modulenative-modal-damage-vehiclenative-kakao-loginnative-google-loginnative-apple-loginmy-library-buttonmy-greeter-packagemy-calc-boxnew-awesome-4321mama-exportermap-values-resolverlrn_metrometro-test-buildmetro-pnpmmetro-eslintmetro-medmetro-bundlernotion-database-exporternpm_qwertynpm_one_12_34_1_npm_one_1_2_3npm_one_2_2npm-package-mentorcheckmath-operation-fun
30.0.0-alpha.3

1 month ago

30.0.0-alpha.2

4 months ago

30.0.0-alpha.1

5 months ago

30.0.0-alpha.0

5 months ago

29.7.0

7 months ago

29.6.3

7 months ago

29.4.2

1 year ago

29.4.3

1 year ago

29.2.0

1 year ago

29.0.0

2 years ago

28.1.1

2 years ago

29.0.0-alpha.2

2 years ago

29.0.0-alpha.3

2 years ago

29.0.0-alpha.0

2 years ago

28.0.0

2 years ago

28.0.2

2 years ago

28.0.0-alpha.6

2 years ago

28.0.0-alpha.3

2 years ago

27.5.0

2 years ago

27.5.1

2 years ago

28.0.0-alpha.0

2 years ago

27.4.0

2 years ago

27.0.6

3 years ago

27.0.1

3 years ago

27.0.0-next.10

3 years ago

27.0.0-next.0

3 years ago

26.0.0

4 years ago

26.0.0-alpha.0

4 years ago

25.3.0

4 years ago

25.2.6

4 years ago

25.2.1-alpha.2

4 years ago

25.2.3

4 years ago

25.2.1-alpha.1

4 years ago

25.2.0-alpha.86

4 years ago

25.2.0

4 years ago

25.1.0

4 years ago

25.0.0

5 years ago

24.9.0

5 years ago

24.3.0

5 years ago

24.2.0-alpha.0

5 years ago

24.2.0

5 years ago

24.0.0

5 years ago

24.0.0-alpha.16

5 years ago

24.0.0-alpha.15

5 years ago

24.0.0-alpha.13

5 years ago

24.0.0-alpha.12

5 years ago

24.0.0-alpha.11

5 years ago

24.0.0-alpha.10

5 years ago

24.0.0-alpha.9

5 years ago

24.0.0-alpha.7

5 years ago

24.0.0-alpha.6

5 years ago

24.0.0-alpha.5

5 years ago

24.0.0-alpha.4

5 years ago

24.0.0-alpha.2

5 years ago

24.0.0-alpha.1

5 years ago

24.0.0-alpha.0

5 years ago

23.2.0

6 years ago

23.0.1

6 years ago

22.4.3

6 years ago

22.4.0

6 years ago

22.2.2

6 years ago

22.2.0

6 years ago

22.1.0

6 years ago

22.0.6

6 years ago

22.0.3

6 years ago

22.0.2

6 years ago

22.0.1

6 years ago

22.0.0

6 years ago

21.3.0-beta.15

6 years ago

21.3.0-beta.14

6 years ago

21.3.0-beta.13

6 years ago

21.3.0-beta.12

6 years ago

21.3.0-beta.11

6 years ago

21.3.0-beta.10

6 years ago

21.3.0-beta.9

6 years ago

21.3.0-beta.8

6 years ago

21.3.0-beta.7

6 years ago

21.3.0-beta.6

6 years ago

21.3.0-beta.5

6 years ago

21.3.0-beta.4

6 years ago

21.3.0-beta.3

6 years ago

21.3.0-beta.2

6 years ago

21.3.0-beta.1

6 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

7 years ago

20.0.2

7 years ago

20.0.1

7 years ago

20.0.0

7 years ago

0.0.0

7 years ago