-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapping.js
56 lines (46 loc) · 971 Bytes
/
mapping.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const JVCIR = require('./JVCIR.js').export
const GROUPS = require('./GROUPS.js').export
// maps ir codes to key strings
class Mapper{
constructor (mapping, group) {
// object that maps codes to strings
if (mapping) {
this.mapping = mapping
} else {
// defaults
this.mapping = JVCIR
}
// lists meanings of keys
if (group) {
this.groups = group
} else {
this.groups = GROUPS
}
}
map (code) {
const k = this.mapping[code]
if (k) {
return k
} else {
return 'unmapped'
}
}
isMapped (code) {
if (this.mapping[code]) {
return true
} else {
return false
}
}
group (name, key) {
if (this.groups[name]) {
return this.groups[name].includes(key)
} else {
throw new Error(`Mapper does not contain group '${name}'`)
}
}
groupCode (name, code) {
return this.group(name, this.map(code))
}
}
exports.Mapper = Mapper