-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjevkoFromString.js
37 lines (36 loc) · 1.03 KB
/
jevkoFromString.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
import { decodeString, textToString } from "./decode.js"
// todo: return this from makeDecoders
// could also impl a backward-compatible version that generates decoders on each call (yuck!)
export const jevkoFromString = (str) => {
let current = {subjevkos: [], suffix: ''}
const parents = [current]
const parent = decodeString(str, {
prefix: (text) => {
const {fencelength} = text
const jevko = {subjevkos: [], suffix: ''}
current.subjevkos.push({
prefix: textToString(text),
jevko,
...(fencelength === undefined? {}: {fencelength})
})
parents.push(current)
current = jevko
},
suffix: (text) => {
const {fencelength} = text
current.suffix = textToString(text)
if (fencelength !== undefined) {
current.fencelength = fencelength
}
current = parents.pop()
},
end: () => {
return current
}
})
// parent.opener = opener
// parent.closer = closer
// parent.escaper = escaper
// parent.fencer = fencer
return parent
}