blob: efb50d6186bdc58b6a33fde1ace61e9262237714 (
plain)
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
|
import { store } from 'app/store'
export const getSection = index => {
const { sections } = store.getState().viewer
return sections[index]
}
export const getNextSection = section => {
const { sections } = store.getState().viewer
if (section.index === sections.length - 1) {
return null
}
return sections[section.index + 1]
}
export const parseCredits = lines => {
let sections = []
let current
lines.split("\n").forEach((s, i) => {
if (s[0] === "#") {
current = {
title: s.replace("#", "").trim(),
lines: [],
i
}
sections.push(current)
} else {
current.lines.push(s.trim())
}
})
return sections
}
export const groupColumns = (lines, cols) => {
const perColumn = Math.ceil(lines.length / cols)
const columns = []
for (let i = 0; i < cols; i++) {
columns.push(lines.slice(i * perColumn, (i+1) * perColumn))
}
return columns
}
|