forked from willmendesneto/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilters.js
More file actions
36 lines (32 loc) · 861 Bytes
/
filters.js
File metadata and controls
36 lines (32 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function() {
'use strict';
angular.module('myApp')
.filter('trim', function () {
return function (input) {
var str;
if (input === undefined || input === null) {
input = '';
}
str = String(input);
if (String.prototype.trim !== null) {
return str.trim();
} else {
return str.replace(/^\s+|\s+$/gm, '');
}
};
});
angular.module('myApp')
.filter('snakeCase', function($filter) {
return function(input) {
if (input === null || input === undefined) {
input = '';
}
// Using `trim` filter that already exist
var $trim = $filter('trim');
return $trim(input)
.replace(/([a-z\d])([A-Z]+)/g, '$1_$2')
.replace(/[-\s]+/g, '_')
.toLowerCase();
};
});
}());