diff options
Diffstat (limited to 'node_modules/camelcase')
-rw-r--r-- | node_modules/camelcase/index.js | 62 | ||||
-rw-r--r-- | node_modules/camelcase/package.json | 9 | ||||
-rw-r--r-- | node_modules/camelcase/readme.md | 2 |
3 files changed, 42 insertions, 31 deletions
diff --git a/node_modules/camelcase/index.js b/node_modules/camelcase/index.js index 5670f73f2..c8492a228 100644 --- a/node_modules/camelcase/index.js +++ b/node_modules/camelcase/index.js @@ -1,31 +1,45 @@ 'use strict'; function preserveCamelCase(str) { - var isLastCharLower = false; + let isLastCharLower = false; + let isLastCharUpper = false; + let isLastLastCharUpper = false; - for (var i = 0; i < str.length; i++) { - var c = str.charAt(i); + for (let i = 0; i < str.length; 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) { + str = str.substr(0, i - 1) + '-' + str.substr(i - 1); + isLastLastCharUpper = isLastCharUpper; + isLastCharUpper = false; + isLastCharLower = true; } else { - isLastCharLower = (c.toLowerCase() === c); + isLastCharLower = c.toLowerCase() === c; + isLastLastCharUpper = isLastCharUpper; + isLastCharUpper = c.toUpperCase() === c; } } return str; } -module.exports = function () { - var str = [].map.call(arguments, function (str) { - return str.trim(); - }).filter(function (str) { - return str.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) { + if (str.length === 0) { return ''; } @@ -33,24 +47,18 @@ module.exports = function () { return str.toLowerCase(); } - if (!(/[_.\- ]+/).test(str)) { - if (str === str.toUpperCase()) { - return str.toLowerCase(); - } - - if (str[0] !== str[0].toLowerCase()) { - return str[0].toLowerCase() + str.slice(1); - } - + if (/^[a-z0-9]+$/.test(str)) { return str; } - str = preserveCamelCase(str); + const hasUpperCase = str !== str.toLowerCase(); + + if (hasUpperCase) { + str = preserveCamelCase(str); + } return str - .replace(/^[_.\- ]+/, '') - .toLowerCase() - .replace(/[_.\- ]+(\w|$)/g, function (m, p1) { - return p1.toUpperCase(); - }); + .replace(/^[_.\- ]+/, '') + .toLowerCase() + .replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase()); }; diff --git a/node_modules/camelcase/package.json b/node_modules/camelcase/package.json index a404754ee..d4cfe32e1 100644 --- a/node_modules/camelcase/package.json +++ b/node_modules/camelcase/package.json @@ -1,16 +1,16 @@ { "name": "camelcase", - "version": "3.0.0", + "version": "4.1.0", "description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar", "license": "MIT", "repository": "sindresorhus/camelcase", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "http://sindresorhus.com" + "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && ava" @@ -35,5 +35,8 @@ "devDependencies": { "ava": "*", "xo": "*" + }, + "xo": { + "esnext": true } } diff --git a/node_modules/camelcase/readme.md b/node_modules/camelcase/readme.md index 080b2a103..0610dc627 100644 --- a/node_modules/camelcase/readme.md +++ b/node_modules/camelcase/readme.md @@ -54,4 +54,4 @@ camelCase('__foo__', '--bar'); ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) |