Socket
Socket
Sign inDemoInstall

stringify

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringify - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

test/getMinifyOptions.spec.js

2

package.json
{
"name": "stringify",
"description": "Browserify middleware to be able to require() text files (including templates) inside of your client-side JavaScript files.",
"version": "5.0.0",
"version": "5.1.0",
"main": "./index.js",

@@ -6,0 +6,0 @@ "author": "John Postlethwait <john.postlethwait@gmail.com>",

@@ -91,7 +91,7 @@ # Stringify #

minify: true,
minifier: {
extensions: ['.html'],
options: {
// html-minifier options
}
minifyAppliesTo: {
includeExtensions: ['.html']
},
minifyOptions: {
// html-minifier options
}

@@ -175,14 +175,18 @@ });

By default, files will not get minified - setting __minify__ configuration
option to true will enable this. The __minifier__ configuration option is used
to set additional options.
option to true will enable this.
The default value of __minifier.extensions__ is:
The __minifyAppliesTo__ configuration option allows files to be included or
excluded from the minifier in a similar way to __appliesTo__ (see _Including
/ Excluding Files_ section for more details).
The default included file extensions are:
```javascript
['.html', '.htm', '.tmpl', '.tpl', '.hbs']
```
The __minifier.options__ are passed through to html-minifier (for more informations or to override those
options, please go to [html-minifier github](https://github.com/kangax/html-minifier)).
The options set in the __minifyOptions__ configuration option are passed
through to html-minifier (for more informations or to override those options,
please go to [html-minifier github](https://github.com/kangax/html-minifier)).
The default value of __minifier.options__ is:
The default value of __minifyOptions__ is:

@@ -222,7 +226,7 @@ ```javascript

minify: true,
minifier: {
extensions: ['.html'],
options: {
// html-minifier options
}
minifyAppliesTo: {
includeExtensions: ['.html']
},
minifyOptions: {
// html-minifier options
}

@@ -229,0 +233,0 @@ })

@@ -7,12 +7,14 @@ 'use strict';

var DEFAULT_MINIFIER_EXTENSIONS = [
'.html',
'.htm',
'.tmpl',
'.tpl',
'.hbs'
];
var MINIFY_TRANSFORM_OPTIONS = {
includeExtensions: [
'.html',
'.htm',
'.tmpl',
'.tpl',
'.hbs'
]
};
var TRANSFORM_OPTIONS = {
includeExtensions: DEFAULT_MINIFIER_EXTENSIONS.concat([
includeExtensions: MINIFY_TRANSFORM_OPTIONS.includeExtensions.concat([
'.text',

@@ -23,3 +25,3 @@ '.txt'

var DEFAULT_MINIFIER_OPTIONS = {
var DEFAULT_MINIFY_OPTIONS = {
removeComments: true,

@@ -119,25 +121,26 @@ removeCommentsFromCDATA: true,

* @param {object} options
* @param {object} options.minifier
* @returns {object}
*/
function getMinifierOptions (_options) {
var options = _options || {};
var minifier = options.minifier || {};
return {
requested : !!options.minify,
extensions: minifier.extensions || DEFAULT_MINIFIER_EXTENSIONS,
options: minifier.options || DEFAULT_MINIFIER_OPTIONS
};
}
function getMinifyOptions (options) {
if (!options || !options.minify) {
return { requested: false };
}
/**
* Returns whether the filename ends in a Stringifiable extension. Case
* insensitive.
* @param {string} filename
* @return {boolean}
*/
function hasStringifiableExtension (filename, extensions) {
var file_extension = path.extname(filename).toLowerCase();
var minifierOpts = options.minifier,
minify = { requested: true, options: DEFAULT_MINIFY_OPTIONS };
return extensions.indexOf(file_extension) > -1;
if (options.minifyAppliesTo) {
minify.config = { appliesTo: options.minifyAppliesTo };
} else if (minifierOpts && minifierOpts.extensions) {
var extensions = minifierOpts.extensions._ || options.minifier.extensions;
minify.config = { appliesTo: { includeExtensions: extensions } };
}
if (options.minifyOptions) {
minify.options = options.minifyOptions;
} else if (minifierOpts && minifierOpts.options) {
minify.options = minifierOpts.options;
}
return minify;
}

@@ -153,6 +156,8 @@

function minify(filename, contents, options) {
var minifier = getMinifierOptions(options);
var minifier = getMinifyOptions(options);
if (minifier.requested && hasStringifiableExtension(filename, minifier.extensions)) {
return htmlMinifier.minify(contents, minifier.options);
if (minifier.requested) {
if (!tools.skipFile(filename, minifier.config, MINIFY_TRANSFORM_OPTIONS)) {
return htmlMinifier.minify(contents, minifier.options);
}
}

@@ -259,7 +264,6 @@

module.exports.TRANSFORM_OPTIONS = TRANSFORM_OPTIONS;
module.exports.hasStringifiableExtension = hasStringifiableExtension;
module.exports.minify = minify;
module.exports.getMinifierOptions = getMinifierOptions;
module.exports.DEFAULT_MINIFIER_EXTENSIONS = DEFAULT_MINIFIER_EXTENSIONS;
module.exports.DEFAULT_MINIFIER_OPTIONS = DEFAULT_MINIFIER_OPTIONS;
module.exports.getMinifyOptions = getMinifyOptions;
module.exports.MINIFY_TRANSFORM_OPTIONS = MINIFY_TRANSFORM_OPTIONS;
module.exports.DEFAULT_MINIFY_OPTIONS = DEFAULT_MINIFY_OPTIONS;
}

@@ -72,4 +72,4 @@ /* jshint expr: true */

minify: true,
minifier: {
extensions: ['.xxx']
minifyAppliesTo: {
includeExtensions: ['.xxx']
}

@@ -76,0 +76,0 @@ });

@@ -24,5 +24,6 @@ /* jshint expr: true */

it('should have default minifier extensions', function () {
var extensions = Stringify.DEFAULT_MINIFIER_EXTENSIONS;
extensions.should.be.an.Array;
extensions.length.should.be.exactly(5);
var extensions = Stringify.MINIFY_TRANSFORM_OPTIONS;
extensions.should.be.an.Object;
extensions.includeExtensions.should.be.an.Array;
extensions.includeExtensions.length.should.be.exactly(5);
});

@@ -36,3 +37,3 @@

it('should not minify html content because minification is not requested', function () {
it('should not minify html content when minification is not requested', function () {
Stringify.minify('some.html', this.givenHtml, {

@@ -43,10 +44,22 @@ minify: false

it('should not minify html content because extension is not supported', function () {
it('should not minify html content when extension is excluded', function () {
Stringify.minify('some.html', this.givenHtml, {
minify: true,
minifier: {
extensions: ['foobar']
}
minifyAppliesTo: { includeExtensions: ['.foo'] }
}).should.be.exactly(this.givenHtml);
});
it('should minify custom content when extension is included', function () {
Stringify.minify('some.ant', this.givenHtml, {
minify: true,
minifyAppliesTo: { includeExtensions: ['.ant'] }
}).should.be.exactly(this.expectedHtml);
});
it('should not minify custom content when extension is excluded', function () {
Stringify.minify('some.soap', this.givenHtml, {
minify: true,
minifyAppliesTo: { includeExtensions: ['.xml'] }
}).should.be.exactly(this.givenHtml);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc