Skip to content

Commit

Permalink
perf: trim keys once (#2194)
Browse files Browse the repository at this point in the history
  • Loading branch information
VIKTORVAV99 committed May 20, 2024
1 parent 20011af commit c5c6291
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ function parseFormatStr(formatStr) {
const opts = optStr.split(';');

opts.forEach((opt) => {
if (!opt) return;
const [key, ...rest] = opt.split(':');
const val = rest
.join(':')
.trim()
.replace(/^'+|'+$/g, ''); // trim and replace ''

if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
if (val === 'false') formatOptions[key.trim()] = false;
if (val === 'true') formatOptions[key.trim()] = true;
// eslint-disable-next-line no-restricted-globals
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
if (opt) {
const [key, ...rest] = opt.split(':');
const val = rest
.join(':')
.trim()
.replace(/^'+|'+$/g, ''); // trim and replace ''

const trimmedKey = key.trim();

if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
if (val === 'false') formatOptions[trimmedKey] = false;
if (val === 'true') formatOptions[trimmedKey] = true;
// eslint-disable-next-line no-restricted-globals
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
}
});
}
}
Expand Down

0 comments on commit c5c6291

Please sign in to comment.