Skip to content

Commit 8db69fe

Browse files
authored
fix: return undefined instead of null (#498)
* fix: return undefined instead of null * chore: tidy up some ci workflows
1 parent a4a6ceb commit 8db69fe

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Code Linting
22

33
on:
44
push:
5-
workflow_call:
65

76
jobs:
87
eslint:

.github/workflows/release-please.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
name: Release
2+
13
on:
24
push:
35
branches:
4-
- master
56
- main
67

78
permissions:
89
contents: write
910
pull-requests: write
1011

11-
name: release-please
12-
1312
jobs:
1413
release-please:
1514
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Unit Testing
2+
23
on:
34
push:
5+
46
jobs:
5-
build:
7+
unit-test:
68
runs-on: ubuntu-latest
79
strategy:
810
matrix:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": "vite",
99
"build": "tsc && vite build",
1010
"lint": "eslint src/**/* --ext .ts",
11-
"test": "vitest --coverage --run"
11+
"test": "vitest --coverage --run",
12+
"test:watch": "vitest --coverage"
1213
},
1314
"repository": {
1415
"type": "git",

src/browser-detection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('Should work correctly', () => {
158158

159159
expect(detectBrowserNameAndVersion(ieWithoutVersion)).toEqual({
160160
name: 'IE',
161-
version: null,
161+
version: undefined,
162162
});
163163
});
164164

@@ -169,7 +169,7 @@ describe('Should work correctly', () => {
169169

170170
expect(detectBrowserNameAndVersion(emptyUserAgent)).toEqual({
171171
name: undefined,
172-
version: NaN,
172+
version: undefined,
173173
});
174174
});
175175
});

src/browser-detection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ function detectBrowserVersion(nav: {userAgent: string}, name: string): number |
168168
switch (name) {
169169
case 'IE': {
170170
const temp = /\brv[ :]+(\d+)/g.exec(userAgent) ?? [];
171-
return Number(temp[1]) || null;
171+
return Number(temp[1]) || undefined;
172172
}
173173

174174
case 'Edge': {
175175
const temp = /\b(Edge)\/(\d+)/.exec(userAgent);
176-
return Number(temp[2]);
176+
return temp ? Number(temp[2]) : undefined;
177177
}
178178
}
179179

@@ -194,7 +194,7 @@ function detectBrowserVersion(nav: {userAgent: string}, name: string): number |
194194
found.splice(1, 1, temp[1]);
195195
}
196196

197-
return Number(found[1]);
197+
return found[1] ? Number(found[1]) : undefined;
198198
}
199199

200200
/**

0 commit comments

Comments
 (0)