You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `@h3ravel/support` package provides convenient debugging helpers inspired by Laravel's debugging utilities. These helpers make it easy to inspect variables, objects, and data structures during development.
3
+
## Introduction
4
+
5
+
H3ravel provides convenient debugging helpers inspired by Laravel's debugging utilities via the `@h3ravel/support` package. These helpers make it easy to inspect variables, objects, and data structures during development, many of them are also used within the framework itself; however, you are free to use them in your own applications if you find them convenient.
6
+
7
+
To use these helpers in your application, you may install the `@h3ravel/support` package by running:
8
+
9
+
::: code-group
10
+
11
+
```sh [npm]
12
+
$ npm install @h3ravel/support --save
13
+
```
14
+
15
+
```sh [yarn]
16
+
$ yarn add @h3ravel/support
17
+
```
18
+
19
+
```sh [pnpm]
20
+
$ pnpm add @h3ravel/support
21
+
```
22
+
23
+
```sh [bun]
24
+
$ bun create @h3ravel/support
25
+
```
26
+
27
+
:::
28
+
29
+
The `@h3ravel/support` is installed by default when using H3ravel
4
30
5
31
## Available Helpers
6
32
7
33
-[`dump()`](#dump) - Output values and continue execution
8
34
-[`dd()`](#dd) - Output values and terminate execution
9
35
10
-
---
11
-
12
36
## `dump()`
13
37
14
38
Dumps one or more values to the console with detailed inspection and continues program execution. This is useful when you want to inspect values without stopping your application.
// Outputs the user object and continues execution
53
-
console.log('Program continues...')
77
+
console.log('Program continues...');
54
78
```
55
79
56
80
#### Dumping Multiple Values
57
81
58
82
```typescript
59
-
import { dump } from'@h3ravel/support'
83
+
import { dump } from'@h3ravel/support';
60
84
61
-
const name ='Alice'
62
-
const age =25
63
-
const hobbies = ['reading', 'coding', 'gaming']
85
+
const name ='Alice';
86
+
const age =25;
87
+
const hobbies = ['reading', 'coding', 'gaming'];
64
88
65
-
dump(name, age, hobbies)
89
+
dump(name, age, hobbies);
66
90
// Outputs all three values in order
67
91
```
68
92
69
93
#### Debugging in Functions
70
94
71
95
```typescript
72
-
import { dump } from'@h3ravel/support'
96
+
import { dump } from'@h3ravel/support';
73
97
74
98
function processOrder(order:any) {
75
-
dump(order) // Inspect the order
76
-
99
+
dump(order);// Inspect the order
100
+
77
101
// Continue processing...
78
-
const total =order.items.reduce((sum, item) =>sum+item.price, 0)
79
-
80
-
dump(total) // Inspect the calculated total
81
-
82
-
returntotal
102
+
const total =order.items.reduce((sum, item) =>sum+item.price, 0);
103
+
104
+
dump(total);// Inspect the calculated total
105
+
106
+
returntotal;
83
107
}
84
108
```
85
109
86
110
#### Inspecting Complex Objects
87
111
88
112
```typescript
89
-
import { dump } from'@h3ravel/support'
113
+
import { dump } from'@h3ravel/support';
90
114
91
115
const complexData = {
92
116
user: {
93
117
profile: {
94
118
settings: {
95
119
theme: 'dark',
96
-
notifications: true
97
-
}
98
-
}
120
+
notifications: true,
121
+
},
122
+
},
99
123
},
100
124
metadata: newMap([['key1', 'value1']]),
101
-
created: newDate()
102
-
}
125
+
created: newDate(),
126
+
};
103
127
104
-
dump(complexData)
128
+
dump(complexData);
105
129
// Shows complete nested structure with all details
106
130
```
107
131
108
-
---
109
-
110
132
## `dd()`
111
133
112
134
Dumps one or more values to the console with detailed inspection and then **terminates the program**. This is Laravel's famous "Dump and Die" function, perfect for debugging when you want to inspect a value and stop execution immediately.
@@ -138,102 +160,99 @@ dd(...args: unknown[]): never
0 commit comments