-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (30 loc) · 967 Bytes
/
index.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
const { Plugin } = require('aid-bundler')
module.exports = function (options) {
function formatWhitespace (data, outputText) {
if (!options.formatWhitespace) return
if (data.history.length === 0) return
data.text = data.text.trim().replace('\n', '')
if (outputText) {
data.text = '\n ' + data.text
} else {
data.text = '\n\n' + data.text
}
}
function inputModifier (data) {
formatWhitespace(data, false)
if (data.history.length > 0 && options.textSeparator) {
data.text = '\n\n' + options.textSeparator + data.text
}
}
function contextModifier (data) {
if (options.textSeparator) {
let lines = data.text.split('\n')
lines = lines.filter(line => line !== options.textSeparator)
data.text = lines.join('\n')
}
}
function outputModifier (data) {
formatWhitespace(data, true)
}
return new Plugin('Reformatter', inputModifier, contextModifier, outputModifier)
}