29.7.0 • Published 6 months ago

jest-docblock v29.7.0

Weekly downloads
11,302,702
License
MIT
Repository
github
Last release
6 months 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-runnerjest-config@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_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uireact-native-jawwy_samplegriffin-ui-librarynebula-http-resiliencycomposizedd-trace-tstailwind-vector-effectsyncbackbasestest-library-123test-haptik-libwonder-jest-runnerwontbreakwebchewoven-challenge-deploywifi_configuration_packagern-tm-notifyrn-use-modal-hookrn-currency-formatterrn-counter-demorn-session-multiplier-demorn_unique_device_idrnttlocksanity-runner-servicereqioxresponsis-gantt-task-reactresponsive-react-appreactnativelyreactofy-css-libraryreikamoon-string-library-aarfp-librn-check-btnrocket-bundlerrn-adyen-dropinteapackage-tatespoorman297superset-plugin-chart-hello-world2supercluster-googlemaps-adapter-clonesstanikionespotify-ds-sestarfirestp-cdkrouter-loggerreact-native-wtfreact-native-version-appreact-native-withframework-checkserde_json_maintestapatest-zeo-collecttestnpm_lmnsvelte-component-libtext-based-game-enginevite-plugin-conventional-entriesvite-plugin-conventional-routesvpressifyvite-plugin-react18-pagesvite-plugin-react-pagesvision-camera-plugin-face-detectorvision-camera-plugin-scan-faces
30.0.0-alpha.6

6 months ago

30.0.0-alpha.5

8 months ago

30.0.0-alpha.4

9 months ago

30.0.0-alpha.3

11 months ago

30.0.0-alpha.2

1 year ago

30.0.0-alpha.1

1 year ago

30.0.0-alpha.0

1 year ago

29.7.0

1 year ago

29.6.3

1 year ago

29.4.2

2 years ago

29.4.3

2 years ago

29.2.0

2 years ago

29.0.0

2 years ago

28.1.1

3 years ago

29.0.0-alpha.2

2 years ago

29.0.0-alpha.3

2 years ago

29.0.0-alpha.0

3 years ago

28.0.0

3 years ago

28.0.2

3 years ago

28.0.0-alpha.6

3 years ago

28.0.0-alpha.3

3 years ago

27.5.0

3 years ago

27.5.1

3 years ago

28.0.0-alpha.0

3 years ago

27.4.0

3 years ago

27.0.6

4 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.1-alpha.2

5 years ago

25.2.3

5 years ago

25.2.1-alpha.1

5 years ago

25.2.0-alpha.86

5 years ago

25.2.0

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

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

7 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.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

8 years ago

20.1.0-delta.3

8 years ago

20.1.0-delta.2

8 years ago

20.1.0-delta.1

8 years ago

20.1.0-chi.1

8 years ago

20.1.0-beta.1

8 years ago

20.1.0-alpha.3

8 years ago

20.1.0-alpha.2

8 years ago

20.1.0-alpha.1

8 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

0.0.0

8 years ago