Skip to content

Commit 61cfd33

Browse files
authored
docs: update readme (#102)
issues: * docs: update readme (#100) commits: * docs: update readme (999937c)
1 parent b3eb88f commit 61cfd33

File tree

2 files changed

+53
-41
lines changed

2 files changed

+53
-41
lines changed

README.md

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# @mnrendra/stack-trace
22

3-
![version](https://img.shields.io/npm/v/@mnrendra/stack-trace)
4-
![types](https://img.shields.io/npm/types/@mnrendra/stack-trace)
5-
![size](https://img.shields.io/npm/unpacked-size/@mnrendra/stack-trace)
6-
![downloads](https://img.shields.io/npm/dm/@mnrendra/stack-trace)
7-
![license](https://img.shields.io/npm/l/@mnrendra/stack-trace)
3+
[![version](https://img.shields.io/npm/v/@mnrendra/stack-trace?logo=nodedotjs)](https://www.npmjs.com/package/@mnrendra/stack-trace?activeTab=versions)
4+
[![downloads](https://img.shields.io/npm/dm/@mnrendra/stack-trace)](https://npm-stat.com/charts.html?package=@mnrendra/stack-trace)
5+
[![size](https://packagephobia.now.sh/badge?p=@mnrendra/stack-trace)](https://packagephobia.com/result?p=%40mnrendra%2Fstack-trace)
6+
[![coverage](https://codecov.io/github/mnrendra/stack-trace/graph/badge.svg?token=LSNMMJVQ77)](https://app.codecov.io/gh/mnrendra/stack-trace)
7+
[![release](https://github.com/mnrendra/stack-trace/actions/workflows/release.yml/badge.svg)](https://github.com/mnrendra/stack-trace/actions/workflows/release.yml)
8+
[![semantic](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/mnrendra/stack-trace/commits/main)
9+
[![license](https://img.shields.io/npm/l/@mnrendra/stack-trace)](https://github.com/mnrendra/stack-trace/blob/main/LICENSE)
10+
11+
A lightweight [stack trace](https://v8.dev/docs/stack-trace-api) utility to retrieve `CallSite` objects from a specific caller.
812

9-
A lightweight [stack trace](https://v8.dev/docs/stack-trace-api) utility to retrieve `CallSite` objects from a specific caller.<br/>
1013
*Useful for debugging, logging, or building tools that need to trace call origins at runtime.*
1114

15+
## Features
16+
- ✅ Supports both **ES Modules** and **CommonJS** from a single source - see [package](https://www.npmjs.com/package/@mnrendra/stack-trace?activeTab=code)
17+
- ✅ Minified and cleansed of unnecessary dependencies, files, and attributes - see [contents](https://www.npmjs.com/package/@mnrendra/stack-trace?activeTab=code)
18+
- ✅ Tiny package - see [size](https://bundlephobia.com/package/@mnrendra/stack-trace)
19+
- ✅ Well tested - see [coverage](https://app.codecov.io/gh/mnrendra/stack-trace)
20+
- ✅ Verified all commits - see [signatures](https://github.com/mnrendra/stack-trace/commits/main)
21+
- ✅ Semantic versioning - see [commits](https://github.com/mnrendra/stack-trace/commits/main)
22+
- ✅ Actively maintained - [pull requests](https://github.com/mnrendra/stack-trace/pulls), [issues](https://github.com/mnrendra/stack-trace/issues), and [discussions](https://github.com/mnrendra/stack-trace/discussions) are welcome!
23+
1224
## Install
1325
```bash
1426
npm i @mnrendra/stack-trace
@@ -129,26 +141,26 @@ If the extracted file name is not a string or not absolute.
129141

130142
## Usage
131143

132-
### CommonJS
133-
`/foo/callee.cjs`
144+
### ES Modules
145+
`/foo/callee.mjs`
134146
```javascript
135-
const { dirname } = require('node:path')
147+
import { dirname } from 'node:path'
136148

137-
const {
149+
import {
138150
stackTrace,
139151
getCallerSite,
140152
extractFilePath,
141153
getCallerFile,
142154
getCallerDir
143-
} = require('@mnrendra/stack-trace')
155+
} from '@mnrendra/stack-trace'
144156

145157
const callee = () => {
146158
// `stackTrace`:
147159
const [callSite1] = stackTrace()
148160
const [callSite2] = stackTrace(callee, { limit: 1 }) // Pass the `callee` function as the callee.
149161

150-
console.log(callSite1.getFileName()) // Output: /foo/callee.cjs
151-
console.log(callSite2.getFileName()) // Output: /foo/caller.cjs
162+
console.log(callSite1.getFileName()) // Output: file:///foo/callee.mjs
163+
console.log(callSite2.getFileName()) // Output: file:///foo/caller.mjs
152164

153165
console.log(callSite1.getFunctionName()) // Output: callee
154166
console.log(callSite2.getFunctionName()) // Output: caller
@@ -160,8 +172,8 @@ const callee = () => {
160172
console.log(callerSite1.getFileName() === callSite1.getFileName()) // Output: true
161173
console.log(callerSite2.getFileName() === callSite2.getFileName()) // Output: true
162174

163-
console.log(callerSite1.getFileName()) // Output: /foo/callee.cjs
164-
console.log(callerSite2.getFileName()) // Output: /foo/caller.cjs
175+
console.log(callerSite1.getFileName()) // Output: file:///foo/callee.mjs
176+
console.log(callerSite2.getFileName()) // Output: file:///foo/caller.mjs
165177

166178
console.log(callerSite1.getFunctionName() === callSite1.getFunctionName()) // Output: true
167179
console.log(callerSite2.getFunctionName() === callSite2.getFunctionName()) // Output: true
@@ -173,8 +185,8 @@ const callee = () => {
173185
const filePath1 = extractFilePath(callerSite1)
174186
const filePath2 = extractFilePath(callerSite2)
175187

176-
console.log(filePath1) // Output: /foo/callee.cjs
177-
console.log(filePath2) // Output: /foo/caller.cjs
188+
console.log(filePath1) // Output: /foo/callee.mjs
189+
console.log(filePath2) // Output: /foo/caller.mjs
178190

179191
// `getCallerFile`:
180192
const callerFile1 = getCallerFile()
@@ -183,8 +195,8 @@ const callee = () => {
183195
console.log(callerFile1 === filePath1) // Output: true
184196
console.log(callerFile2 === filePath2) // Output: true
185197

186-
console.log(callerFile1) // Output: /foo/callee.cjs
187-
console.log(callerFile2) // Output: /foo/caller.cjs
198+
console.log(callerFile1) // Output: /foo/callee.mjs
199+
console.log(callerFile2) // Output: /foo/caller.mjs
188200

189201
// `getCallerDir`:
190202
const callerDir1 = getCallerDir()
@@ -197,36 +209,36 @@ const callee = () => {
197209
console.log(callerDir2) // Output: /foo
198210
}
199211

200-
module.exports = callee
212+
export default callee
201213
```
202214

203-
`/foo/caller.cjs`
215+
`/foo/caller.mjs`
204216
```javascript
205-
const callee = require('./callee.cjs')
217+
import callee from './callee.mjs'
206218
const caller = () => callee()
207219
caller()
208220
```
209221

210-
### ES Modules
211-
`/foo/callee.mjs`
222+
### CommonJS
223+
`/foo/callee.cjs`
212224
```javascript
213-
import { dirname } from 'node:path'
225+
const { dirname } = require('node:path')
214226

215-
import {
227+
const {
216228
stackTrace,
217229
getCallerSite,
218230
extractFilePath,
219231
getCallerFile,
220232
getCallerDir
221-
} from '@mnrendra/stack-trace'
233+
} = require('@mnrendra/stack-trace')
222234

223235
const callee = () => {
224236
// `stackTrace`:
225237
const [callSite1] = stackTrace()
226238
const [callSite2] = stackTrace(callee, { limit: 1 }) // Pass the `callee` function as the callee.
227239

228-
console.log(callSite1.getFileName()) // Output: file:///foo/callee.mjs
229-
console.log(callSite2.getFileName()) // Output: file:///foo/caller.mjs
240+
console.log(callSite1.getFileName()) // Output: /foo/callee.cjs
241+
console.log(callSite2.getFileName()) // Output: /foo/caller.cjs
230242

231243
console.log(callSite1.getFunctionName()) // Output: callee
232244
console.log(callSite2.getFunctionName()) // Output: caller
@@ -238,8 +250,8 @@ const callee = () => {
238250
console.log(callerSite1.getFileName() === callSite1.getFileName()) // Output: true
239251
console.log(callerSite2.getFileName() === callSite2.getFileName()) // Output: true
240252

241-
console.log(callerSite1.getFileName()) // Output: file:///foo/callee.mjs
242-
console.log(callerSite2.getFileName()) // Output: file:///foo/caller.mjs
253+
console.log(callerSite1.getFileName()) // Output: /foo/callee.cjs
254+
console.log(callerSite2.getFileName()) // Output: /foo/caller.cjs
243255

244256
console.log(callerSite1.getFunctionName() === callSite1.getFunctionName()) // Output: true
245257
console.log(callerSite2.getFunctionName() === callSite2.getFunctionName()) // Output: true
@@ -251,8 +263,8 @@ const callee = () => {
251263
const filePath1 = extractFilePath(callerSite1)
252264
const filePath2 = extractFilePath(callerSite2)
253265

254-
console.log(filePath1) // Output: /foo/callee.mjs
255-
console.log(filePath2) // Output: /foo/caller.mjs
266+
console.log(filePath1) // Output: /foo/callee.cjs
267+
console.log(filePath2) // Output: /foo/caller.cjs
256268

257269
// `getCallerFile`:
258270
const callerFile1 = getCallerFile()
@@ -261,8 +273,8 @@ const callee = () => {
261273
console.log(callerFile1 === filePath1) // Output: true
262274
console.log(callerFile2 === filePath2) // Output: true
263275

264-
console.log(callerFile1) // Output: /foo/callee.mjs
265-
console.log(callerFile2) // Output: /foo/caller.mjs
276+
console.log(callerFile1) // Output: /foo/callee.cjs
277+
console.log(callerFile2) // Output: /foo/caller.cjs
266278

267279
// `getCallerDir`:
268280
const callerDir1 = getCallerDir()
@@ -275,12 +287,12 @@ const callee = () => {
275287
console.log(callerDir2) // Output: /foo
276288
}
277289

278-
export default callee
290+
module.exports = callee
279291
```
280292

281-
`/foo/caller.mjs`
293+
`/foo/caller.cjs`
282294
```javascript
283-
import callee from './callee.mjs'
295+
const callee = require('./callee.cjs')
284296
const caller = () => callee()
285297
caller()
286298
```

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)