[Pkg-javascript-commits] [node-camelcase] 01/04: New upstream version 4.1.0
suman rajan
sumanrajan-guest at moszumanska.debian.org
Sat Nov 11 06:26:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
sumanrajan-guest pushed a commit to branch master
in repository node-camelcase.
commit 0bcfc246d4cf4866ab1f74ea5d6a0539589b5d85
Author: suman <suman at protonmail.com>
Date: Sat Nov 11 06:03:57 2017 +0000
New upstream version 4.1.0
---
.editorconfig | 5 +---
.gitattributes | 1 +
.travis.yml | 4 +--
index.js | 62 +++++++++++++++++++++++------------------
package.json | 9 ++++--
readme.md | 2 +-
test.js | 88 ++++++++++++++++++++++++++++++----------------------------
7 files changed, 90 insertions(+), 81 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 86c8f59..98a761d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
-[package.json]
+[{package.json,*.yml}]
indent_style = space
indent_size = 2
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
index 176a458..391f0a4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
* text=auto
+*.js text eol=lf
diff --git a/.travis.yml b/.travis.yml
index a78e23d..b18bae5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,5 @@
sudo: false
language: node_js
node_js:
- - '5'
+ - '6'
- '4'
- - '0.12'
- - '0.10'
diff --git a/index.js b/index.js
index 5670f73..c8492a2 100644
--- a/index.js
+++ b/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/package.json b/package.json
index a404754..d4cfe32 100644
--- a/package.json
+++ b/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 at 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/readme.md b/readme.md
index 080b2a1..0610dc6 100644
--- a/readme.md
+++ b/readme.md
@@ -54,4 +54,4 @@ camelCase('__foo__', '--bar');
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
index 258e6aa..97461e4 100644
--- a/test.js
+++ b/test.js
@@ -1,47 +1,49 @@
import test from 'ava';
-import fn from './';
+import m from './';
test('camelCase', t => {
- t.is(fn('foo'), 'foo');
- t.is(fn('foo-bar'), 'fooBar');
- t.is(fn('foo-bar-baz'), 'fooBarBaz');
- t.is(fn('foo--bar'), 'fooBar');
- t.is(fn('--foo-bar'), 'fooBar');
- t.is(fn('--foo--bar'), 'fooBar');
- t.is(fn('FOO-BAR'), 'fooBar');
- t.is(fn('FOÈ-BAR'), 'foèBar');
- t.is(fn('-foo-bar-'), 'fooBar');
- t.is(fn('--foo--bar--'), 'fooBar');
- t.is(fn('foo.bar'), 'fooBar');
- t.is(fn('foo..bar'), 'fooBar');
- t.is(fn('..foo..bar..'), 'fooBar');
- t.is(fn('foo_bar'), 'fooBar');
- t.is(fn('__foo__bar__'), 'fooBar');
- t.is(fn('__foo__bar__'), 'fooBar');
- t.is(fn('foo bar'), 'fooBar');
- t.is(fn(' foo bar '), 'fooBar');
- t.is(fn('-'), '-');
- t.is(fn(' - '), '-');
- t.is(fn('fooBar'), 'fooBar');
- t.is(fn('fooBar-baz'), 'fooBarBaz');
- t.is(fn('foìBar-baz'), 'foìBarBaz');
- t.is(fn('fooBarBaz-bazzy'), 'fooBarBazBazzy');
- t.is(fn('FBBazzy'), 'fBBazzy');
- t.is(fn('F'), 'f');
- t.is(fn('FBBÈzzy'), 'fBBÈzzy');
- t.is(fn('FooBar'), 'fooBar');
- t.is(fn('Foo'), 'foo');
- t.is(fn('FOO'), 'foo');
- t.is(fn('foo', 'bar'), 'fooBar');
- t.is(fn('foo', '-bar'), 'fooBar');
- t.is(fn('foo', '-bar', 'baz'), 'fooBarBaz');
- t.is(fn('', ''), '');
- t.is(fn('--'), '');
- t.is(fn(''), '');
- t.is(fn('--__--_--_'), '');
- t.is(fn('---_', '--', '', '-_- '), '');
- t.is(fn('foo bar?'), 'fooBar?');
- t.is(fn('foo bar!'), 'fooBar!');
- t.is(fn('foo bar$'), 'fooBar$');
- t.is(fn('foo-bar#'), 'fooBar#');
+ t.is(m('foo'), 'foo');
+ t.is(m('foo-bar'), 'fooBar');
+ t.is(m('foo-bar-baz'), 'fooBarBaz');
+ t.is(m('foo--bar'), 'fooBar');
+ t.is(m('--foo-bar'), 'fooBar');
+ t.is(m('--foo--bar'), 'fooBar');
+ t.is(m('FOO-BAR'), 'fooBar');
+ t.is(m('FOÈ-BAR'), 'foèBar');
+ t.is(m('-foo-bar-'), 'fooBar');
+ t.is(m('--foo--bar--'), 'fooBar');
+ t.is(m('foo.bar'), 'fooBar');
+ t.is(m('foo..bar'), 'fooBar');
+ t.is(m('..foo..bar..'), 'fooBar');
+ t.is(m('foo_bar'), 'fooBar');
+ t.is(m('__foo__bar__'), 'fooBar');
+ t.is(m('__foo__bar__'), 'fooBar');
+ t.is(m('foo bar'), 'fooBar');
+ t.is(m(' foo bar '), 'fooBar');
+ t.is(m('-'), '-');
+ t.is(m(' - '), '-');
+ t.is(m('fooBar'), 'fooBar');
+ t.is(m('fooBar-baz'), 'fooBarBaz');
+ t.is(m('foìBar-baz'), 'foìBarBaz');
+ t.is(m('fooBarBaz-bazzy'), 'fooBarBazBazzy');
+ t.is(m('FBBazzy'), 'fbBazzy');
+ t.is(m('F'), 'f');
+ t.is(m('FooBar'), 'fooBar');
+ t.is(m('Foo'), 'foo');
+ t.is(m('FOO'), 'foo');
+ t.is(m('foo', 'bar'), 'fooBar');
+ t.is(m('foo', '-bar'), 'fooBar');
+ t.is(m('foo', '-bar', 'baz'), 'fooBarBaz');
+ t.is(m('', ''), '');
+ t.is(m('--'), '');
+ t.is(m(''), '');
+ t.is(m('--__--_--_'), '');
+ t.is(m('---_', '--', '', '-_- '), '');
+ t.is(m('foo bar?'), 'fooBar?');
+ t.is(m('foo bar!'), 'fooBar!');
+ t.is(m('foo bar$'), 'fooBar$');
+ t.is(m('foo-bar#'), 'fooBar#');
+ t.is(m('XMLHttpRequest'), 'xmlHttpRequest');
+ t.is(m('AjaxXMLHttpRequest'), 'ajaxXmlHttpRequest');
+ t.is(m('Ajax-XMLHttpRequest'), 'ajaxXmlHttpRequest');
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-camelcase.git
More information about the Pkg-javascript-commits
mailing list