Skip to content

Commit

Permalink
Refactor variable names to decrease line lenghts
Browse files Browse the repository at this point in the history
  • Loading branch information
frederfred committed Feb 3, 2017
1 parent 89f4e2d commit ea025da
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,28 @@ function parameterize(str, options) {
const opts = Object.assign({}, defaultOptions, options);

// Replaces non-ASCII characters with an ASCII approximation
let parameterizedString = transliterate(str);
let output = transliterate(str);

// Convert unwanted chars into the separator
parameterizedString = parameterizedString.replace(/[^a-z0-9-_]/gi, opts.separator || '');
output = output.replace(/[^a-z0-9-_]/gi, opts.separator || '');

if (opts.separator) {
const escapedSeparator = escapeRegExp(String(opts.separator));
const maxOneSeparatorRegExp = new RegExp(`${escapedSeparator}{2,}`, 'g');
const trimSeparatorRegExp = new RegExp(`^${escapedSeparator}|${escapedSeparator}$`, 'g');
const escapedSep = escapeRegExp(String(opts.separator));
const maxOneSepRegExp = new RegExp(`${escapedSep}{2,}`, 'g');
const trimSepRegExp = new RegExp(`^${escapedSep}|${escapedSep}$`, 'g');

// No more than one of the separator in a row.
parameterizedString = parameterizedString.replace(maxOneSeparatorRegExp, opts.separator);
output = output.replace(maxOneSepRegExp, opts.separator);

// Remove leading/trailing separator.
parameterizedString = parameterizedString.replace(trimSeparatorRegExp, '');
output = output.replace(trimSepRegExp, '');
}

if (!opts.preserveCase) {
parameterizedString = parameterizedString.toLowerCase();
output = output.toLowerCase();
}

return parameterizedString;
return output;
}

module.exports = parameterize;

0 comments on commit ea025da

Please sign in to comment.