aboutsummaryrefslogtreecommitdiff
path: root/node_modules/camelcase/index.js
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/camelcase/index.js
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/camelcase/index.js')
-rw-r--r--node_modules/camelcase/index.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/camelcase/index.js b/node_modules/camelcase/index.js
new file mode 100644
index 0000000..c8492a2
--- /dev/null
+++ b/node_modules/camelcase/index.js
@@ -0,0 +1,64 @@
+'use strict';
+
+function preserveCamelCase(str) {
+ let isLastCharLower = false;
+ let isLastCharUpper = false;
+ let isLastLastCharUpper = false;
+
+ for (let i = 0; i < str.length; i++) {
+ const c = str[i];
+
+ if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
+ str = str.substr(0, i) + '-' + str.substr(i);
+ isLastCharLower = false;
+ isLastLastCharUpper = isLastCharUpper;
+ isLastCharUpper = true;
+ i++;
+ } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
+ str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
+ isLastLastCharUpper = isLastCharUpper;
+ isLastCharUpper = false;
+ isLastCharLower = true;
+ } else {
+ isLastCharLower = c.toLowerCase() === c;
+ isLastLastCharUpper = isLastCharUpper;
+ isLastCharUpper = c.toUpperCase() === c;
+ }
+ }
+
+ return str;
+}
+
+module.exports = function (str) {
+ if (arguments.length > 1) {
+ str = Array.from(arguments)
+ .map(x => x.trim())
+ .filter(x => x.length)
+ .join('-');
+ } else {
+ str = str.trim();
+ }
+
+ if (str.length === 0) {
+ return '';
+ }
+
+ if (str.length === 1) {
+ return str.toLowerCase();
+ }
+
+ if (/^[a-z0-9]+$/.test(str)) {
+ return str;
+ }
+
+ const hasUpperCase = str !== str.toLowerCase();
+
+ if (hasUpperCase) {
+ str = preserveCamelCase(str);
+ }
+
+ return str
+ .replace(/^[_.\- ]+/, '')
+ .toLowerCase()
+ .replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
+};