Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

gulp-append-prepend

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-append-prepend - npm Package Compare versions

Comparing version
1.0.6
to
1.0.7
+1
spec/fixture/index.html
<body><h1>GAP</h1></body>
<!doctype html>
<html>
<head><title>GAP</title></head>
// Mocha Specification Cases
// Imports
const assert = require('assert').strict;
const fs = require('fs');
const Vinyl = require('vinyl');
// Plugin
const gap = require('../index.js');
// Data
console.log(' Input files:');
fs.readdirSync('spec/fixture').forEach(file => console.log(' spec/fixture/' + file));
const page = {
begin: '<!doctype html>\n<html>\n<head><title>GAP</title></head>',
body: '<body><h1>GAP</h1></body>',
end: '</html>'
};
////////////////////////////////////////////////////////////////////////////////////////////////////
describe('The gulp-append-prepend plugin', () => {
it('is exported as an object', () => {
const actual = { type: typeof gap };
const expected = { type: 'object' };
assert.deepEqual(actual, expected);
});
it('contains the functions: appendFile(), prependFile(), appendText(), prependText()', () => {
const names = ['appendFile', 'prependFile', 'appendText', 'prependText'];
const actual = { functions: Object.keys(gap).sort() };
const expected = { functions: names.sort() };
assert.deepEqual(actual, expected);
});
it('functions are the correct type', () => {
const actual = { types: Object.values(gap).map(v => typeof v) };
const expected = { types: ['function', 'function', 'function', 'function'] };
assert.deepEqual(actual, expected);
});
});
////////////////////////////////////////////////////////////////////////////////////////////////////
describe('The appendFile() function', () => {
it('correctly appends file contents to the body of an HTML file', (done) => {
const inputFile = 'spec/fixture/index.html';
const handleFileFromStream = (file) => {
const actual = { page: file.contents.toString() };
const expected = { page: page.body + '\n\n' + page.end };
assert.deepEqual(actual, expected);
done();
};
const stream = gap.appendFile('spec/fixture/page-end.html');
stream.on('data', handleFileFromStream);
stream.write(new Vinyl({ contents: fs.readFileSync(inputFile) }));
stream.end();
});
});
////////////////////////////////////////////////////////////////////////////////////////////////////
describe('The prependFile() function', () => {
it('correctly prepends file contents to the body of an HTML file', (done) => {
const inputFile = 'spec/fixture/index.html';
const handleFileFromStream = (file) => {
const actual = { page: file.contents.toString() };
const expected = { page: page.begin + '\n' + page.body + '\n' };
assert.deepEqual(actual, expected);
done();
};
const stream = gap.prependFile('spec/fixture/page-begin.html');
stream.on('data', handleFileFromStream);
stream.write(new Vinyl({ contents: fs.readFileSync(inputFile) }));
stream.end();
});
});
////////////////////////////////////////////////////////////////////////////////////////////////////
describe('The appendText() function', () => {
it('correctly appends a string to the body of an HTML file', (done) => {
const inputFile = 'spec/fixture/index.html';
const handleFileFromStream = (file) => {
const actual = { page: file.contents.toString() };
const expected = { page: page.body + '\n\n' + page.end };
assert.deepEqual(actual, expected);
done();
};
const stream = gap.appendText(page.end);
stream.on('data', handleFileFromStream);
stream.write(new Vinyl({ contents: fs.readFileSync(inputFile) }));
stream.end();
});
});
////////////////////////////////////////////////////////////////////////////////////////////////////
describe('The prependText() function', () => {
it('correctly prepends a string to the body of an HTML file', (done) => {
const inputFile = 'spec/fixture/index.html';
const handleFileFromStream = (file) => {
const actual = { page: file.contents.toString() };
const expected = { page: page.begin + '\n' + page.body + '\n' };
assert.deepEqual(actual, expected);
done();
};
const stream = gap.prependText(page.begin);
stream.on('data', handleFileFromStream);
stream.write(new Vinyl({ contents: fs.readFileSync(inputFile) }));
stream.end();
});
});
+10
-10

@@ -13,3 +13,3 @@ const through = require('through2');

const filesContents = [];
for(i = 0; i < filepaths.length; i++){
for (let i = 0; i < filepaths.length; i++) {
filesContents.push(read.sync(filepaths[i], 'utf8'));

@@ -29,3 +29,3 @@ }

if (type != "append" && type != "prepend") {
if (type !== "append" && type !== "prepend") {
throw new PluginError(PLUGIN_NAME, 'Missing type !');

@@ -39,7 +39,7 @@ }

const buffers = [];
for (i = 0; i < texts.length; i++) {
if (type == "prepend") {
buffers.push(new Buffer(texts[i].trim() + separator));
}else if(type == "append") {
buffers.push(new Buffer(separator + texts[i].trim()));
for (let i = 0; i < texts.length; i++) {
if (type === "prepend") {
buffers.push(Buffer.from(texts[i].trim() + separator));
} else if (type === "append") {
buffers.push(Buffer.from(separator + texts[i].trim()));
}

@@ -56,9 +56,9 @@ }

const concat = [];
if (type == "append") {
if (type === "append") {
concat.push(file.contents);
}
for(i = 0; i < buffers.length; i++){
for (let i = 0; i < buffers.length; i++) {
concat.push(buffers[i]);
}
if (type == "prepend") {
if (type === "prepend") {
concat.push(file.contents);

@@ -65,0 +65,0 @@ }

{
"name": "gulp-append-prepend",
"version": "1.0.6",
"version": "1.0.7",
"description": "Simple Gulp plugin to append/prepend.",

@@ -31,4 +31,17 @@ "main": "index.js",

],
"jshintConfig": {
"esversion": 9,
"strict": "implied",
"eqeqeq": true,
"undef": true,
"unused": true,
"mocha": true,
"node": true
},
"scripts": {
"pretest": "jshint *.js spec",
"test": "mocha spec/*.js"
},
"engines": {
"node": ">= 0.10.0"
"node": ">=8.15.0"
},

@@ -39,3 +52,8 @@ "dependencies": {

"plugin-error": "^1.0.1"
},
"devDependencies": {
"jshint": "^2.10.2",
"mocha": "^6.0.2",
"vinyl": "~2.2.0"
}
}