{"name":"@tapjs/stack","version":"0.0.0-5","description":"Utility for working with stack traces","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"imports":{"#require-resolve":{"import":"./dist/mjs/require-resolve-esm.js","require":"./dist/cjs/require-resolve.js"}},"license":"BlueOak-1.0.0","scripts":{"prepare":"tsc -p tsconfig/cjs.json && tsc -p tsconfig/esm.json && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"tap","snap":"tap","format":"prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"tap":{"coverage-map":"map.js"},"dependencies":{"tcompare":"6.0.1-4","trivial-deferred":"^2.0.0"},"engines":{"node":">=16"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/tapjs/tapjs.git"},"_id":"@tapjs/stack@0.0.0-5","readme":"# `@tapjs/stack`\n\nA comprehensive library for dealing with stack traces, supporting\nsource map lookup (when enabled in node with `--enable-source-maps`),\nfiltering of specified packages and/or Node.js internals, and\ncapturing call sites relative to a given function.\n\nThe spiritual descendant of\n[stack-utils](https://github.com/tapjs/stack-utils).\n\n## Class `CallSiteLike`\n\nThis is similar to the `CallSite` class in V8. However, rather\nthan provide methods to get all the relevant details about the\ncall site, it has them set as properties. Additionally, it may be\ngenerated by parsing a line from a string stack trace, which is\nuseful when tracking down the source of thrown errors.\n\nSee\n[the typedocs](https://tapjs.github.io/tapjs/classes/_tapjs_stack.call_site_like.CallSiteLike.html) for more information.\n\n## Class `CallSiteLikeJSON`\n\nThis is the \"plain old JavaScript object\" form of a\n`CallSiteLike` object, for use when serializing a `CallSiteLike`\nto YAML or JSON.\n\nIt contains all the same fields as `CallSiteLike`, but fields are\nunset rather than being set to `null` or `undefined` if they are\nnot relevant to the call site, to reduce noise when printing test\ndiagnostics.\n\nThe `toString()` value of CallSiteLike objects is a much terser\nrepresentation of the call site than the standard `Error.stack`\nstring, and it contains both the generated and origin call sites\nin the case of source mapped files.\n\nSee [the\ntypedocs](https://tapjs.github.io/tapjs/interfaces/_tapjs_stack.call_site_like.CallSiteLikeJSON.html)\nfor more information.\n\n## `at(fn?: Function): CallSiteLike | undefined`\n\nGet the call site in the stack either where `at()` is called, or\nwhere the supplied `fn` function is called.\n\nIf `fn` is provided, and is not in the current call stack, then\n`undefined` will be returned.\n\n## `capture(limit = 0, fn?: Function): CallSiteLike[]`\n\nGet an array of CallSiteLike objects for the current location,\nfrom the call to the `fn` argument if supplied, limited to the\nnumber of frames specified by `limit`.\n\nIf `fn` is supplied, and not in the current call stack, then an\nempty array will be returned.\n\nIf the `limit` argument is 0, then the current\n`Error.stackTraceLimit` value will be used.\n\nThis method is not re-entry safe, due to the fact that it relies\non temporarily overriding the global `Error.prepareStackTrace`.\nAs a result, if a capture() is triggered in any of the methods\nused by the `CallSiteLike` constructor (for example, if\n[`@tapjs/intercept`](https://tapjs.github.io/tapjs/modules/_tapjs_intercept.html)\nis used to capture the `process.cwd()` method, which is used by\n`path.resolve()`), then that will cause problems. To work around\nthis, if a re-entry is detected, then an empty stack of `[]` is\nreturned.\n\nEven if it was made re-entry safe, it would be easy to accidentally\ntrigger an infinite recursion and stack overflow in such a scenario, so\nreturning an empty stack in the case of re-entry is the best workaround.\n\n## `captureString(limit = 0, fn?: Function): string`\n\nThe same as `capture()`, but returns a string stack where each\nline is the `toString()` of the CallSiteLike object.\n\n## `captureError(er: Error): CallSiteLike[]`\n\nGet a stack of `CallSiteLike` objects by parsing the `stack`\nproperty of the supplied Error object.\n\nThis does _not_ actually look at the current call site, or do\nanything magical with the V8 engine. It's just parsing a string.\n\nWhile some effort is made to interpret stacks correctly when an\nError contains a `name` and `message`, remember that the\n`Error.stack` property in JavaScript is remarkably sloppy. In\nsome cases, if the `Error.message` contains `\\n` and some lines\nafter the first look like stack trace lines, incorrect data may\nresult. It's only as good as the stack you pass to it.\n\n## `captureErrorString(er: Error): string`\n\nThe same as `captureError` (with the same caveats) but presenting\nthe string stack where each line is the `toString()` value of the\nCallSiteLike object.\n\n## `parseStack(stack: string): CallSiteLike[]`\n\nTurn a string stack (either from `@tapjs/stack` or from a native\nError object) into an array of CallSiteLike objects.\n\nOnly useful in some niche situations, most of the time you're\nbetter off using `capture()` or `captureError()`.\n\n## `setCwd(cwd: string | undefined)`\n\nSet the current working directory used to shorten filename paths\nin CallSiteLike objects.\n\nDefault value is `process.cwd()`. Setting it to `undefined` will\ncause the CallSiteLike objects returned by the capture methods to\ndisplay full file paths.\n\n## `getCwd(): string | undefined`\n\nGet the current value of the effective cwd used by capture\nmethods.\n\n## `getFilterNodeInternals(): boolean`\n\nTells you whether or not node internals are being filtered out.\n\nDefaults to `true`\n\n## `setFilterNodeInternals(f: boolean)`\n\nSpecify whether node internals should be filtered out.\n\n## `getFilterIgnoredPackages(): boolean`\n\nTells you whether or not the set of ignored packages are being\nfiltered out.\n\nDefaults to `true`\n\n## `setFilterIgnoredPackages(f: boolean)`\n\nSpecify whether or not ignored packages should be filtered out.\n\n## `getIgnoredPackages(): string[]`\n\nGet the list of packages that are filtered out of captured stacks.\n\n## `addIgnoredPackage(pkg: string)`\n\nAdd a package to the filter set.\n\n## `removeIgnoredPackage(pkg: string)`\n\nRemove a package from the filter set.\n","readmeFilename":"README.md","gitHead":"e3de44331a26fc39bba46e5dfb8f5989d8ef5f20","bugs":{"url":"https://github.com/tapjs/tapjs/issues"},"homepage":"https://github.com/tapjs/tapjs#readme","_nodeVersion":"18.16.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-WtJMsejym2B+Kex3jt4gM8pSQZL9P+RVfwUI2ozEfzNinBDcSDQfRnPlvAHhCU+USJFnld8jtRlfhHjl+EQxwg==","shasum":"691a83f3f50d4e29b2fff991d435ca810298cde4","tarball":"http://registry-npm.ywwl.com/@tapjs/stack/download/@tapjs/stack-0.0.0-5.tgz","fileCount":37,"unpackedSize":209268,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHAiE4aJTWGVQfCKbB762qhY6oA9brko11whcqSkq63CAiBIMl7eYsXnK8OdM9/nsZWGmR7pFTXOW9YSV+Va0o9WmQ=="}],"size":31381,"noattachment":false,"key":"/@tapjs/stack/-/@tapjs/stack-0.0.0-5.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"ljharb","email":"ljharb@gmail.com"},{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stack_0.0.0-5_1693117020102_0.7036881059387241"},"_hasShrinkwrap":false,"publish_time":1693117020303,"_cnpm_publish_time":1693117020303,"dist-tags":{"latest":"4.3.3","pre":"1.0.0"}}