New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

minify-html-literals

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minify-html-literals - npm Package Compare versions

Comparing version 1.3.2 to 1.3.4

src/types/clean-css/index.d.ts

17

CHANGELOG.md

@@ -5,2 +5,19 @@ # Changelog

### [1.3.4](https://github.com/asyncLiz/minify-html-literals/compare/v1.3.3...v1.3.4) (2021-03-09)
### Bug Fixes
* build errors ([ee4d596](https://github.com/asyncLiz/minify-html-literals/commit/ee4d596c2797cea335af2c43ba0368ec3d6fa518))
### [1.3.3](https://github.com/asyncLiz/minify-html-literals/compare/v1.3.2...v1.3.3) (2021-03-09)
### Bug Fixes
* html attribute placeholders throwing split error [#28](https://github.com/asyncLiz/minify-html-literals/issues/28) ([b1e14dc](https://github.com/asyncLiz/minify-html-literals/commit/b1e14dca1a5ed9e6599193f474992729953f885d))
* minify multiline svg elements ([9f37d2d](https://github.com/asyncLiz/minify-html-literals/commit/9f37d2d6442a6533a90c1728f80aeb78d6060d9b))
* parse errors with JS comments in HTML attributes with no quotes ([0f5a842](https://github.com/asyncLiz/minify-html-literals/commit/0f5a842c54f3514c72c79eaf6749f15770818550))
* spaces in pseudo classes (like ::part) are not removed ([85526fc](https://github.com/asyncLiz/minify-html-literals/commit/85526fcb889e288e1adbb5c7ff9feca41d45acff)), closes [#26](https://github.com/asyncLiz/minify-html-literals/issues/26)
### [1.3.2](https://github.com/asyncLiz/minify-html-literals/compare/v1.3.1...v1.3.2) (2020-08-18)

@@ -7,0 +24,0 @@

17

index.js
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./src/minifyHTMLLiterals"));
__export(require("./src/strategy"));
__exportStar(require("./src/minifyHTMLLiterals"), exports);
__exportStar(require("./src/strategy"), exports);
//# sourceMappingURL=index.js.map
{
"name": "minify-html-literals",
"version": "1.3.2",
"version": "1.3.4",
"description": "Minify HTML template literal strings",

@@ -23,3 +23,3 @@ "main": "index.js",

"scripts": {
"clean": "rimraf \"src/**/*.{js*,d.ts}\" && rimraf \"index.{js*,d.ts}\" && rimraf \"{.nyc_output/,coverage/}\"",
"clean": "tsc --build --clean && rimraf \"{.nyc_output/,coverage/}\"",
"prebuild": "npm run clean",

@@ -64,3 +64,3 @@ "build": "tsc",

"magic-string": "^0.25.0",
"parse-literals": "^1.2.0"
"parse-literals": "^1.2.1"
},

@@ -71,3 +71,3 @@ "devDependencies": {

"@types/mocha": "^5.2.5",
"@types/node": "^10.5.2",
"@types/node": "^14.14.32",
"@types/sinon": "^5.0.1",

@@ -86,4 +86,4 @@ "chai": "^4.1.2",

"ts-node": "^7.0.0",
"typescript": "^2.9.2"
"typescript": "^4.2.3"
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.minifyHTMLLiterals = exports.defaultValidation = exports.defaultShouldMinifyCSS = exports.defaultShouldMinify = exports.defaultGenerateSourceMap = void 0;
const magic_string_1 = require("magic-string");

@@ -4,0 +5,0 @@ const parse_literals_1 = require("parse-literals");

@@ -0,1 +1,2 @@

/// <reference types="node" />
import * as CleanCSS from 'clean-css';

@@ -75,2 +76,15 @@ import { Options as HTMLOptions } from 'html-minifier';

export declare const defaultStrategy: Strategy<HTMLOptions, CleanCSS.Options>;
export declare function adjustMinifyCSSOptions(options?: CleanCSS.Options): CleanCSS.Options;
export declare function adjustMinifyCSSOptions(options?: CleanCSS.Options): {
level: import("clean-css/lib/options/optimization-level").OptimizationLevelOptions;
compatibility?: CleanCSS.CompatibilityOptions | "*" | "ie9" | "ie8" | "ie7" | undefined;
fetch?: ((uri: string, inlineRequest: import("http").RequestOptions | import("https").RequestOptions, inlineTimeout: number, done: (message: string | number, body: string) => void) => void) | undefined;
format?: false | CleanCSS.FormatOptions | "beautify" | "keep-breaks" | undefined;
inline?: false | readonly string[] | undefined;
inlineRequest?: import("http").RequestOptions | import("https").RequestOptions | undefined;
inlineTimeout?: number | undefined;
rebase?: boolean | undefined;
rebaseTo?: string | undefined;
returnPromise?: boolean | undefined;
sourceMap?: boolean | undefined;
sourceMapInlineSources?: boolean | undefined;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adjustMinifyCSSOptions = exports.defaultStrategy = exports.defaultMinifyOptions = exports.defaultMinifyCSSOptions = void 0;
const CleanCSS = require("clean-css");
const optimization_level_1 = require("clean-css/lib/options/optimization-level");
const html_minifier_1 = require("html-minifier");

@@ -62,78 +64,102 @@ /**

}
let adjustedMinifyCSSOptions = false;
if (minifyCSSOptions) {
minifyCSSOptions = adjustMinifyCSSOptions(minifyCSSOptions);
adjustedMinifyCSSOptions = adjustMinifyCSSOptions(minifyCSSOptions);
}
return html_minifier_1.minify(html, {
let result = html_minifier_1.minify(html, {
...options,
minifyCSS: minifyCSSOptions
minifyCSS: adjustedMinifyCSSOptions
});
if (options.collapseWhitespace) {
// html-minifier does not support removing newlines inside <svg>
// attributes. Support this, but be careful not to remove newlines from
// supported areas (such as within <pre> and <textarea> tags).
const matches = Array.from(result.matchAll(/<svg/g)).reverse();
for (const match of matches) {
const startTagIndex = match.index;
const closeTagIndex = result.indexOf('</svg', startTagIndex);
if (closeTagIndex < 0) {
// Malformed SVG without a closing tag
continue;
}
const start = result.substring(0, startTagIndex);
let svg = result.substring(startTagIndex, closeTagIndex);
const end = result.substring(closeTagIndex);
svg = svg.replace(/\r?\n/g, '');
result = start + svg + end;
}
}
if (adjustedMinifyCSSOptions &&
adjustedMinifyCSSOptions.level[optimization_level_1.OptimizationLevel.One].tidySelectors) {
// Fix https://github.com/jakubpawlowicz/clean-css/issues/996
result = fixCleanCssTidySelectors(html, result);
}
return result;
},
minifyCSS(css, options = {}) {
const output = new CleanCSS(adjustMinifyCSSOptions(options)).minify(css);
const adjustedOptions = adjustMinifyCSSOptions(options);
const output = new CleanCSS(adjustedOptions).minify(css);
if (output.errors && output.errors.length) {
throw new Error(output.errors.join('\n\n'));
}
if (adjustedOptions.level[optimization_level_1.OptimizationLevel.One].tidySelectors) {
output.styles = fixCleanCssTidySelectors(css, output.styles);
}
return output.styles;
},
splitHTMLByPlaceholder(html, placeholder) {
const parts = html.split(placeholder);
// Make the last character (a semicolon) optional. See above.
// return html.split(new RegExp(`${placeholder}?`, 'g'));
return html.split(placeholder);
if (placeholder.endsWith(';')) {
const withoutSemicolon = placeholder.substring(0, placeholder.length - 1);
for (let i = parts.length - 1; i >= 0; i--) {
parts.splice(i, 1, ...parts[i].split(withoutSemicolon));
}
}
return parts;
}
};
function adjustMinifyCSSOptions(options = {}) {
const levelOne = {
transform(_property, value) {
if (value.startsWith('@TEMPLATE_EXPRESSION') && !value.endsWith(';')) {
// The CSS minifier has removed the semicolon from the placeholder
// and we need to add it back.
return `${value};`;
}
else {
return value;
}
const level = optimization_level_1.optimizationLevelFrom(options.level);
const originalTransform = typeof options.level === 'object' &&
options.level[1] &&
options.level[1].transform;
level[optimization_level_1.OptimizationLevel.One].transform = (property, value) => {
if (value.startsWith('@TEMPLATE_EXPRESSION') && !value.endsWith(';')) {
// The CSS minifier has removed the semicolon from the placeholder
// and we need to add it back.
return (value = `${value};`);
}
return originalTransform ? originalTransform(property, value) : value;
};
const level = options.level;
if (typeof level === 'undefined' || level === 1) {
return {
...options,
level: {
1: levelOne
}
};
}
else if (level === 2) {
return {
...options,
level: {
1: levelOne,
2: { all: true }
}
};
}
else if (level === 0) {
return {
...options,
level: 0
};
}
else {
const newLevel = { ...level };
if (!newLevel[1]) {
newLevel[1] = levelOne;
return {
...options,
level
};
}
exports.adjustMinifyCSSOptions = adjustMinifyCSSOptions;
function fixCleanCssTidySelectors(original, result) {
const regex = /(::?.+\((.*)\))[\s\r\n]*{/gm;
let match;
while ((match = regex.exec(original)) != null) {
const pseudoClass = match[1];
const parameters = match[2];
if (!parameters.match(/\s/)) {
continue;
}
else {
newLevel[1] = {
...levelOne,
...newLevel[1]
};
const parametersWithoutSpaces = parameters.replace(/\s/g, '');
const resultPseudoClass = pseudoClass.replace(parameters, parametersWithoutSpaces);
const resultStartIndex = result.indexOf(resultPseudoClass);
if (resultStartIndex < 0) {
continue;
}
return {
...options,
level: newLevel
};
const resultEndIndex = resultStartIndex + resultPseudoClass.length;
// Restore the original pseudo class with spaces
result =
result.substring(0, resultStartIndex) +
pseudoClass +
result.substring(resultEndIndex);
}
return result;
}
exports.adjustMinifyCSSOptions = adjustMinifyCSSOptions;
//# sourceMappingURL=strategy.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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