Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,27 +1,64 @@
'use strict';
module.exports = function () {
var str = [].map.call(arguments, function (str) {
return str.trim();
}).filter(function (str) {
return str.length;
}).join('-');
if (!str.length) {
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 || !(/[_.\- ]+/).test(str) ) {
if (str[0] === str[0].toLowerCase() && str.slice(1) !== str.slice(1).toLowerCase()) {
return str;
}
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, function (m, p1) {
return p1.toUpperCase();
});
.replace(/^[_.\- ]+/, '')
.toLowerCase()
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
};

View File

@@ -1,46 +1,45 @@
{
"_args": [
[
"camelcase@1.2.1",
"camelcase@4.1.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
]
],
"_from": "camelcase@1.2.1",
"_id": "camelcase@1.2.1",
"_from": "camelcase@4.1.0",
"_id": "camelcase@4.1.0",
"_inBundle": false,
"_integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=",
"_integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
"_location": "/webpack/camelcase",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "camelcase@1.2.1",
"raw": "camelcase@4.1.0",
"name": "camelcase",
"escapedName": "camelcase",
"rawSpec": "1.2.1",
"rawSpec": "4.1.0",
"saveSpec": null,
"fetchSpec": "1.2.1"
"fetchSpec": "4.1.0"
},
"_requiredBy": [
"/webpack/uglify-js/yargs"
],
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
"_spec": "1.2.1",
"_requiredBy": [],
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"_spec": "4.1.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/camelcase/issues"
},
"description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar",
"devDependencies": {
"ava": "0.0.4"
"ava": "*",
"xo": "*"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"files": [
"index.js"
@@ -67,7 +66,10 @@
"url": "git+https://github.com/sindresorhus/camelcase.git"
},
"scripts": {
"test": "node test.js"
"test": "xo && ava"
},
"version": "1.2.1"
"version": "4.1.0",
"xo": {
"esnext": true
}
}

View File

@@ -5,7 +5,7 @@
## Install
```sh
```
$ npm install --save camelcase
```
@@ -13,44 +13,45 @@ $ npm install --save camelcase
## Usage
```js
var camelCase = require('camelcase');
const camelCase = require('camelcase');
camelCase('foo-bar');
//=> fooBar
//=> 'fooBar'
camelCase('foo_bar');
//=> fooBar
//=> 'fooBar'
camelCase('Foo-Bar');
//=> fooBar
//=> 'fooBar'
camelCase('--foo.bar');
//=> fooBar
//=> 'fooBar'
camelCase('__foo__bar__');
//=> fooBar
//=> 'fooBar'
camelCase('foo bar');
//=> fooBar
//=> 'fooBar'
console.log(process.argv[3]);
//=> --foo-bar
//=> '--foo-bar'
camelCase(process.argv[3]);
//=> fooBar
//=> 'fooBar'
camelCase('foo', 'bar');
//=> fooBar
//=> 'fooBar'
camelCase('__foo__', '--bar');
//=> fooBar
//=> 'fooBar'
```
## Related
See [`decamelize`](https://github.com/sindresorhus/decamelize) for the inverse.
- [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
- [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)