[Pkg-javascript-commits] [node-camelcase] 01/04: Imported Upstream version 3.0.0

Jonathan Horn jonathanh-guest at moszumanska.debian.org
Sat Jun 4 20:57:53 UTC 2016


This is an automated email from the git hooks/post-receive script.

jonathanh-guest pushed a commit to branch master
in repository node-camelcase.

commit 10d3ee979f86b3ac1e31faf8757b0a914eac04d4
Author: Jonathan Horn <info at autoit4you.de>
Date:   Sat Jun 4 20:50:50 2016 +0200

    Imported Upstream version 3.0.0
---
 .editorconfig  | 15 +++++++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .travis.yml    |  7 +++++++
 index.js       | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 39 +++++++++++++++++++++++++++++++++++++++
 readme.md      | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 244 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..86c8f59
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[package.json]
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..a78e23d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+sudo: false
+language: node_js
+node_js:
+  - '5'
+  - '4'
+  - '0.12'
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..5670f73
--- /dev/null
+++ b/index.js
@@ -0,0 +1,56 @@
+'use strict';
+
+function preserveCamelCase(str) {
+	var isLastCharLower = false;
+
+	for (var i = 0; i < str.length; i++) {
+		var c = str.charAt(i);
+
+		if (isLastCharLower && (/[a-zA-Z]/).test(c) && c.toUpperCase() === c) {
+			str = str.substr(0, i) + '-' + str.substr(i);
+			isLastCharLower = false;
+			i++;
+		} else {
+			isLastCharLower = (c.toLowerCase() === c);
+		}
+	}
+
+	return str;
+}
+
+module.exports = function () {
+	var str = [].map.call(arguments, function (str) {
+		return str.trim();
+	}).filter(function (str) {
+		return str.length;
+	}).join('-');
+
+	if (!str.length) {
+		return '';
+	}
+
+	if (str.length === 1) {
+		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);
+		}
+
+		return str;
+	}
+
+	str = preserveCamelCase(str);
+
+	return str
+	.replace(/^[_.\- ]+/, '')
+	.toLowerCase()
+	.replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
+		return p1.toUpperCase();
+	});
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a404754
--- /dev/null
+++ b/package.json
@@ -0,0 +1,39 @@
+{
+  "name": "camelcase",
+  "version": "3.0.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"
+  },
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "camelcase",
+    "camel-case",
+    "camel",
+    "case",
+    "dash",
+    "hyphen",
+    "dot",
+    "underscore",
+    "separator",
+    "string",
+    "text",
+    "convert"
+  ],
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..080b2a1
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,57 @@
+# camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase)
+
+> Convert a dash/dot/underscore/space separated string to camelCase: `foo-bar` → `fooBar`
+
+
+## Install
+
+```
+$ npm install --save camelcase
+```
+
+
+## Usage
+
+```js
+const camelCase = require('camelcase');
+
+camelCase('foo-bar');
+//=> 'fooBar'
+
+camelCase('foo_bar');
+//=> 'fooBar'
+
+camelCase('Foo-Bar');
+//=> 'fooBar'
+
+camelCase('--foo.bar');
+//=> 'fooBar'
+
+camelCase('__foo__bar__');
+//=> 'fooBar'
+
+camelCase('foo bar');
+//=> 'fooBar'
+
+console.log(process.argv[3]);
+//=> '--foo-bar'
+camelCase(process.argv[3]);
+//=> 'fooBar'
+
+camelCase('foo', 'bar');
+//=> 'fooBar'
+
+camelCase('__foo__', '--bar');
+//=> 'fooBar'
+```
+
+
+## Related
+
+- [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)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..258e6aa
--- /dev/null
+++ b/test.js
@@ -0,0 +1,47 @@
+import test from 'ava';
+import fn 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#');
+});

-- 
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