Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-replace-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-replace-webpack-plugin - npm Package Compare versions

Comparing version 2.2.8 to 2.5.0

74

index.js

@@ -1,10 +0,6 @@

function HtmlReplaceWebpackPlugin(options)
{
function HtmlReplaceWebpackPlugin(options) {
options = Array.isArray(options) ? options : [options]
options.forEach(function(option)
{
if(typeof option.pattern == 'undefined' ||
typeof option.replacement == 'undefined')
{
options.forEach(option => {
if (typeof option.pattern == 'undefined' || typeof option.replacement == 'undefined') {
throw new Error('Both `pattern` and `replacement` options must be defined!')

@@ -14,50 +10,42 @@ }

this.replace = function(htmlData)
{
options.forEach(function(option)
{
if(typeof option.replacement === 'function')
{
var matches = null;
var isPatternValid = true;
try {
new RegExp(option.pattern);
} catch(e) {
isPatternValid = false;
}
this.replace = function(htmlPluginData, callback) {
options.forEach(option => {
if (typeof option.replacement === 'function') {
var matches = null
var isPatternValid = true
try {
new RegExp(option.pattern)
} catch (e) {
isPatternValid = false
}
if(!isPatternValid) throw new Error("Invalid `pattern` option provided, it must be a valid regex.");
while((matches = option.pattern.exec(htmlData)) != null)
{
if (!isPatternValid) throw new Error("Invalid `pattern` option provided, it must be a valid regex.")
while ((matches = option.pattern.exec(htmlPluginData.html)) != null) {
var replacement = option.replacement.apply(null, matches)
// matches[0]: matching content string
htmlData = htmlData.replace(matches[0], replacement)
htmlPluginData.html = htmlPluginData.html.replace(matches[0], replacement)
}
} else {
// htmlPluginData.html.replace(option.pattern, option.replacement)
htmlPluginData.html = htmlPluginData.html.split(option.pattern).join(option.replacement)
}
else
{
// htmlData = htmlData.replace(option.pattern, option.replacement)
htmlData = htmlData.split(option.pattern).join(option.replacement)
}
})
return htmlData
callback(null, htmlPluginData)
}
}
HtmlReplaceWebpackPlugin.prototype.apply = function(compiler)
{
var _this = this
compiler.plugin('compilation', function(compilation)
{
// console.log('The compiler is starting a new compilation...')
compilation.plugin('html-webpack-plugin-before-html-processing',
function(htmlPluginData, callback)
{
htmlPluginData.html = _this.replace(htmlPluginData.html)
callback(null, htmlPluginData)
})
})
HtmlReplaceWebpackPlugin.prototype.apply = function(compiler) {
if (compiler.hooks) {
compiler.hooks.compilation.tap('HtmlReplaceWebpackPlugin', compilation => {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync('html-webpack-plugin-before-html-processing', this.replace)
})
} else {
compiler.plugin('compilation', compilation => {
compilation.plugin('html-webpack-plugin-before-html-processing', this.replace)
})
}
}
module.exports = HtmlReplaceWebpackPlugin
{
"name": "html-replace-webpack-plugin",
"version": "2.2.8",
"version": "2.5.0",
"description": "A Webpack plugin for replace HTML contents with custom pattern string or regex.",

@@ -5,0 +5,0 @@ "main": "index.js",

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