runtime-reporter 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +61 -51
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,8 +1,28 @@
1
1
  # Runtime Reporter
2
2
 
3
- Structured runtime reporting that is type-safe, centralized, and production-ready — for front-end frameworks and applications.
3
+ Replace ad-hoc logging with structured, code-based messaging.
4
4
 
5
- Runtime Reporter replaces ad-hoc logging with structured, code-based messaging.
5
+ Runtime Reporter provides centralized, type-safe reporting that is convenient in development and secure in production.
6
+
7
+ ```ts
8
+ // ./src/runtime-reporter.ts
9
+
10
+ import { createReporter } from "runtime-reporter";
11
+
12
+ export const reporter = createReporter({
13
+ ERR01: "Something went wrong",
14
+ });
15
+
16
+ // ./src/MyComponent.ts
17
+
18
+ import { reporter } from "./runtime-reporter";
19
+
20
+ export function MyComponent() {
21
+ useEffect(() => {
22
+ reporter.error("ERR01");
23
+ }, []);
24
+ }
25
+ ```
6
26
 
7
27
  ## Why?
8
28
 
@@ -20,7 +40,14 @@ by introducing these features:
20
40
  - test assertions without string duplication
21
41
  - safer production output (no sensitive data exposure)
22
42
 
23
- in a lightweight, self-contained package (less than 1 KB).
43
+ in a lightweight, self-contained package (less than 1 KB gzipped).
44
+
45
+ ## Who is this for?
46
+
47
+ - Front-end frameworks and libraries
48
+ - Projects that need stable error codes
49
+ - Teams replacing custom logging systems
50
+ - Projects that want safer production output
24
51
 
25
52
  ## Installation
26
53
 
@@ -30,11 +57,9 @@ npm install runtime-reporter
30
57
 
31
58
  ## Quick start
32
59
 
33
- A copy-and-paste example of how to use Runtime Reporter in your project.
60
+ A full, copy-and-paste example of how to use Runtime Reporter in your project:
34
61
 
35
62
  ```ts
36
- // src/runtime-reporter.ts
37
-
38
63
  import { createReporter, type RuntimeReporterMessages } from "runtime-reporter";
39
64
 
40
65
  const messages: RuntimeReporterMessages<
@@ -64,62 +89,57 @@ const reporter = createReporter(messages);
64
89
  export default reporter;
65
90
  ```
66
91
 
67
- Once your reporter is created, import and use it wherever you want:
92
+ ## Features
68
93
 
69
- ```ts
70
- // src/my-component.ts
94
+ If you are new to Runtime Reporter, take a moment to explore its core features.
71
95
 
72
- import { reporter } from "./runtime-reporter";
96
+ ### 1. Code-based messaging
73
97
 
74
- export function MyComponent() {
75
- useEffect(() => {
76
- reporter.error("ERR01", { componentName: "MyComponent" });
77
- }, []);
78
-
79
- return <div>My Component</div>;
80
- }
81
- ```
98
+ Replace inline strings with centralized, code-based identifiers.
82
99
 
83
- ## Features
100
+ ```ts
101
+ // Without runtime-reporter
102
+ console.log("Something went wrong");
103
+ // ❌ Logs: "Something went wrong"
84
104
 
85
- If you are new to Runtime Reporter, take a moment to explore its core features.
105
+ // With runtime-reporter
106
+ reporter.log("ERR01");
107
+ // ✅ Logs: "Something went wrong (ERR01)"
108
+ ```
86
109
 
87
- ### 1. Basic usage
110
+ ### 2. Dynamic messages
88
111
 
89
- Create a reporter instance with your messages and start logging.
112
+ Inject runtime data into your messages via message templates and tokenized variables.
90
113
 
91
114
  ```ts
92
- import { createReporter } from "runtime-reporter";
93
-
94
115
  const reporter = createReporter({
95
- ERR01: "MyComponent failed to mount",
116
+ ERR01: "{{ componentName }} failed to mount",
96
117
  });
97
118
 
98
- reporter.error("ERR01");
119
+ reporter.error("ERR01", { componentName: "MyComponent" });
120
+ // Logs: "MyComponent failed to mount (ERR01)"
99
121
  ```
100
122
 
101
- ### 2. Code-based messaging
123
+ ### 3. Development vs. production
102
124
 
103
- Replace inline strings with centralized, code-based identifiers.
125
+ Pass an empty object to the `createReporter` function in production environments for better security and a smaller bundle size.
104
126
 
105
127
  ```ts
106
- // Without runtime-reporter (logs "MyComponent failed to mount")
107
- console.error("MyComponent failed to mount");
108
-
109
- // With runtime-reporter (logs "MyComponent failed to mount (ERR01)")
110
- reporter.error("ERR01");
128
+ const reporter = createReporter(
129
+ process.env.NODE_ENV === "production" ? ({} as typeof messages) : messages
130
+ );
111
131
  ```
112
132
 
113
- ### 3. Dynamic messages
114
-
115
- Inject runtime data into your messages via message templates and tokenized variables.
133
+ Development environments get detailed messaging, while production environments get as little as possible.
116
134
 
117
135
  ```ts
118
- const reporter = createReporter({
119
- ERR01: "{{ componentName }} failed to mount",
120
- });
136
+ reporter.error("ERR01");
137
+ // In development, it logs: "Something went wrong (ERR01)"
138
+ // In production, it does not log
121
139
 
122
- reporter.error("ERR01", { componentName: "MyComponent" });
140
+ reporter.fail("ERR01");
141
+ // In development, it throws: "Something went wrong (ERR01)"
142
+ // In production, it throws: "An error occurred (ERR01)"
123
143
  ```
124
144
 
125
145
  ### 4. Type safety
@@ -147,17 +167,7 @@ reporter.error("ERR02", { componentName: "MyComponent" });
147
167
  reporter.error("ERR01");
148
168
  ```
149
169
 
150
- ### 5. Production environments
151
-
152
- Pass an empty object to the `createReporter` function in production environments for better security and a smaller bundle size.
153
-
154
- ```ts
155
- const reporter = createReporter(
156
- process.env.NODE_ENV === "production" ? ({} as typeof messages) : messages
157
- );
158
- ```
159
-
160
- ### 6. Test friendly
170
+ ### 5. Test friendly
161
171
 
162
172
  Assert against resolved messages without duplicating message text in your test environment.
163
173
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "runtime-reporter",
3
- "version": "0.4.5",
4
- "description": "Structured runtime reporting that is type-safe, centralized, and production-ready.",
3
+ "version": "0.4.7",
4
+ "description": "Replace ad-hoc logging with structured, code-based messaging",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",