Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use suffixes in the match string, e.g. @@env.css.darkStyle@@ #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/applause.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ var Applause = function (opts) {
usePrefix: true,
preservePrefix: false,
delimiter: '.',
preserveOrder: false
preserveOrder: false,
detail: false,
suffix: opts.useSuffix === true ? '@@' : '',
useSuffix: false
});
};

Expand Down Expand Up @@ -119,7 +122,7 @@ Applause.prototype.replace = function (content, process) {
expression = true;
} else if (_.isString(match)) {
if (match.length > 0) {
match = new RegExp(opts.prefix + escapeRegExp(match), 'g');
match = new RegExp(opts.prefix + escapeRegExp(match) + opts.suffix, 'g');
} else {
// empty match
return;
Expand Down Expand Up @@ -162,23 +165,23 @@ Applause.prototype.replace = function (content, process) {
content = content.replace(match, replacement);
// save detail data
detail.push({
match: match,
replacement: replacement,
source: pattern.source,
count: count
});
total_count += count;
}
});
// FIXME: always return detailed result
if (detail.length === 0) {
content = false;
}
return {
content: content,
detail: detail,
count: total_count
};
if (opts.detail === true) {
return {
content: content,
detail: detail,
count: total_count
};
}
return content;
};

// static
Expand All @@ -187,7 +190,7 @@ Applause.create = function (opts) {
return new Applause(opts);
};

Applause.version = require('../package.json').version;
Applause.VERSION = require('../package.json').version;

// expose

Expand Down