camelcase
Advanced tools
Comparing version 5.0.0 to 5.1.0
24
index.js
'use strict'; | ||
const preserveCamelCase = input => { | ||
const preserveCamelCase = string => { | ||
let isLastCharLower = false; | ||
@@ -8,7 +8,7 @@ let isLastCharUpper = false; | ||
for (let i = 0; i < input.length; i++) { | ||
const c = input[i]; | ||
for (let i = 0; i < string.length; i++) { | ||
const character = string[i]; | ||
if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) { | ||
input = input.slice(0, i) + '-' + input.slice(i); | ||
if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) { | ||
string = string.slice(0, i) + '-' + string.slice(i); | ||
isLastCharLower = false; | ||
@@ -18,4 +18,4 @@ isLastLastCharUpper = isLastCharUpper; | ||
i++; | ||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) { | ||
input = input.slice(0, i - 1) + '-' + input.slice(i - 1); | ||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(character) && character.toLowerCase() === character) { | ||
string = string.slice(0, i - 1) + '-' + string.slice(i - 1); | ||
isLastLastCharUpper = isLastCharUpper; | ||
@@ -25,12 +25,16 @@ isLastCharUpper = false; | ||
} else { | ||
isLastCharLower = c.toLowerCase() === c; | ||
isLastCharLower = character.toLowerCase() === character; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = c.toUpperCase() === c; | ||
isLastCharUpper = character.toUpperCase() === character; | ||
} | ||
} | ||
return input; | ||
return string; | ||
}; | ||
module.exports = (input, options) => { | ||
if (!(typeof input === 'string' || Array.isArray(input))) { | ||
throw new TypeError('Expected the input to be `string | string[]`'); | ||
} | ||
options = Object.assign({ | ||
@@ -37,0 +41,0 @@ pascalCase: false |
{ | ||
"name": "camelcase", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`", | ||
@@ -38,5 +38,5 @@ "license": "MIT", | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
"ava": "^1.2.1", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -5,3 +5,16 @@ # camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase) | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-camelcase?utm_source=npm-camelcase&utm_medium=referral&utm_campaign=readme">Get professional support for 'camelcase' with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> | ||
--- | ||
## Install | ||
@@ -72,2 +85,7 @@ | ||
## Security | ||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. | ||
## Related | ||
@@ -74,0 +92,0 @@ |
5948
60
100