Skip to content

Commit 05e5c65

Browse files
committed
Initial commit
0 parents  commit 05e5c65

13 files changed

+302
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
bower_components/

.jshintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"bitwise": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"globalstrict": true,
6+
"latedef": "nofunc",
7+
"noarg": true,
8+
"undef": true,
9+
"unused": true,
10+
"browser": true,
11+
"jasmine": true,
12+
"globals": {
13+
"angular": true,
14+
"module": true,
15+
"inject": true
16+
}
17+
}

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test/
2+
.editorconfig
3+
.jshintrc
4+
.npmignore
5+
bower.json
6+
karma.conf.js

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Pablo Villoslada Puigcerber
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# angular-camelize-filter
2+
3+
AngularJS filter to convert strings to **lower camel case** replacing non-alphanumeric characters.
4+
5+
## Installation
6+
7+
You can install the filter using [Bower](http://bower.io/):
8+
9+
```bash
10+
$ bower install angular-camelize-filter
11+
```
12+
13+
Or [npm](https://www.npmjs.com/):
14+
15+
```bash
16+
$ npm install angular-camelize-filter
17+
```
18+
19+
Then you have to include it in your HTML:
20+
21+
```html
22+
<script src="bower_components/angular-camelize-filter/camelize.js"></script>
23+
<script src="node_modules/angular-camelize-filter/camelize.js"></script>
24+
```
25+
26+
And inject the module `puigcerber.camelize` as a dependency of your application:
27+
28+
```js
29+
angular.module('webApp', ['puigcerber.camelize']);
30+
```
31+
32+
## Usage
33+
34+
You can use it like any other AngularJS filter:
35+
36+
```html
37+
<p>{{ input | camelize }}</p>
38+
```
39+
40+
### Example
41+
42+
```js
43+
var camelized = $filter('camelize')('angular-camelize-filter');
44+
console.log(camelized); // angularCamelizeFilter
45+
```
46+
47+
## Testing
48+
49+
To run the tests:
50+
51+
```bash
52+
$ npm install
53+
$ npm test
54+
```

bower.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "angular-camelize-filter",
3+
"version": "1.0.0",
4+
"description": "AngularJS filter to convert strings to lower camel case replacing non-alphanumeric characters.",
5+
"main": "camelize.js",
6+
"authors": [
7+
"Pablo Villoslada Puigcerber <[email protected]> (http://pablovilloslada.com/)"
8+
],
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/Puigcerber/angular-camelize-filter"
12+
},
13+
"keywords": [
14+
"AngularJS",
15+
"camelize",
16+
"filter",
17+
"CamelCase",
18+
"lowerCamelCase"
19+
],
20+
"license": "MIT",
21+
"ignore": [
22+
"**/.*",
23+
"node_modules",
24+
"bower_components",
25+
"test",
26+
"karma.conf.js",
27+
"**/*.json",
28+
"index.js"
29+
],
30+
"dependencies": {
31+
"angular": "~1.4.9"
32+
}
33+
}

camelize.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
angular.module('puigcerber.camelize', [])
4+
.filter('camelize', function () {
5+
return function (input) {
6+
if (!input) {
7+
return input;
8+
}
9+
return input.replace(/[^A-Za-z0-9]+(\w|$)/g, function (_, letter) {
10+
return letter.toUpperCase();
11+
}).replace(/^(.)/, function (_, letter) {
12+
return letter.toLowerCase();
13+
});
14+
};
15+
});

camelize.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('angular');
2+
require('./camelize');
3+
module.exports = 'puigcerber.camelize';

karma.conf.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Karma configuration
2+
// Generated on Sun Jan 24 2016 12:28:36 GMT+0100 (CET)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['jasmine'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'node_modules/angular/angular.js',
19+
'node_modules/angular-mocks/angular-mocks.js',
20+
'test/**/*.spec.js',
21+
'camelize.js'
22+
],
23+
24+
25+
// list of files to exclude
26+
exclude: [
27+
],
28+
29+
30+
// preprocess matching files before serving them to the browser
31+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
32+
preprocessors: {
33+
},
34+
35+
36+
// test results reporter to use
37+
// possible values: 'dots', 'progress'
38+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
39+
reporters: ['progress'],
40+
41+
42+
// web server port
43+
port: 9876,
44+
45+
46+
// enable / disable colors in the output (reporters and logs)
47+
colors: true,
48+
49+
50+
// level of logging
51+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
52+
logLevel: config.LOG_INFO,
53+
54+
55+
// enable / disable watching file and executing tests whenever any file changes
56+
autoWatch: true,
57+
58+
59+
// start these browsers
60+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
61+
browsers: ['PhantomJS', 'Chrome'],
62+
63+
64+
// Continuous Integration mode
65+
// if true, Karma captures browsers, runs the tests and exits
66+
singleRun: true,
67+
68+
// Concurrency level
69+
// how many browser should be started simultaneous
70+
concurrency: Infinity
71+
})
72+
};

package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "angular-camelize-filter",
3+
"version": "1.0.0",
4+
"description": "AngularJS filter to convert strings to lower camel case replacing non-alphanumeric characters.",
5+
"author": "Pablo Villoslada Puigcerber <[email protected]> (http://pablovilloslada.com/)",
6+
"main": "index.js",
7+
"scripts": {
8+
"build": "uglifyjs camelize.js -m -o camelize.min.js",
9+
"lint": "jshint camelize.js test; true",
10+
"test": "karma start",
11+
"pretest": "npm run lint"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/Puigcerber/angular-camelize-filter"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/Puigcerber/angular-camelize-filter/issues"
19+
},
20+
"keywords": [
21+
"AngularJS",
22+
"camelize",
23+
"filter",
24+
"CamelCase",
25+
"lowerCamelCase"
26+
],
27+
"license": "MIT",
28+
"devDependencies": {
29+
"angular-mocks": "^1.4.9",
30+
"jasmine-core": "^2.4.1",
31+
"jshint": "^2.9.1",
32+
"karma": "^0.13.19",
33+
"karma-chrome-launcher": "^0.2.2",
34+
"karma-jasmine": "^0.3.6",
35+
"karma-phantomjs-launcher": "^0.2.3",
36+
"phantomjs": "^1.9.19",
37+
"uglify-js": "^2.6.1"
38+
},
39+
"dependencies": {
40+
"angular": "^1.4.9"
41+
}
42+
}

test/camelize.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
describe('Filter: camelize', function () {
4+
5+
beforeEach(module('puigcerber.camelize'));
6+
7+
var camelize;
8+
beforeEach(inject(function ($filter) {
9+
camelize = $filter('camelize');
10+
}));
11+
12+
it('should transform the string to lower camel case', function () {
13+
expect(camelize('Lower Camel Case')).toBe('lowerCamelCase');
14+
expect(camelize('AngularJS')).toBe('angularJS');
15+
});
16+
17+
it('should replace non-alphanumeric characters', function () {
18+
expect(camelize('ng-conf')).toBe('ngConf');
19+
expect(camelize('Angular.io')).toBe('angularIo');
20+
expect(camelize('__private_key__')).toBe('privateKey');
21+
});
22+
23+
});

0 commit comments

Comments
 (0)