forked from danielwerg/r6api.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-utils.ts
40 lines (32 loc) · 1.36 KB
/
ts-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* This files contains some useful type-checking functions
You can require this file with:
- require('r6api.js/ts-utils')
- import * as utils from 'r6api.js/ts-utils'
- import { functionName } from 'r6api.js/ts-utils'
*/
import { oldRankNumber, operator, rankNumber, seasonNumber, weaponName, weaponType } from './typings/autogen'
import * as constants from './lib/constants'
export function isOldRankNumber(value: number): value is oldRankNumber {
return typeof value == 'number'
&& Object.keys(constants.OLD_RANKS).map(parseInt).includes(value)
}
export function isOperator(value: string): value is operator {
return typeof value == 'string'
&& constants.OPERATORS.map(op => op.name).includes(value)
}
export function isRankNumber(value: number): value is rankNumber {
return typeof value == 'number'
&& Object.keys(constants.RANKS).map(parseInt).includes(value)
}
export function isSeasonNumber(value: number): value is seasonNumber {
return typeof value == 'number'
&& Object.keys(constants.SEASONS).map(parseInt).includes(value)
}
export function isWeaponName(value: string): value is weaponName {
return typeof value == 'string'
&& constants.WEAPONS.map(wp => wp.name).includes(value)
}
export function isWeaponType(value: string): value is weaponType {
return typeof value == 'string'
&& Object.values(constants.WEAPONTYPES).includes(value)
}