-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectInterjevko.js
More file actions
49 lines (43 loc) · 1.36 KB
/
directInterjevko.js
File metadata and controls
49 lines (43 loc) · 1.36 KB
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
export const getFirstJevkoAtKey = (jevko, key) => {
const {subjevkos} = jevko
for (const {prefix, jevko} of subjevkos) {
if (prefix.trim() === key) return jevko
}
throw Error(`key not found: ${key}`)
}
export const getLastJevkoAtKey = (jevko, key) => {
const {subjevkos} = jevko
for (let i = subjevkos.length - 1; i >= 0; --i) {
const {prefix, jevko} = subjevkos[i]
if (prefix.trim() === key) return jevko
}
throw Error(`key not found: ${key}`)
}
export const getJevkoAtIndex = (jevko, index) => {
const {subjevkos} = jevko
if (index >= subjevkos.length) throw Error(`index not found: ${index}`)
return subjevkos[index].jevko
}
export const getSuffixAsString = (jevko) => {
return jevko.suffix
}
export const getSuffixAsNumber = (jevko) => {
const trimmed = jevko.suffix.trim()
if (trimmed === 'NaN') return NaN
const num = Number(trimmed)
if (Number.isNaN(num)) throw Error(`not a number: ${trimmed}`)
return num
}
export const getSuffixAsBoolean = (jevko) => {
const trimmed = jevko.suffix.trim()
if (trimmed === 'true') return true
if (trimmed === 'false') return false
throw Error(`not a boolean: ${trimmed}`)
}
export const getSuffixAsNull = (jevko) => {
const {suffix} = jevko
if (suffix === '') return null
const trimmed = suffix.trim()
if (trimmed === 'null') return null
throw Error(`not a null: ${trimmed}`)
}