Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 0e27a76

Browse files
committed
Simplify scheme mapper
1 parent 539232c commit 0e27a76

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

packages/core/src/util/scheme-mapper.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { ReleaseDescriptor, TagDescriptor } from '../types'
2-
3-
function validate(obj: any) {
4-
if (! obj) {
5-
throw new Error('The object to map must not be falsy!')
6-
}
7-
}
1+
import { ReleaseDescriptor, RestResponseRelease, RestResponseTag, TagDescriptor } from '../types'
82

93
/**
104
* Maps a response object into the form described here:
115
* https://github.com/axelrindle/github-version-checker/wiki/API#releases
126
*/
13-
export function release(obj: any): ReleaseDescriptor {
14-
validate(obj)
7+
export function release(obj: RestResponseRelease|undefined): ReleaseDescriptor|undefined {
8+
if (obj === undefined) {
9+
return undefined
10+
}
1511

1612
return {
1713
name: obj.name,
@@ -28,8 +24,10 @@ export function release(obj: any): ReleaseDescriptor {
2824
* Maps a response object into the form described here:
2925
* https://github.com/axelrindle/github-version-checker/wiki/API#tags
3026
*/
31-
export function tag(obj: any): TagDescriptor {
32-
validate(obj)
27+
export function tag(obj: RestResponseTag|undefined): TagDescriptor|undefined {
28+
if (obj === undefined) {
29+
return undefined
30+
}
3331

3432
return {
3533
name: obj.name

packages/core/test/test-scheme-mapper.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,15 @@ test('scheme-mapper#release maps correctly', t => {
4343
publishedAt: '1. May 2018',
4444
url: 'https://github.com/axelrindle/github-version-checker/releases/tag/v2.0.0'
4545
})
46+
47+
t.is(release(undefined), undefined)
4648
})
4749

4850
test('scheme-mapper#release fails with invalid object', t => {
4951
const error = t.throws(() => {
5052
return release(null)
5153
})
52-
t.is(error.message, 'The object to map must not be falsy!')
53-
54-
const error2 = t.throws(() => {
55-
return release(undefined)
56-
})
57-
t.is(error2.message, 'The object to map must not be falsy!')
54+
t.regex(error.message, /^Cannot read properties of null/g)
5855
})
5956

6057
test('scheme-mapper#tag maps correctly', t => {
@@ -67,16 +64,13 @@ test('scheme-mapper#tag maps correctly', t => {
6764
t.deepEqual(mapped2, {
6865
name: 'axelrindle/github-version-checker'
6966
})
67+
68+
t.is(tag(undefined), undefined)
7069
})
7170

7271
test('scheme-mapper#tag fails with invalid object', t => {
7372
const error = t.throws(() => {
74-
return tag(null)
75-
})
76-
t.is(error.message, 'The object to map must not be falsy!')
77-
78-
const error2 = t.throws(() => {
79-
return tag(undefined)
73+
return release(null)
8074
})
81-
t.is(error2.message, 'The object to map must not be falsy!')
75+
t.regex(error.message, /^Cannot read properties of null/g)
8276
})

0 commit comments

Comments
 (0)