/
text.js
37 lines (35 loc) · 958 Bytes
/
text.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 { textFromDoc } from './lib/_text.js'
import fmts from './_fmts.js'
const isObject = val => {
return Object.prototype.toString.call(val) === '[object Object]'
}
export default {
/** */
text: function (fmt) {
let opts = {}
if (fmt && typeof fmt === 'string' && fmts.hasOwnProperty(fmt)) {
opts = Object.assign({}, fmts[fmt])
} else if (fmt && isObject(fmt)) {
opts = Object.assign({}, fmt)//todo: fixme
}
if (opts.keepSpace === undefined && this.pointer) {
opts.keepSpace = false
}
if (opts.keepPunct === undefined && this.pointer) {
let ptr = this.pointer[0]
if (ptr && ptr[1]) {
opts.keepPunct = false
} else {
opts.keepPunct = true
}
}
// set defaults
if (opts.keepPunct === undefined) {
opts.keepPunct = true
}
if (opts.keepSpace === undefined) {
opts.keepSpace = true
}
return textFromDoc(this.docs, opts)
},
}