Skip to content

Commit ce66297

Browse files
committed
build(v0.4.8): bump version
1 parent e28a6ac commit ce66297

File tree

6 files changed

+79
-10
lines changed

6 files changed

+79
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular-filter   [![Build Status](https://travis-ci.org/a8m/angular-filter.svg?branch=master)](https://travis-ci.org/a8m/angular-filter) [![Coverage Status](https://coveralls.io/repos/a8m/angular-filter/badge.png?branch=master)](https://coveralls.io/r/a8m/angular-filter?branch=master)
2-
>Bunch of useful filters for angularJS (with no external dependencies!), **v0.4.7**
2+
>Bunch of useful filters for angularJS (with no external dependencies!), **v0.4.8**
33
44
##Table of contents:
55
- [Get Started](#get-started)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-filter",
3-
"version": "0.4.7",
3+
"version": "0.4.8",
44
"main": "dist/angular-filter.js",
55
"description": "Bunch of useful filters for angularJS(with no external dependencies!)",
66
"repository": {

dist/angular-filter.js

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Bunch of useful filters for angularJS
3-
* @version v0.4.7 - 2014-10-03 * @link https://github.com/a8m/angular-filter
2+
* Bunch of useful filters for angularJS(with no external dependencies!)
3+
* @version v0.4.8 - 2014-10-13 * @link https://github.com/a8m/angular-filter
44
* @author Ariel Mashraki <ariel@mashraki.co.il>
55
* @license MIT License, http://www.opensource.org/licenses/MIT
66
*/
@@ -22,6 +22,7 @@ var isDefined = angular.isDefined,
2222

2323

2424
/**
25+
* @description
2526
* get an object and return array of values
2627
* @param object
2728
* @returns {Array}
@@ -34,7 +35,6 @@ function toArray(object) {
3435
}
3536

3637
/**
37-
*
3838
* @param value
3939
* @returns {boolean}
4040
*/
@@ -43,6 +43,7 @@ function isNull(value) {
4343
}
4444

4545
/**
46+
* @description
4647
* return if object contains partial object
4748
* @param partial{object}
4849
* @param object{object}
@@ -58,6 +59,7 @@ function objectContains(partial, object) {
5859
}
5960

6061
/**
62+
* @description
6163
* search for approximate pattern in string
6264
* @param word
6365
* @param pattern
@@ -76,6 +78,7 @@ function hasApproxPattern(word, pattern) {
7678
}
7779

7880
/**
81+
* @description
7982
* return the first n element of an array,
8083
* if expression provided, is returns as long the expression return truthy
8184
* @param array
@@ -103,7 +106,6 @@ if (!String.prototype.contains) {
103106
}
104107

105108
/**
106-
*
107109
* @param num {Number}
108110
* @param decimal {Number}
109111
* @param $math
@@ -112,6 +114,35 @@ if (!String.prototype.contains) {
112114
function convertToDecimal(num, decimal, $math){
113115
return $math.round(num * $math.pow(10,decimal)) / ($math.pow(10,decimal));
114116
}
117+
118+
/**
119+
* @description
120+
* Get an object, and return an array composed of it's properties names(nested too).
121+
* @param obj {Object}
122+
* @param stack {Array}
123+
* @param parent {String}
124+
* @returns {Array}
125+
* @example
126+
* parseKeys({ a:1, b: { c:2, d: { e: 3 } } }) ==> ["a", "b.c", "b.d.e"]
127+
*/
128+
function deepKeys(obj, stack, parent) {
129+
stack = stack || [];
130+
var keys = Object.keys(obj);
131+
132+
keys.forEach(function(el) {
133+
//if it's a nested object
134+
if(isObject(obj[el]) && !isArray(obj[el])) {
135+
//concatenate the new parent if exist
136+
var p = parent ? parent + '.' + el : parent;
137+
deepKeys(obj[el], stack, p || el);
138+
} else {
139+
//create and save the key
140+
var key = parent ? parent + '.' + el : el;
141+
stack.push(key)
142+
}
143+
});
144+
return stack
145+
}
115146
/**
116147
* @ngdoc filter
117148
* @name a8m.angular
@@ -485,6 +516,43 @@ angular.module('a8m.count-by', [])
485516
}
486517
}]);
487518

519+
/**
520+
* @ngdoc filter
521+
* @name defaults
522+
* @kind function
523+
*
524+
* @description
525+
* defaultsFilter allows to specify a default fallback value for properties that resolve to undefined.
526+
*/
527+
528+
angular.module('a8m.defaults', [])
529+
.filter('defaults', ['$parse', function( $parse ) {
530+
return function(collection, defaults) {
531+
532+
collection = (isObject(collection)) ? toArray(collection) : collection;
533+
534+
if(!isArray(collection) || !isObject(defaults)) {
535+
return collection;
536+
}
537+
538+
var keys = deepKeys(defaults);
539+
540+
collection.forEach(function(elm) {
541+
//loop through all the keys
542+
keys.forEach(function(key) {
543+
var getter = $parse(key);
544+
var setter = getter.assign;
545+
//if it's not exist
546+
if(isUndefined(getter(elm))) {
547+
//get from defaults, and set to the returned object
548+
setter(elm, getter(defaults))
549+
}
550+
});
551+
});
552+
553+
return collection;
554+
}
555+
}]);
488556
/**
489557
* @ngdoc filter
490558
* @name every
@@ -1953,6 +2021,7 @@ angular.module('angular.filter', [
19532021
'a8m.after-where',
19542022
'a8m.before',
19552023
'a8m.before-where',
2024+
'a8m.defaults',
19562025
'a8m.where',
19572026
'a8m.reverse',
19582027
'a8m.remove',

dist/angular-filter.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-filter.zip

2.25 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-filter",
33
"description": "Bunch of useful filters for angularJS(with no external dependencies!)",
4-
"version": "0.4.7",
4+
"version": "0.4.8",
55
"filename": "angular-filter.min.js",
66
"main": "dist/angular-filter.min.js",
77
"homepage": "https://github.com/a8m/angular-filter",

0 commit comments

Comments
 (0)