Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # jest-docblock
  2. `jest-docblock` is a package that can extract and parse a specially-formatted comment called a "docblock" at the top of a file.
  3. A docblock looks like this:
  4. ```js
  5. /**
  6. * Stuff goes here!
  7. */
  8. ```
  9. Docblocks can contain pragmas, which are words prefixed by `@`:
  10. ```js
  11. /**
  12. * Pragma incoming!
  13. *
  14. * @flow
  15. */
  16. ```
  17. Pragmas can also take arguments:
  18. ```js
  19. /**
  20. * Check this out:
  21. *
  22. * @myPragma it is so cool
  23. */
  24. ```
  25. `jest-docblock` can:
  26. - extract the docblock from some code as a string
  27. - parse a docblock string's pragmas into an object
  28. - print an object and some comments back to a string
  29. ## Installation
  30. ```sh
  31. # with yarn
  32. $ yarn add jest-docblock
  33. # with npm
  34. $ npm install jest-docblock
  35. ```
  36. ## Usage
  37. ```js
  38. const code = `
  39. /**
  40. * Everything is awesome!
  41. *
  42. * @everything is:awesome
  43. * @flow
  44. */
  45. export const everything = Object.create(null);
  46. export default function isAwesome(something) {
  47. return something === everything;
  48. }
  49. `;
  50. const {
  51. extract,
  52. strip,
  53. parse,
  54. parseWithComments,
  55. print,
  56. } = require('jest-docblock');
  57. const docblock = extract(code);
  58. console.log(docblock); // "/**\n * Everything is awesome!\n * \n * @everything is:awesome\n * @flow\n */"
  59. const stripped = strip(code);
  60. console.log(stripped); // "export const everything = Object.create(null);\n export default function isAwesome(something) {\n return something === everything;\n }"
  61. const pragmas = parse(docblock);
  62. console.log(pragmas); // { everything: "is:awesome", flow: "" }
  63. const parsed = parseWithComments(docblock);
  64. console.log(parsed); // { comments: "Everything is awesome!", pragmas: { everything: "is:awesome", flow: "" } }
  65. console.log(print({pragmas, comments: 'hi!'})); // /**\n * hi!\n *\n * @everything is:awesome\n * @flow\n */;
  66. ```
  67. ## API Documentation
  68. ### `extract(contents: string): string`
  69. 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 (`""`).
  70. ### `strip(contents: string): string`
  71. 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.
  72. ### `parse(docblock: string): {[key: string]: string | string[] }`
  73. 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.
  74. ### `parseWithComments(docblock: string): { comments: string, pragmas: {[key: string]: string | string[]} }`
  75. Similar to `parse` except this method also returns the comments from the docblock. Useful when used with `print()`.
  76. ### `print({ comments?: string, pragmas?: {[key: string]: string | string[]} }): string`
  77. 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.