@existdb/gulp-replace-tmpl
Advanced tools
Comparing version
19
index.js
@@ -162,2 +162,3 @@ const replace = require('gulp-replace') | ||
function GulpReplaceTmpl (replacements, options) { | ||
const _options = options || {} | ||
// required option missing | ||
@@ -167,3 +168,3 @@ if (!replacements) { | ||
} | ||
if (options.prefix && options.prefix.match(/[^a-zA-Z0-9]/)) { | ||
if (_options.prefix && _options.prefix.match(/[^a-zA-Z0-9]/)) { | ||
throw new Error('Invalid prefix, only [a-zA-Z0-9] allowed') | ||
@@ -176,3 +177,3 @@ } | ||
if (!options.prefix && !options.unprefixed) { | ||
if (!_options.prefix && !_options.unprefixed) { | ||
prefix = defaultPrefix | ||
@@ -182,14 +183,14 @@ pattern = defaultPattern | ||
} | ||
if (options.prefix) { | ||
prefix = options.prefix | ||
pattern = new RegExp(`@(${options.prefix}\.)?([a-zA-Z0-9]+)@`, 'g') | ||
handler = getMatchHandlerWithPrefix(options.prefix, mergedReplacements) | ||
if (_options.prefix) { | ||
prefix = _options.prefix | ||
pattern = new RegExp(`@(${_options.prefix}\.)?([a-zA-Z0-9]+)@`, 'g') | ||
handler = getMatchHandlerWithPrefix(_options.prefix, mergedReplacements) | ||
} | ||
if (options.unprefixed) { | ||
if (_options.unprefixed) { | ||
prefix = undefined | ||
pattern = /@([a-zA-Z0-9]+)@/g | ||
handler = getMatchHandler(mergedReplacements, options) | ||
handler = getMatchHandler(mergedReplacements, _options) | ||
} | ||
if (options.debug) { | ||
if (_options.debug) { | ||
console.log('Prefix:', prefix || 'unprefixed') | ||
@@ -196,0 +197,0 @@ console.log('Replacements:', mergedReplacements) |
{ | ||
"name": "@existdb/gulp-replace-tmpl", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Replace placeholders in files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12848
0.34%199
0.51%