12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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')
- 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)
-
- .replace(CAMEL_CASE_REGEXP, '$1 $2')
-
- .replace(CAMEL_CASE_UPPER_REGEXP, '$1 $2')
-
- .replace(NON_WORD_REGEXP, replace)
-
- return lowerCase(str, locale)
- }
|