Skip to content

Commit 9af958f

Browse files
committed
Add word separator
Add word separator as a new parameter of the filter. Add .editorconfig file for the coding style. Bump to version 2.2.0. Closes #3
1 parent 264009d commit 9af958f

File tree

8 files changed

+49
-13
lines changed

8 files changed

+49
-13
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
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

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ module.exports = function (grunt) {
7070
grunt.registerTask('default', ['jshint', 'test', 'build']);
7171
grunt.registerTask('build', ['uglify']);
7272
grunt.registerTask('test', ['karma']);
73-
};
73+
};

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,36 @@ angular.module('webApp', ['angular-capitalize-filter']);
3434
You can use it like any other AngularJS filter:
3535

3636
```html
37-
<p>{{ input | capitalize:format }}</p>
37+
<p>{{ input | capitalize:format:separator }}</p>
3838
```
3939

40+
The format and separator are optional parameters. If not specified all the words are capitalized.
41+
42+
### Format
43+
4044
Available formats:
4145

4246
* [all](#all)
4347
* [first](#first)
4448
* [team](#team)
4549

46-
### All
50+
#### All
4751

4852
It capitalizes all the words of a given sentence. As it's the default format you can omit the parameter.
4953

5054
```html
5155
<p>{{ sentence | capitalize:'all' }}</p>
5256
```
5357

54-
### First
58+
#### First
5559

5660
It capitalizes just the first letter of the given sentence.
5761

5862
```html
5963
<p>{{ sentence | capitalize:'first' }}</p>
6064
```
6165

62-
### Team
66+
#### Team
6367

6468
Specially adapted for team names, with uppercase abbreviation.
6569

@@ -69,11 +73,20 @@ Specially adapted for team names, with uppercase abbreviation.
6973

7074
It formats the team name as CD Logroñés, FC Barcelona or Valencia CF.
7175

76+
### Separator
77+
78+
By default the words are separated by the space character.
79+
But any other character can be specified as a separator.
80+
81+
```html
82+
<p>{{ underscored_sentence | capitalize:'all':'_' }}</p>
83+
```
84+
7285
## Testing
7386

7487
To run the tests:
7588

7689
```bash
7790
$ npm install && bower install
7891
$ grunt test
79-
```
92+
```

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-capitalize-filter",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"homepage": "https://github.com/Puigcerber/angular-capitalize-filter",
55
"repository": {
66
"type": "git",

capitalize.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010
* @param {string} input The string to be formatted.
1111
* @param {string} [format] The format to be applied being the options 'all', 'first' or 'team'.
1212
* If not specified, 'all' is used.
13+
* @param {string} [separator] The character(s) to be used for separating the string.
14+
* If not specified, space is used.
1315
* @returns {string} Formatted string.
1416
*/
1517
angular.module('angular-capitalize-filter',[])
1618
.filter('capitalize', function () {
17-
return function (input, format, wordDelim) {
19+
return function (input, format, separator) {
1820
if (!input) {
1921
return input;
2022
}
2123
format = format || 'all';
22-
wordDelim = wordDelim || ' ';
24+
separator = separator || ' ';
2325
if (format === 'first') {
2426
// Capitalize the first letter of a sentence
2527
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
2628
} else {
27-
var words = input.split(wordDelim);
29+
var words = input.split(separator);
2830
var result = [];
2931
words.forEach(function(word) {
3032
if (word.length === 2 && format === 'team') {
@@ -34,7 +36,7 @@ angular.module('angular-capitalize-filter',[])
3436
result.push(word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
3537
}
3638
});
37-
return result.join(' ');
39+
return result.join(separator);
3840
}
3941
};
4042
});

capitalize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-capitalize-filter",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "AngularJS filter to capitalize sentences and specially team names.",
55
"author": "Pablo Villoslada Puigcerber <pablo85@gmail.com>",
66
"main": "index.js",

test/capitalize.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ describe('Filter: capitalize', function () {
4747
});
4848
});
4949

50+
describe('Separator', function () {
51+
it('should return the underscored sentence with the desired capitalization', function() {
52+
var text = 'COPY_and_PASTE_is_a_design_ERROR';
53+
expect(capitalize(text, 'all', '_')).toBe('Copy_And_Paste_Is_A_Design_Error');
54+
expect(capitalize(text, 'first', '_')).toBe('Copy_and_paste_is_a_design_error');
55+
});
56+
});
57+
5058
});

0 commit comments

Comments
 (0)