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.

60 lines
1.0 KiB

4 years ago
  1. # babel-code-frame
  2. > Generate errors that contain a code frame that point to source locations.
  3. ## Install
  4. ```sh
  5. npm install --save-dev babel-code-frame
  6. ```
  7. ## Usage
  8. ```js
  9. import codeFrame from 'babel-code-frame';
  10. const rawLines = `class Foo {
  11. constructor()
  12. }`;
  13. const lineNumber = 2;
  14. const colNumber = 16;
  15. const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ });
  16. console.log(result);
  17. ```
  18. ```sh
  19. 1 | class Foo {
  20. > 2 | constructor()
  21. | ^
  22. 3 | }
  23. ```
  24. If the column number is not known, you may pass `null` instead.
  25. ## Options
  26. ### `highlightCode`
  27. `boolean`, defaults to `false`.
  28. Toggles syntax highlighting the code as JavaScript for terminals.
  29. ### `linesAbove`
  30. `number`, defaults to `2`.
  31. Adjust the number of lines to show above the error.
  32. ### `linesBelow`
  33. `number`, defaults to `3`.
  34. Adjust the number of lines to show below the error.
  35. ### `forceColor`
  36. `boolean`, defaults to `false`.
  37. Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.