aboutsummaryrefslogtreecommitdiff
path: root/node_modules/no-case/no-case.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/no-case/no-case.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/no-case/no-case.js')
-rw-r--r--node_modules/no-case/no-case.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/node_modules/no-case/no-case.js b/node_modules/no-case/no-case.js
new file mode 100644
index 00000000..cf24540f
--- /dev/null
+++ b/node_modules/no-case/no-case.js
@@ -0,0 +1,40 @@
+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)
+}