-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: bring back v5 perf improvements and add some new ones
- Loading branch information
1 parent
41204bc
commit 288800b
Showing
8 changed files
with
79 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
function toFixedDecimals(value, decimals) { | ||
return value.toFixed(decimals); | ||
} | ||
|
||
function replaceSeparator(value, separator) { | ||
return value.replace('.', separator); | ||
} | ||
|
||
export default function numberFormatter(opts = {}) { | ||
if (opts.separator) { | ||
if (opts.decimals) { | ||
return (value) => | ||
replaceSeparator(toFixedDecimals(value, opts.decimals), opts.separator); | ||
value.toFixed(opts.decimals).replace('.', opts.separator); | ||
} | ||
|
||
return (value) => replaceSeparator(value.toString(), opts.separator); | ||
return (value) => `${value}`.replace('.', opts.separator); | ||
} | ||
|
||
if (opts.decimals) { | ||
return (value) => toFixedDecimals(value, opts.decimals); | ||
return (value) => value.toFixed(opts.decimals); | ||
} | ||
|
||
return (value) => value.toString(); | ||
return (value) => `${value}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
export function getProp(obj, path, defaultValue) { | ||
return obj[path] === undefined ? defaultValue : obj[path]; | ||
const value = obj[path]; | ||
return value === undefined ? defaultValue : value; | ||
} | ||
|
||
export function flattenReducer(acc, arr) { | ||
try { | ||
// This is faster but susceptible to `RangeError: Maximum call stack size exceeded` | ||
acc.push(...arr); | ||
return acc; | ||
} catch (err) { | ||
// Fallback to a slower but safer option | ||
return acc.concat(arr); | ||
} | ||
} | ||
|
||
export function fastJoin(arr, separator) { | ||
let isFirst = true; | ||
return arr.reduce((acc, elem) => { | ||
if (elem === null || elem === undefined) { | ||
elem = ''; | ||
} | ||
|
||
if (isFirst) { | ||
isFirst = false; | ||
return `${elem}`; | ||
} | ||
|
||
return `${acc}${separator}${elem}`; | ||
}, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters