gulp-propertext
Version:
Gulp plugin to parse propertext files
42 lines (35 loc) • 868 B
JavaScript
var Vinyl = require('vinyl')
var outdent = require('outdent')
var ptext = require('./')
var test = require('tape')
var file = new Vinyl({
path: 'test.txt',
contents: Buffer.from(outdent`
[one:] first
[two:] second
`)
})
test('basic', t => {
var stream = ptext().on('data', file => {
var data = JSON.parse(file.contents.toString())
t.equal(data.one, 'first')
t.equal(data.two, 'second')
})
t.plan(4)
stream.write(file.clone())
stream.write(file.clone())
})
test('config', t => {
var keepContents = true
var mappings = {
one: str => str.trim().toUpperCase(),
two: str => str
}
var stream = ptext({ keepContents, mappings }).on('data', file => {
var data = JSON.parse(file.contents.toString())
t.equal(data.one, 'FIRST')
t.equal(data.two, ' second\n')
t.end()
})
stream.write(file.clone())
})