mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
R=jacktfranklin@chromium.org Bug: 1213034 Change-Id: I5da8225f60b53870a1c67d6b5d02a464c08f4eb2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2917088 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
var lowerCase = require('lower-case')
|
|
|
|
var NON_WORD_REGEXP = require('./vendor/non-word-regexp')
|
|
var CAMEL_CASE_REGEXP = require('./vendor/camel-case-regexp')
|
|
var CAMEL_CASE_UPPER_REGEXP = require('./vendor/camel-case-upper-regexp')
|
|
|
|
/**
|
|
* Sentence case a string.
|
|
*
|
|
* @param {string} str
|
|
* @param {string} locale
|
|
* @param {string} replacement
|
|
* @return {string}
|
|
*/
|
|
module.exports = function (str, locale, replacement) {
|
|
if (str == null) {
|
|
return ''
|
|
}
|
|
|
|
replacement = typeof replacement !== 'string' ? ' ' : replacement
|
|
|
|
function replace (match, index, value) {
|
|
if (index === 0 || index === (value.length - match.length)) {
|
|
return ''
|
|
}
|
|
|
|
return replacement
|
|
}
|
|
|
|
str = String(str)
|
|
// Support camel case ("camelCase" -> "camel Case").
|
|
.replace(CAMEL_CASE_REGEXP, '$1 $2')
|
|
// Support odd camel case ("CAMELCase" -> "CAMEL Case").
|
|
.replace(CAMEL_CASE_UPPER_REGEXP, '$1 $2')
|
|
// Remove all non-word characters and replace with a single space.
|
|
.replace(NON_WORD_REGEXP, replace)
|
|
|
|
// Lower case the entire string.
|
|
return lowerCase(str, locale)
|
|
}
|