Skip to content

Commit 5005e08

Browse files
committed
feat(stackz): add complete stack trace formatting library 🎉
- add stack trace formatting with compact and detailed modes - configure dual publishing to npm and JSR registries - create complete TypeScript type definitions and interfaces - create detailed documentation with usage examples and demo - implement cross-runtime support for Deno, Node.js, Bun, and browsers - implement error parsing for TypeError, ReferenceError, and custom errors - include extensive test suite with 100% coverage - setup automated CI/CD pipelines with GitHub Actions - setup project build configuration with unbuild and Deno support
0 parents  commit 5005e08

File tree

17 files changed

+3412
-0
lines changed

17 files changed

+3412
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-check:
11+
name: Build Check
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [22.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Build project
31+
run: npm run build

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deno Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: denoland/setup-deno@v2
18+
with:
19+
deno-version: v2.5.4
20+
21+
- name: Check package
22+
run: deno check src/index.ts
23+
24+
- name: Run unit tests
25+
run: deno test --no-check
26+
27+
- name: Publish package
28+
run: deno publish --allow-dirty

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Deno
2+
.deno/
3+
coverage/
4+
deno.lock
5+
6+
# IDE
7+
.vscode/
8+
.idea/
9+
10+
# OS
11+
.DS_Store
12+
Thumbs.db
13+
14+
# Node
15+
dist/
16+
node_modules/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 NeaByteLab
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Stackz [![Module type: CJS+ESM](https://img.shields.io/badge/module%20type-cjs%2Besm-brightgreen)](https://github.com/NeaByteLab/Stackz) [![npm version](https://img.shields.io/npm/v/@neabyte/stackz.svg)](https://www.npmjs.org/package/@neabyte/stackz) [![JSR](https://jsr.io/badges/@neabyte/stackz)](https://jsr.io/@neabyte/stackz) [![Node.js CI](https://github.com/NeaByteLab/Stackz/actions/workflows/ci.yaml/badge.svg)](https://github.com/NeaByteLab/Stackz)
2+
3+
Beautiful stack trace formatter with source code context for JavaScript.
4+
5+
![Demo](./assets/demo.png)
6+
7+
## Features
8+
9+
- **Cross-runtime support** - Works in Deno, Node.js, Bun, and browsers
10+
- **Source code context** - Shows actual code around error locations (detailed mode)
11+
- **Two formatting styles** - Compact and detailed stack traces
12+
- **ANSI colors** - Beautiful terminal output with syntax highlighting
13+
14+
## Installation
15+
16+
Choose your preferred package manager:
17+
18+
```bash
19+
# npm package
20+
npm install @neabyte/stackz
21+
22+
# Deno module
23+
deno add jsr:@neabyte/stackz
24+
```
25+
26+
## Usage
27+
28+
```typescript
29+
import Stackz from '@neabyte/stackz'
30+
31+
try {
32+
// Your code that might throw
33+
throw new Error('Something went wrong')
34+
} catch (error) {
35+
// Compact format without source context
36+
console.log(Stackz.format(error, 'compact'))
37+
// Detailed format with source context
38+
console.log(await Stackz.format(error, 'detailed'))
39+
}
40+
```
41+
42+
## Formats
43+
44+
### Compact
45+
46+
```
47+
TypeError Cannot read properties of undefined (reading 'property')
48+
→ createTypeError @ index.ts:5:14
49+
→ index.ts:15:3
50+
```
51+
52+
### Detailed
53+
54+
```
55+
TypeError Cannot read properties of undefined (reading 'property')
56+
57+
Path: /path/to/project/index.ts:5:14
58+
2 |
59+
3 | function createTypeError() {
60+
4 | const obj = undefined as any
61+
5 return obj.property // This will create TypeError with real stack
62+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
6 | }
64+
65+
Call Stack:
66+
• createTypeError → index.ts:5:14
67+
• anonymous → index.ts:15:3
68+
```
69+
70+
## License
71+
72+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.

assets/demo.png

184 KB
Loading

build.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
import { resolve } from 'node:path'
3+
4+
export default defineBuildConfig({
5+
entries: ['src/index'],
6+
declaration: true,
7+
clean: true,
8+
alias: {
9+
'@app': resolve(__dirname, 'src')
10+
},
11+
rollup: {
12+
emitCJS: true,
13+
inlineDependencies: true
14+
},
15+
sourcemap: false,
16+
failOnWarn: false
17+
})

deno.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"name": "@neabyte/stackz",
3+
"description": "Beautiful stack trace formatter with source code context for JavaScript",
4+
"version": "0.1.0",
5+
"type": "module",
6+
"license": "MIT",
7+
"exports": "./src/index.ts",
8+
"compilerOptions": {
9+
"allowUnreachableCode": false,
10+
"allowUnusedLabels": false,
11+
"checkJs": false,
12+
"exactOptionalPropertyTypes": true,
13+
"jsx": "react",
14+
"lib": ["deno.ns", "dom", "esnext"],
15+
"noErrorTruncation": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"noImplicitAny": true,
18+
"noImplicitOverride": true,
19+
"noImplicitReturns": true,
20+
"noImplicitThis": true,
21+
"noPropertyAccessFromIndexSignature": true,
22+
"noUncheckedIndexedAccess": true,
23+
"noUnusedLocals": true,
24+
"noUnusedParameters": true,
25+
"strict": true,
26+
"strictBindCallApply": true,
27+
"strictFunctionTypes": true,
28+
"strictNullChecks": true,
29+
"strictPropertyInitialization": true,
30+
"useUnknownInCatchVariables": true
31+
},
32+
"fmt": {
33+
"bracePosition": "sameLine",
34+
"indentWidth": 2,
35+
"lineWidth": 100,
36+
"proseWrap": "preserve",
37+
"semiColons": false,
38+
"singleBodyPosition": "nextLine",
39+
"singleQuote": true,
40+
"spaceAround": false,
41+
"spaceSurroundingProperties": true,
42+
"trailingCommas": "never",
43+
"useBraces": "always",
44+
"useTabs": false
45+
},
46+
"lint": {
47+
"include": ["src/"],
48+
"rules": {
49+
"tags": ["fresh", "jsr", "jsx", "react", "recommended", "workspace"],
50+
"include": [
51+
"ban-untagged-todo",
52+
"camelcase",
53+
"default-param-last",
54+
"eqeqeq",
55+
"explicit-function-return-type",
56+
"explicit-module-boundary-types",
57+
"guard-for-in",
58+
"no-await-in-loop",
59+
"no-boolean-literal-for-arguments",
60+
"no-const-assign",
61+
"no-eval",
62+
"no-implicit-declare-namespace-export",
63+
"no-inferrable-types",
64+
"no-invalid-triple-slash-reference",
65+
"no-non-null-asserted-optional-chain",
66+
"no-non-null-assertion",
67+
"no-self-compare",
68+
"no-sparse-arrays",
69+
"no-sync-fn-in-async-fn",
70+
"no-throw-literal",
71+
"no-undef",
72+
"no-useless-rename",
73+
"no-top-level-await",
74+
"single-var-declarator"
75+
],
76+
"exclude": ["no-console", "no-external-import", "prefer-ascii", "prefer-primordials"]
77+
}
78+
},
79+
"lock": true,
80+
"nodeModulesDir": "none",
81+
"test": {
82+
"include": ["tests/**/*.ts"],
83+
"exclude": ["tests/**/*.d.ts"]
84+
},
85+
"tasks": {
86+
"check": "deno fmt src/ && deno lint src/ && deno check src/",
87+
"test": "deno fmt tests/ && deno lint tests/ && deno test --no-check"
88+
},
89+
"imports": {
90+
"@std/assert": "jsr:@std/assert@^1.0.15",
91+
"@app/": "./src/",
92+
"@tests/": "./tests/"
93+
},
94+
"publish": {
95+
"exclude": [
96+
"*.bench.ts",
97+
"*.spec.ts",
98+
"*.test.ts",
99+
".github/",
100+
"bench/",
101+
"build.config.ts",
102+
"coverage/",
103+
"dist/",
104+
"package-lock.json",
105+
"package.json",
106+
"tests/"
107+
]
108+
}
109+
}

0 commit comments

Comments
 (0)