提交学习笔记专用
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.

40 lines
1.4 KiB

  1. # error-stack-parser-es
  2. [![NPM version](https://img.shields.io/npm/v/error-stack-parser-es?color=a1b858&label=)](https://www.npmjs.com/package/error-stack-parser-es)
  3. A port of [stacktracejs/error-stack-parser](https://github.com/stacktracejs/error-stack-parser), rewrite with TypeScript and ES Modules.
  4. ## Usage
  5. ```ts
  6. import { parse } from 'error-stack-parser-es'
  7. const stacktrace = parse(new Error('BOOM!'))
  8. ```
  9. Refer to [stacktracejs/error-stack-parser](https://github.com/stacktracejs/error-stack-parser) for more details.
  10. ### Lite API
  11. Additionally, this fork added a lite version of the API representation for the stack frames. You can import it from `error-stack-parser-es/lite`. For example, `line` and `col` instead of `lineNumber` and `columnNumber`.
  12. ```ts
  13. import { parse } from 'error-stack-parser-es/lite'
  14. const stacktrace = parse(new Error('BOOM!'))
  15. // [{ file: 'file.js', name: 'method', line: 1, col: 2}]
  16. ```
  17. It also allows you to parse directly from a stacktrace string (which does not support Opera stacktrace format).
  18. ```ts
  19. import { parseStack } from 'error-stack-parser-es/lite'
  20. const stacktrace = parseStack('Error\n at method (file.js:1:2)')
  21. // [{ file: 'file.js', name: 'method', line: 1, col: 2}]
  22. ```
  23. ## License
  24. [MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu)
  25. [MIT](./LICENSE) License © 2017 [Eric Wendelin](https://github.com/eriwen)