mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Tiny performance improvement by not compiling regular expression each time (#3479)
This commit is contained in:
committed by
John-David Dalton
parent
424d9fc34e
commit
e23c874272
@@ -1,5 +1,7 @@
|
|||||||
import words from './words.js'
|
import words from './words.js'
|
||||||
|
|
||||||
|
const reQuotes = /['\u2019]/g
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts `string`, as space separated words, to lower case.
|
* Converts `string`, as space separated words, to lower case.
|
||||||
*
|
*
|
||||||
@@ -20,7 +22,7 @@ import words from './words.js'
|
|||||||
* // => 'foo bar'
|
* // => 'foo bar'
|
||||||
*/
|
*/
|
||||||
const lowerCase = (string) => (
|
const lowerCase = (string) => (
|
||||||
words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => (
|
words(`${string}`.replace(reQuotes, '')).reduce((result, word, index) => (
|
||||||
result + (index ? ' ' : '') + word.toLowerCase()
|
result + (index ? ' ' : '') + word.toLowerCase()
|
||||||
), '')
|
), '')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user