getbox 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +262 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +24 -0
- package/coverage/coverage-final.json +2 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +116 -0
- package/coverage/index.ts.html +280 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Eric Afes
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# getbox
|
|
2
|
+
|
|
3
|
+
### Lightweight dependency injection for TypeScript.
|
|
4
|
+
|
|
5
|
+
getbox provides a simple way of managing dependencies in TypeScript applications. It uses classes and factory functions to define dependencies and automatically handles instance caching.
|
|
6
|
+
|
|
7
|
+
The main advantage of `getbox` is removing the need to manually pass references around when instantiating classes that depend on one another.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install getbox
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
`getbox` has a very small API surface. You typically only need to use the `Box.get()` and optionally static init methods or the `factory` helper.
|
|
18
|
+
|
|
19
|
+
### Create a class
|
|
20
|
+
|
|
21
|
+
Classes are instantiated once and cached. Subsequent calls return the cached instance.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// printer.ts
|
|
25
|
+
import { Box } from "getbox";
|
|
26
|
+
|
|
27
|
+
export class Printer {
|
|
28
|
+
print(text: string): string {
|
|
29
|
+
return text.toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Use in another class
|
|
35
|
+
|
|
36
|
+
Retrieve instances by calling `box.get(Constructor)` within your class constructor or factory function.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// office.ts
|
|
40
|
+
import { Box, factory } from "getbox";
|
|
41
|
+
import { Printer } from "./printer";
|
|
42
|
+
|
|
43
|
+
export class Office {
|
|
44
|
+
constructor(public printer: Printer) {}
|
|
45
|
+
|
|
46
|
+
static init(box: Box) {
|
|
47
|
+
const printer = box.get(Printer);
|
|
48
|
+
return new Office(printer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Use in application
|
|
54
|
+
|
|
55
|
+
Create a Box instance to hold cached instances.
|
|
56
|
+
|
|
57
|
+
When initializing a class, any dependencies it has will also be cached, ensuring that shared dependencies use the same instance.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// main.ts
|
|
61
|
+
import { Box } from "getbox";
|
|
62
|
+
import { Office } from "./office";
|
|
63
|
+
import { Printer } from "./printer";
|
|
64
|
+
|
|
65
|
+
const box = new Box();
|
|
66
|
+
|
|
67
|
+
const office = box.get(Office);
|
|
68
|
+
office.printer.print("hello world");
|
|
69
|
+
|
|
70
|
+
// Instances are cached and shared
|
|
71
|
+
const printer = box.get(Printer);
|
|
72
|
+
console.log(office.printer === printer); // true
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Transient instances
|
|
76
|
+
|
|
77
|
+
Use `box.new()` to create a new instance each time without caching. This is useful for instances that should not be shared.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// printer.ts
|
|
81
|
+
import { Box } from "getbox";
|
|
82
|
+
|
|
83
|
+
export class Printer {
|
|
84
|
+
id = Math.random();
|
|
85
|
+
|
|
86
|
+
print(text: string): string {
|
|
87
|
+
return text.toUpperCase();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// main.ts
|
|
94
|
+
import { Box } from "getbox";
|
|
95
|
+
import { Printer } from "./printer";
|
|
96
|
+
|
|
97
|
+
const box = new Box();
|
|
98
|
+
|
|
99
|
+
const printer1 = box.new(Printer);
|
|
100
|
+
const printer2 = box.new(Printer);
|
|
101
|
+
|
|
102
|
+
console.log(printer1 === printer2); // false
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Factory functions
|
|
106
|
+
|
|
107
|
+
Use the `factory` helper to create function-based constructors instead of classes. Factories work well with interfaces for better abstraction.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// logger.ts
|
|
111
|
+
import { Box, factory } from "getbox";
|
|
112
|
+
|
|
113
|
+
export interface Logger {
|
|
114
|
+
log(message: string): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class ConsoleLogger implements Logger {
|
|
118
|
+
log(message: string): void {
|
|
119
|
+
console.log(`[LOG] ${message}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const LoggerFactory = factory((box: Box): Logger => {
|
|
124
|
+
return new ConsoleLogger();
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// service.ts
|
|
130
|
+
import { Box } from "getbox";
|
|
131
|
+
import { Logger, LoggerFactory } from "./logger";
|
|
132
|
+
|
|
133
|
+
export class UserService {
|
|
134
|
+
constructor(private logger: Logger) {}
|
|
135
|
+
|
|
136
|
+
static init(box: Box) {
|
|
137
|
+
const logger = box.get(LoggerFactory);
|
|
138
|
+
return new UserService(logger);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
createUser(name: string) {
|
|
142
|
+
this.logger.log(`Creating user: ${name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Constants
|
|
148
|
+
|
|
149
|
+
Use the `constant` helper to register constant values without needing a factory or class.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { Box, constant } from "getbox";
|
|
153
|
+
|
|
154
|
+
const ApiUrl = constant("https://api.example.com");
|
|
155
|
+
const Port = constant(3000);
|
|
156
|
+
const Config = constant({
|
|
157
|
+
apiUrl: "https://api.example.com",
|
|
158
|
+
timeout: 5000,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const box = new Box();
|
|
162
|
+
|
|
163
|
+
const apiUrl = box.get(ApiUrl);
|
|
164
|
+
const port = box.get(Port);
|
|
165
|
+
const config = box.get(Config);
|
|
166
|
+
|
|
167
|
+
console.log(apiUrl); // "https://api.example.com"
|
|
168
|
+
console.log(port); // 3000
|
|
169
|
+
console.log(config.timeout); // 5000
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Constructing classes with dependencies
|
|
173
|
+
|
|
174
|
+
Use `box.for()` for a convenient way to create instances of classes that take other constructors as dependencies. The instance created with `box.for()` is not cached, but dependencies resolved with `.get()` are cached.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
// database.ts
|
|
178
|
+
export class Database {
|
|
179
|
+
connect() { /* ... */ }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// logger.ts
|
|
183
|
+
import { Box, factory } from "getbox";
|
|
184
|
+
|
|
185
|
+
export interface Logger {
|
|
186
|
+
log(message: string): void;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const LoggerFactory = factory((box: Box): Logger => {
|
|
190
|
+
return console;
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
// service.ts
|
|
196
|
+
import { Box } from "getbox";
|
|
197
|
+
import { Database } from "./database";
|
|
198
|
+
import { Logger, LoggerFactory } from "./logger";
|
|
199
|
+
|
|
200
|
+
export class UserService {
|
|
201
|
+
constructor(
|
|
202
|
+
private db: Database,
|
|
203
|
+
private logger: Logger
|
|
204
|
+
) {}
|
|
205
|
+
|
|
206
|
+
static init(box: Box) {
|
|
207
|
+
// Create new instance with cached dependencies
|
|
208
|
+
return box.for(UserService).get(Database, LoggerFactory);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
createUser(name: string) {
|
|
212
|
+
this.logger.log(`Creating user: ${name}`);
|
|
213
|
+
// Use db to save user
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
// main.ts
|
|
220
|
+
import { Box } from "getbox";
|
|
221
|
+
import { UserService } from "./service";
|
|
222
|
+
|
|
223
|
+
const box = new Box();
|
|
224
|
+
|
|
225
|
+
const service = box.get(UserService);
|
|
226
|
+
service.createUser("Alice");
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Mocking
|
|
230
|
+
|
|
231
|
+
You can mock dependencies for testing using `Box.mock`. This is particularly useful with factories and interfaces.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
// service.test.ts
|
|
235
|
+
import { Box } from "getbox";
|
|
236
|
+
import { Logger, LoggerFactory } from "./logger";
|
|
237
|
+
import { UserService } from "./service";
|
|
238
|
+
|
|
239
|
+
class MockLogger implements Logger {
|
|
240
|
+
messages: string[] = [];
|
|
241
|
+
|
|
242
|
+
log(message: string): void {
|
|
243
|
+
this.messages.push(message);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const box = new Box();
|
|
248
|
+
Box.mock(box, LoggerFactory, new MockLogger());
|
|
249
|
+
|
|
250
|
+
const service = box.get(UserService);
|
|
251
|
+
service.createUser("Alice");
|
|
252
|
+
|
|
253
|
+
console.log(mockLogger.messages); // ["Creating user: Alice"]
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Circular dependencies
|
|
257
|
+
|
|
258
|
+
`getbox` does not prevent circular dependencies. You should structure your code to avoid circular imports between modules.
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
body, html {
|
|
2
|
+
margin:0; padding: 0;
|
|
3
|
+
height: 100%;
|
|
4
|
+
}
|
|
5
|
+
body {
|
|
6
|
+
font-family: Helvetica Neue, Helvetica, Arial;
|
|
7
|
+
font-size: 14px;
|
|
8
|
+
color:#333;
|
|
9
|
+
}
|
|
10
|
+
.small { font-size: 12px; }
|
|
11
|
+
*, *:after, *:before {
|
|
12
|
+
-webkit-box-sizing:border-box;
|
|
13
|
+
-moz-box-sizing:border-box;
|
|
14
|
+
box-sizing:border-box;
|
|
15
|
+
}
|
|
16
|
+
h1 { font-size: 20px; margin: 0;}
|
|
17
|
+
h2 { font-size: 14px; }
|
|
18
|
+
pre {
|
|
19
|
+
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
|
20
|
+
margin: 0;
|
|
21
|
+
padding: 0;
|
|
22
|
+
-moz-tab-size: 2;
|
|
23
|
+
-o-tab-size: 2;
|
|
24
|
+
tab-size: 2;
|
|
25
|
+
}
|
|
26
|
+
a { color:#0074D9; text-decoration:none; }
|
|
27
|
+
a:hover { text-decoration:underline; }
|
|
28
|
+
.strong { font-weight: bold; }
|
|
29
|
+
.space-top1 { padding: 10px 0 0 0; }
|
|
30
|
+
.pad2y { padding: 20px 0; }
|
|
31
|
+
.pad1y { padding: 10px 0; }
|
|
32
|
+
.pad2x { padding: 0 20px; }
|
|
33
|
+
.pad2 { padding: 20px; }
|
|
34
|
+
.pad1 { padding: 10px; }
|
|
35
|
+
.space-left2 { padding-left:55px; }
|
|
36
|
+
.space-right2 { padding-right:20px; }
|
|
37
|
+
.center { text-align:center; }
|
|
38
|
+
.clearfix { display:block; }
|
|
39
|
+
.clearfix:after {
|
|
40
|
+
content:'';
|
|
41
|
+
display:block;
|
|
42
|
+
height:0;
|
|
43
|
+
clear:both;
|
|
44
|
+
visibility:hidden;
|
|
45
|
+
}
|
|
46
|
+
.fl { float: left; }
|
|
47
|
+
@media only screen and (max-width:640px) {
|
|
48
|
+
.col3 { width:100%; max-width:100%; }
|
|
49
|
+
.hide-mobile { display:none!important; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.quiet {
|
|
53
|
+
color: #7f7f7f;
|
|
54
|
+
color: rgba(0,0,0,0.5);
|
|
55
|
+
}
|
|
56
|
+
.quiet a { opacity: 0.7; }
|
|
57
|
+
|
|
58
|
+
.fraction {
|
|
59
|
+
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
60
|
+
font-size: 10px;
|
|
61
|
+
color: #555;
|
|
62
|
+
background: #E8E8E8;
|
|
63
|
+
padding: 4px 5px;
|
|
64
|
+
border-radius: 3px;
|
|
65
|
+
vertical-align: middle;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
div.path a:link, div.path a:visited { color: #333; }
|
|
69
|
+
table.coverage {
|
|
70
|
+
border-collapse: collapse;
|
|
71
|
+
margin: 10px 0 0 0;
|
|
72
|
+
padding: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
table.coverage td {
|
|
76
|
+
margin: 0;
|
|
77
|
+
padding: 0;
|
|
78
|
+
vertical-align: top;
|
|
79
|
+
}
|
|
80
|
+
table.coverage td.line-count {
|
|
81
|
+
text-align: right;
|
|
82
|
+
padding: 0 5px 0 20px;
|
|
83
|
+
}
|
|
84
|
+
table.coverage td.line-coverage {
|
|
85
|
+
text-align: right;
|
|
86
|
+
padding-right: 10px;
|
|
87
|
+
min-width:20px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
table.coverage td span.cline-any {
|
|
91
|
+
display: inline-block;
|
|
92
|
+
padding: 0 5px;
|
|
93
|
+
width: 100%;
|
|
94
|
+
}
|
|
95
|
+
.missing-if-branch {
|
|
96
|
+
display: inline-block;
|
|
97
|
+
margin-right: 5px;
|
|
98
|
+
border-radius: 3px;
|
|
99
|
+
position: relative;
|
|
100
|
+
padding: 0 4px;
|
|
101
|
+
background: #333;
|
|
102
|
+
color: yellow;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.skip-if-branch {
|
|
106
|
+
display: none;
|
|
107
|
+
margin-right: 10px;
|
|
108
|
+
position: relative;
|
|
109
|
+
padding: 0 4px;
|
|
110
|
+
background: #ccc;
|
|
111
|
+
color: white;
|
|
112
|
+
}
|
|
113
|
+
.missing-if-branch .typ, .skip-if-branch .typ {
|
|
114
|
+
color: inherit !important;
|
|
115
|
+
}
|
|
116
|
+
.coverage-summary {
|
|
117
|
+
border-collapse: collapse;
|
|
118
|
+
width: 100%;
|
|
119
|
+
}
|
|
120
|
+
.coverage-summary tr { border-bottom: 1px solid #bbb; }
|
|
121
|
+
.keyline-all { border: 1px solid #ddd; }
|
|
122
|
+
.coverage-summary td, .coverage-summary th { padding: 10px; }
|
|
123
|
+
.coverage-summary tbody { border: 1px solid #bbb; }
|
|
124
|
+
.coverage-summary td { border-right: 1px solid #bbb; }
|
|
125
|
+
.coverage-summary td:last-child { border-right: none; }
|
|
126
|
+
.coverage-summary th {
|
|
127
|
+
text-align: left;
|
|
128
|
+
font-weight: normal;
|
|
129
|
+
white-space: nowrap;
|
|
130
|
+
}
|
|
131
|
+
.coverage-summary th.file { border-right: none !important; }
|
|
132
|
+
.coverage-summary th.pct { }
|
|
133
|
+
.coverage-summary th.pic,
|
|
134
|
+
.coverage-summary th.abs,
|
|
135
|
+
.coverage-summary td.pct,
|
|
136
|
+
.coverage-summary td.abs { text-align: right; }
|
|
137
|
+
.coverage-summary td.file { white-space: nowrap; }
|
|
138
|
+
.coverage-summary td.pic { min-width: 120px !important; }
|
|
139
|
+
.coverage-summary tfoot td { }
|
|
140
|
+
|
|
141
|
+
.coverage-summary .sorter {
|
|
142
|
+
height: 10px;
|
|
143
|
+
width: 7px;
|
|
144
|
+
display: inline-block;
|
|
145
|
+
margin-left: 0.5em;
|
|
146
|
+
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
|
147
|
+
}
|
|
148
|
+
.coverage-summary .sorted .sorter {
|
|
149
|
+
background-position: 0 -20px;
|
|
150
|
+
}
|
|
151
|
+
.coverage-summary .sorted-desc .sorter {
|
|
152
|
+
background-position: 0 -10px;
|
|
153
|
+
}
|
|
154
|
+
.status-line { height: 10px; }
|
|
155
|
+
/* yellow */
|
|
156
|
+
.cbranch-no { background: yellow !important; color: #111; }
|
|
157
|
+
/* dark red */
|
|
158
|
+
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
|
|
159
|
+
.low .chart { border:1px solid #C21F39 }
|
|
160
|
+
.highlighted,
|
|
161
|
+
.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
|
|
162
|
+
background: #C21F39 !important;
|
|
163
|
+
}
|
|
164
|
+
/* medium red */
|
|
165
|
+
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
|
|
166
|
+
/* light red */
|
|
167
|
+
.low, .cline-no { background:#FCE1E5 }
|
|
168
|
+
/* light green */
|
|
169
|
+
.high, .cline-yes { background:rgb(230,245,208) }
|
|
170
|
+
/* medium green */
|
|
171
|
+
.cstat-yes { background:rgb(161,215,106) }
|
|
172
|
+
/* dark green */
|
|
173
|
+
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
|
|
174
|
+
.high .chart { border:1px solid rgb(77,146,33) }
|
|
175
|
+
/* dark yellow (gold) */
|
|
176
|
+
.status-line.medium, .medium .cover-fill { background: #f9cd0b; }
|
|
177
|
+
.medium .chart { border:1px solid #f9cd0b; }
|
|
178
|
+
/* light yellow */
|
|
179
|
+
.medium { background: #fff4c2; }
|
|
180
|
+
|
|
181
|
+
.cstat-skip { background: #ddd; color: #111; }
|
|
182
|
+
.fstat-skip { background: #ddd; color: #111 !important; }
|
|
183
|
+
.cbranch-skip { background: #ddd !important; color: #111; }
|
|
184
|
+
|
|
185
|
+
span.cline-neutral { background: #eaeaea; }
|
|
186
|
+
|
|
187
|
+
.coverage-summary td.empty {
|
|
188
|
+
opacity: .5;
|
|
189
|
+
padding-top: 4px;
|
|
190
|
+
padding-bottom: 4px;
|
|
191
|
+
line-height: 1;
|
|
192
|
+
color: #888;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.cover-fill, .cover-empty {
|
|
196
|
+
display:inline-block;
|
|
197
|
+
height: 12px;
|
|
198
|
+
}
|
|
199
|
+
.chart {
|
|
200
|
+
line-height: 0;
|
|
201
|
+
}
|
|
202
|
+
.cover-empty {
|
|
203
|
+
background: white;
|
|
204
|
+
}
|
|
205
|
+
.cover-full {
|
|
206
|
+
border-right: none !important;
|
|
207
|
+
}
|
|
208
|
+
pre.prettyprint {
|
|
209
|
+
border: none !important;
|
|
210
|
+
padding: 0 !important;
|
|
211
|
+
margin: 0 !important;
|
|
212
|
+
}
|
|
213
|
+
.com { color: #999 !important; }
|
|
214
|
+
.ignore-none { color: #999; font-weight: normal; }
|
|
215
|
+
|
|
216
|
+
.wrapper {
|
|
217
|
+
min-height: 100%;
|
|
218
|
+
height: auto !important;
|
|
219
|
+
height: 100%;
|
|
220
|
+
margin: 0 auto -48px;
|
|
221
|
+
}
|
|
222
|
+
.footer, .push {
|
|
223
|
+
height: 48px;
|
|
224
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var jumpToCode = (function init() {
|
|
3
|
+
// Classes of code we would like to highlight in the file view
|
|
4
|
+
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
|
|
5
|
+
|
|
6
|
+
// Elements to highlight in the file listing view
|
|
7
|
+
var fileListingElements = ['td.pct.low'];
|
|
8
|
+
|
|
9
|
+
// We don't want to select elements that are direct descendants of another match
|
|
10
|
+
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
|
|
11
|
+
|
|
12
|
+
// Selector that finds elements on the page to which we can jump
|
|
13
|
+
var selector =
|
|
14
|
+
fileListingElements.join(', ') +
|
|
15
|
+
', ' +
|
|
16
|
+
notSelector +
|
|
17
|
+
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
|
|
18
|
+
|
|
19
|
+
// The NodeList of matching elements
|
|
20
|
+
var missingCoverageElements = document.querySelectorAll(selector);
|
|
21
|
+
|
|
22
|
+
var currentIndex;
|
|
23
|
+
|
|
24
|
+
function toggleClass(index) {
|
|
25
|
+
missingCoverageElements
|
|
26
|
+
.item(currentIndex)
|
|
27
|
+
.classList.remove('highlighted');
|
|
28
|
+
missingCoverageElements.item(index).classList.add('highlighted');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function makeCurrent(index) {
|
|
32
|
+
toggleClass(index);
|
|
33
|
+
currentIndex = index;
|
|
34
|
+
missingCoverageElements.item(index).scrollIntoView({
|
|
35
|
+
behavior: 'smooth',
|
|
36
|
+
block: 'center',
|
|
37
|
+
inline: 'center'
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function goToPrevious() {
|
|
42
|
+
var nextIndex = 0;
|
|
43
|
+
if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
|
44
|
+
nextIndex = missingCoverageElements.length - 1;
|
|
45
|
+
} else if (missingCoverageElements.length > 1) {
|
|
46
|
+
nextIndex = currentIndex - 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
makeCurrent(nextIndex);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function goToNext() {
|
|
53
|
+
var nextIndex = 0;
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
typeof currentIndex === 'number' &&
|
|
57
|
+
currentIndex < missingCoverageElements.length - 1
|
|
58
|
+
) {
|
|
59
|
+
nextIndex = currentIndex + 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
makeCurrent(nextIndex);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return function jump(event) {
|
|
66
|
+
if (
|
|
67
|
+
document.getElementById('fileSearch') === document.activeElement &&
|
|
68
|
+
document.activeElement != null
|
|
69
|
+
) {
|
|
70
|
+
// if we're currently focused on the search input, we don't want to navigate
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
switch (event.which) {
|
|
75
|
+
case 78: // n
|
|
76
|
+
case 74: // j
|
|
77
|
+
goToNext();
|
|
78
|
+
break;
|
|
79
|
+
case 66: // b
|
|
80
|
+
case 75: // k
|
|
81
|
+
case 80: // p
|
|
82
|
+
goToPrevious();
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
})();
|
|
87
|
+
window.addEventListener('keydown', jumpToCode);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<coverage generated="1766849830981" clover="3.2.0">
|
|
3
|
+
<project timestamp="1766849830981" name="All files">
|
|
4
|
+
<metrics statements="15" coveredstatements="15" conditionals="4" coveredconditionals="4" methods="13" coveredmethods="13" elements="32" coveredelements="32" complexity="0" loc="15" ncloc="15" packages="1" files="1" classes="1"/>
|
|
5
|
+
<file name="index.ts" path="/Users/eriicafes/Developer/node/usebox/src/index.ts">
|
|
6
|
+
<metrics statements="15" coveredstatements="15" conditionals="4" coveredconditionals="4" methods="13" coveredmethods="13"/>
|
|
7
|
+
<line num="8" count="10" type="stmt"/>
|
|
8
|
+
<line num="12" count="7" type="stmt"/>
|
|
9
|
+
<line num="16" count="34" type="stmt"/>
|
|
10
|
+
<line num="20" count="58" type="cond" truecount="2" falsecount="0"/>
|
|
11
|
+
<line num="25" count="64" type="cond" truecount="2" falsecount="0"/>
|
|
12
|
+
<line num="28" count="45" type="stmt"/>
|
|
13
|
+
<line num="30" count="45" type="stmt"/>
|
|
14
|
+
<line num="31" count="45" type="stmt"/>
|
|
15
|
+
<line num="35" count="12" type="stmt"/>
|
|
16
|
+
<line num="43" count="5" type="stmt"/>
|
|
17
|
+
<line num="48" count="12" type="stmt"/>
|
|
18
|
+
<line num="51" count="4" type="stmt"/>
|
|
19
|
+
<line num="52" count="4" type="stmt"/>
|
|
20
|
+
<line num="56" count="11" type="stmt"/>
|
|
21
|
+
<line num="57" count="8" type="stmt"/>
|
|
22
|
+
</file>
|
|
23
|
+
</project>
|
|
24
|
+
</coverage>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"/Users/eriicafes/Developer/node/usebox/src/index.ts": {"path":"/Users/eriicafes/Developer/node/usebox/src/index.ts","statementMap":{"0":{"start":{"line":8,"column":2},"end":{"line":8,"column":null}},"1":{"start":{"line":12,"column":2},"end":{"line":12,"column":null}},"2":{"start":{"line":12,"column":23},"end":{"line":12,"column":29}},"3":{"start":{"line":16,"column":2},"end":{"line":16,"column":null}},"4":{"start":{"line":20,"column":4},"end":{"line":20,"column":null}},"5":{"start":{"line":25,"column":4},"end":{"line":25,"column":null}},"6":{"start":{"line":25,"column":37},"end":{"line":25,"column":null}},"7":{"start":{"line":28,"column":18},"end":{"line":28,"column":null}},"8":{"start":{"line":30,"column":4},"end":{"line":30,"column":null}},"9":{"start":{"line":31,"column":4},"end":{"line":31,"column":null}},"10":{"start":{"line":35,"column":4},"end":{"line":35,"column":null}},"11":{"start":{"line":43,"column":4},"end":{"line":43,"column":null}},"12":{"start":{"line":48,"column":22},"end":{"line":48,"column":40}},"13":{"start":{"line":48,"column":40},"end":{"line":48,"column":54}},"14":{"start":{"line":51,"column":22},"end":{"line":51,"column":null}},"15":{"start":{"line":51,"column":40},"end":{"line":51,"column":57}},"16":{"start":{"line":52,"column":4},"end":{"line":52,"column":null}},"17":{"start":{"line":56,"column":22},"end":{"line":56,"column":null}},"18":{"start":{"line":56,"column":40},"end":{"line":56,"column":57}},"19":{"start":{"line":57,"column":4},"end":{"line":57,"column":null}}},"fnMap":{"0":{"name":"factory","decl":{"start":{"line":7,"column":16},"end":{"line":7,"column":27}},"loc":{"start":{"line":7,"column":66},"end":{"line":9,"column":null}},"line":7},"1":{"name":"constant","decl":{"start":{"line":11,"column":16},"end":{"line":11,"column":34}},"loc":{"start":{"line":11,"column":60},"end":{"line":13,"column":null}},"line":11},"2":{"name":"(anonymous_2)","decl":{"start":{"line":12,"column":17},"end":{"line":12,"column":23}},"loc":{"start":{"line":12,"column":23},"end":{"line":12,"column":29}},"line":12},"3":{"name":"(anonymous_3)","decl":{"start":{"line":15,"column":7},"end":{"line":15,"column":13}},"loc":{"start":{"line":15,"column":7},"end":{"line":16,"column":null}},"line":15},"4":{"name":"(anonymous_4)","decl":{"start":{"line":18,"column":9},"end":{"line":18,"column":16}},"loc":{"start":{"line":18,"column":48},"end":{"line":21,"column":null}},"line":18},"5":{"name":"(anonymous_5)","decl":{"start":{"line":23,"column":9},"end":{"line":23,"column":16}},"loc":{"start":{"line":23,"column":48},"end":{"line":32,"column":null}},"line":23},"6":{"name":"(anonymous_6)","decl":{"start":{"line":34,"column":9},"end":{"line":34,"column":46}},"loc":{"start":{"line":34,"column":62},"end":{"line":36,"column":null}},"line":34},"7":{"name":"(anonymous_7)","decl":{"start":{"line":38,"column":16},"end":{"line":38,"column":null}},"loc":{"start":{"line":42,"column":4},"end":{"line":44,"column":null}},"line":42},"8":{"name":"(anonymous_8)","decl":{"start":{"line":48,"column":2},"end":{"line":48,"column":22}},"loc":{"start":{"line":48,"column":54},"end":{"line":48,"column":null}},"line":48},"9":{"name":"(anonymous_9)","decl":{"start":{"line":50,"column":9},"end":{"line":50,"column":16}},"loc":{"start":{"line":50,"column":64},"end":{"line":53,"column":null}},"line":50},"10":{"name":"(anonymous_10)","decl":{"start":{"line":51,"column":31},"end":{"line":51,"column":32}},"loc":{"start":{"line":51,"column":40},"end":{"line":51,"column":57}},"line":51},"11":{"name":"(anonymous_11)","decl":{"start":{"line":55,"column":9},"end":{"line":55,"column":16}},"loc":{"start":{"line":55,"column":64},"end":{"line":58,"column":null}},"line":55},"12":{"name":"(anonymous_12)","decl":{"start":{"line":56,"column":31},"end":{"line":56,"column":32}},"loc":{"start":{"line":56,"column":40},"end":{"line":56,"column":57}},"line":56}},"branchMap":{"0":{"loc":{"start":{"line":20,"column":11},"end":{"line":20,"column":null}},"type":"cond-expr","locations":[{"start":{"line":20,"column":35},"end":{"line":20,"column":60}},{"start":{"line":20,"column":60},"end":{"line":20,"column":null}}],"line":20},"1":{"loc":{"start":{"line":25,"column":4},"end":{"line":25,"column":null}},"type":"if","locations":[{"start":{"line":25,"column":4},"end":{"line":25,"column":null}},{"start":{},"end":{}}],"line":25}},"s":{"0":10,"1":7,"2":7,"3":34,"4":58,"5":64,"6":19,"7":45,"8":45,"9":45,"10":12,"11":5,"12":12,"13":12,"14":4,"15":4,"16":4,"17":8,"18":11,"19":8},"f":{"0":10,"1":7,"2":7,"3":34,"4":58,"5":64,"6":12,"7":1,"8":12,"9":4,"10":4,"11":8,"12":11},"b":{"0":[33,25],"1":[19,45]},"meta":{"lastBranch":2,"lastFunction":13,"lastStatement":20,"seen":{"f:7:16:7:27":0,"s:8:2:8:Infinity":0,"f:11:16:11:34":1,"s:12:2:12:Infinity":1,"f:12:17:12:23":2,"s:12:23:12:29":2,"f:15:7:15:13":3,"s:16:2:16:Infinity":3,"f:18:9:18:16":4,"s:20:4:20:Infinity":4,"b:20:35:20:60:20:60:20:Infinity":0,"f:23:9:23:16":5,"b:25:4:25:Infinity:undefined:undefined:undefined:undefined":1,"s:25:4:25:Infinity":5,"s:25:37:25:Infinity":6,"s:28:18:28:Infinity":7,"s:30:4:30:Infinity":8,"s:31:4:31:Infinity":9,"f:34:9:34:46":6,"s:35:4:35:Infinity":10,"f:38:16:38:Infinity":7,"s:43:4:43:Infinity":11,"f:48:2:48:22":8,"s:48:22:48:40":12,"s:48:40:48:54":13,"f:50:9:50:16":9,"s:51:22:51:Infinity":14,"f:51:31:51:32":10,"s:51:40:51:57":15,"s:52:4:52:Infinity":16,"f:55:9:55:16":11,"s:56:22:56:Infinity":17,"f:56:31:56:32":12,"s:56:40:56:57":18,"s:57:4:57:Infinity":19}}}
|
|
2
|
+
}
|
|
Binary file
|