diff options
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js')
-rw-r--r-- | deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js index e3d2a45620..c8492a2286 100644 --- a/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js +++ b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/camelcase/index.js @@ -6,15 +6,15 @@ function preserveCamelCase(str) { let isLastLastCharUpper = false; for (let i = 0; i < str.length; i++) { - const c = str.charAt(i); + const c = str[i]; - if (isLastCharLower && (/[a-zA-Z]/).test(c) && c.toUpperCase() === c) { + 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) { + } 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; @@ -29,8 +29,15 @@ function preserveCamelCase(str) { return str; } -module.exports = function () { - let str = [].map.call(arguments, x => x.trim()).filter(x => x.length).join('-'); +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 ''; @@ -40,7 +47,15 @@ module.exports = function () { return str.toLowerCase(); } - str = preserveCamelCase(str); + if (/^[a-z0-9]+$/.test(str)) { + return str; + } + + const hasUpperCase = str !== str.toLowerCase(); + + if (hasUpperCase) { + str = preserveCamelCase(str); + } return str .replace(/^[_.\- ]+/, '') |