Skip to content

Commit

Permalink
hotfix: v1.2.1 (#36)
Browse files Browse the repository at this point in the history
issues:
* hotfix: v1.2.1 (#33)

commits:
* fix: readme (#35) (3d2ae98)
  • Loading branch information
gitops-merge authored Jul 3, 2024
2 parents 83650d0 + 3d2ae98 commit 0de189d
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,52 @@ console.log(trace.getFileName()); // Output: /foo/project-name/node_modules/modu
Note: When calling `getFileName` from an <b>ESM</b> module, it will return the file name as a <b>URL</b> instead of a file path.
## Options
3. Implement `options` and `validateSkippedStacks`:
```javascript
import type { stackTrace } from '@mnrendra/stack-trace'
import {
stackTrace,
// from `@mnrendra/validate-skipped-stacks`:
validateSkippedStacks
} from '@mnrendra/stack-trace'

stackTrace(
const stacks = stackTrace(
null, // Or any target function to be invoked.
{
limit: 10 // The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace.
}
)

const SKIPPED_STACK = 'your-module-name' // Example, you want to skip your module stack and trace your consumer stacks.

const paths = stacks.map((stack) =>
typeof stack.getFileName() === 'string' && stack.getFileName() !== ''
? stack.getFileName()
: SKIPPED_STACK
)

const validSkippedStacks = validateSkippedStacks(
SKIPPED_STACK,
['other-stack'] // Or you can also pass it as an optional skipped stack from your consumer.
)

// Find the initial path.
const path = paths.find((path) => !(
validSkippedStacks.some((skippedStack) =>
typeof path === 'string' && path !== '' && path.includes(skippedStack)
)
))

console.log(path)
```
## Types
```typescript
import {
import type {
CallSite, // NodeJS.CallSite
StackTrace, // (targetFunction?: TargetFunction, options?: Options) => CallSite[]
TargetFunction, // (...args: any[]) => any | Promise<TargetFunction>
Options, // { limit?: number }
// from `@mnrendra/validate-skipped-stacks`
// from `@mnrendra/validate-skipped-stacks`:
SkippedStacks,
ValidSkippedStacks
} from '@mnrendra/stack-trace'
Expand Down

0 comments on commit 0de189d

Please sign in to comment.