Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Option to remove BOM from start of file #46

Merged
merged 2 commits into from
Oct 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function hbsfy(file, opts) {
var compiled = "// hbsfy compiled Handlebars template\n";
var parsed = null;
var partials = null;

if (opts && (opts.b || opts.bom) && buffer.indexOf('') === 0) {
buffer = buffer.substring(1);
}

try {
if (traverse) {
Expand Down
1 change: 1 addition & 0 deletions test/bom.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{msg}}!
28 changes: 28 additions & 0 deletions test/bom_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

var assert = require("assert");
var concat = require("concat-stream");
var fs = require("fs");
var hbsfyBom = require("hbsfy");
var hbsfyNoBom = require("hbsfy").configure({
bom: true
});

var templatePath = __dirname + "/bom.hbs";

fs.createReadStream(templatePath)
.pipe(hbsfyBom(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()),
"The template should contain a bom"
);
}));

fs.createReadStream(templatePath)
.pipe(hbsfyNoBom(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()) === false,
"The template should not contain a bom"
);
}));