New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-filter

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-filter - npm Package Compare versions

Comparing version 0.4.9 to 0.5.0

src/_filter/string/uri-component-encode.js

2

bower.json
{
"name": "angular-filter",
"version": "0.4.9",
"version": "0.5.0",
"main": "dist/angular-filter.js",

@@ -5,0 +5,0 @@ "description": "Bunch of useful filters for angularJS(with no external dependencies!)",

/**
* Bunch of useful filters for angularJS(with no external dependencies!)
* @version v0.4.9 - 2014-10-14 * @link https://github.com/a8m/angular-filter
* @version v0.5.0 - 2014-11-12 * @link https://github.com/a8m/angular-filter
* @author Ariel Mashraki <ariel@mashraki.co.il>

@@ -146,3 +146,13 @@ * @license MIT License, http://www.opensource.org/licenses/MIT

}
/**
* @description
* Test if given object is a Scope instance
* @param obj
* @returns {Boolean}
*/
function isScope(obj) {
return obj && obj.$evalAsync && obj.$watch;
}
/**
* @ngdoc filter

@@ -841,6 +851,2 @@ * @name a8m.angular

var result,
get = $parse(property),
prop;
if(!isObject(collection) || isUndefined(property)) {

@@ -850,22 +856,33 @@ return collection;

//Add collection instance to watch list
result = filterWatcher.$watch('groupBy', collection);
var getterFn = $parse(property);
forEach( collection, function( elm ) {
prop = get(elm);
// If it's called outside the DOM
if(!isScope(this)) {
return _groupBy(collection, getterFn);
}
// Return the memoized|| memozie the result
return filterWatcher.isMemoized('groupBy', arguments) ||
filterWatcher.memoize('groupBy', arguments, this,
_groupBy(collection, getterFn));
if(!result[prop]) {
result[prop] = [];
}
/**
* groupBy function
* @param collection
* @param getter
* @returns {{}}
*/
function _groupBy(collection, getter) {
var result = {};
var prop;
if(result[prop].indexOf( elm ) === -1) {
forEach( collection, function( elm ) {
prop = getter(elm);
if(!result[prop]) {
result[prop] = [];
}
result[prop].push(elm);
}
});
//kill instance
filterWatcher.$destroy('groupBy', collection);
return result;
});
return result;
}
}

@@ -1094,19 +1111,6 @@ }]);

return (isArray(input)) ? reverseArray(input) : input;
return (isArray(input)) ? input.slice().reverse() : input;
}
}]);
/**
* @description
* Get an array, reverse it manually.
* @param arr
* @returns {Array}
*/
function reverseArray(arr) {
var res = [];
arr.forEach(function(e, i) {
res.push(arr[arr.length - i -1]);
});
return res;
}

@@ -1413,4 +1417,4 @@ /**

* @description
* Math.max
*
* Math.max will get an array and return the max value. if an expression
* is provided, will return max value by expression.
*/

@@ -1420,12 +1424,27 @@

.filter('max', ['$math', function ($math) {
return function (input) {
.filter('max', ['$math', '$parse', function ($math, $parse) {
return function (input, expression) {
return (isArray(input)) ?
$math.max.apply($math, input) :
input;
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? $math.max.apply($math, input)
: input[indexByMax(input, expression)];
};
/**
* @private
* @param array
* @param exp
* @returns {number|*|Number}
*/
function indexByMax(array, exp) {
var mappedArray = array.map(function(elm){
return $parse(exp)(elm);
});
return mappedArray.indexOf($math.max.apply($math, mappedArray));
}
}]);
/**

@@ -1437,4 +1456,4 @@ * @ngdoc filter

* @description
* Math.min
*
* Math.min will get an array and return the min value. if an expression
* is provided, will return min value by expression.
*/

@@ -1444,12 +1463,27 @@

.filter('min', ['$math', function ($math) {
return function (input) {
.filter('min', ['$math', '$parse', function ($math, $parse) {
return function (input, expression) {
return (isArray(input)) ?
$math.min.apply($math, input) :
input;
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? $math.min.apply($math, input)
: input[indexByMin(input, expression)];
};
/**
* @private
* @param array
* @param exp
* @returns {number|*|Number}
*/
function indexByMin(array, exp) {
var mappedArray = array.map(function(elm){
return $parse(exp)(elm);
});
return mappedArray.indexOf($math.min.apply($math, mappedArray));
}
}]);
/**

@@ -1722,3 +1756,3 @@ * @ngdoc filter

var replace = sub || '-';
var replace = (isUndefined(sub)) ? '-' : sub;

@@ -1875,2 +1909,24 @@ if(isString(input)) {

* @ngdoc filter
* @name uriComponentEncode
* @kind function
*
* @description
* get string as parameter and return encoded string
*/
angular.module('a8m.uri-component-encode', [])
.filter('uriComponentEncode',['$window', function ($window) {
return function (input) {
if(isString(input)) {
return $window.encodeURIComponent(input);
}
return input;
}
}]);
/**
* @ngdoc filter
* @name uriEncode

@@ -1925,5 +1981,4 @@ * @kind function

* @description
* filterWatchers is a _privateProvider
* It's created to solve the problem of $rootScope:infdig(Infinite $digest loop) when using
* some filters on the view.
* store specific filters result in $$cache, based on scope life time(avoid memory leak).
* on scope.$destroy remove it's cache from $$cache container
*/

@@ -1934,28 +1989,29 @@

var filterPrefix = '_$$';
this.$get = [function() {
/**
* @description
* change the prefix name for filters on watch phase
* @param prefix
* @returns {filterWatcher}
*/
this.setPrefix = function(prefix) {
filterPrefix = prefix;
return this;
};
/**
* Cache storing
* @type {Object}
*/
var $$cache = {};
this.$get = ['$window', function($window) {
/**
* Scope listeners container
* scope.$destroy => remove all cache keys
* bind to current scope.
* @type {Object}
*/
var $$listeners = {};
var $$timeout = $window.setTimeout;
/**
* @description
* return the filter full name
* @param name
* get `HashKey` string based on the given arguments.
* @param fName
* @param args
* @returns {string}
* @private
*/
function _getFullName(name) {
return filterPrefix + name;
function getHashKey(fName, args) {
return [fName, JSON.stringify(args)]
.join('#')
.replace(/"/g,'');
}

@@ -1965,10 +2021,13 @@

* @description
* return whether or not this object is watched in current phase
* @param fName
* @param object
* @returns {boolean}
* @private
* fir on $scope.$destroy,
* remove cache based scope from `$$cache`,
* and remove itself from `$$listeners`
* @param event
*/
function _isWatched(fName, object) {
return isDefined(object[fName]);
function removeCache(event) {
var id = event.targetScope.$id;
forEach($$listeners[id], function(key) {
delete $$cache[key];
});
delete $$listeners[id];
}

@@ -1978,19 +2037,15 @@

* @description
* return the object.$$filterName instance in current phase
* @param name
* @param object
* @private
* Store hashKeys in $$listeners container
* on scope.$destroy, remove them all(bind an event).
* @param scope
* @param hashKey
* @returns {*}
*/
function _watch(name, object) {
var fName = _getFullName(name);
if(!_isWatched(fName, object)) {
//Create new instance
Object.defineProperty(object, fName, {
enumerable: false,
configurable: true,
value: {}
});
function addListener(scope, hashKey) {
var id = scope.$id;
if(isUndefined($$listeners[id])) {
scope.$on('$destroy', removeCache);
$$listeners[id] = [];
}
return object[fName];
return $$listeners[id].push(hashKey);
}

@@ -2000,21 +2055,58 @@

* @description
* destroy/delete current watch instance
* @param name
* @param object
* @private
* return the `cacheKey` or undefined.
* @param filterName
* @param args
* @returns {*}
*/
function _destroy(name, object) {
return $$timeout(function() {
delete object[_getFullName(name)];
});
function $$isMemoized(filterName, args) {
var hashKey = getHashKey(filterName, args);
return $$cache[hashKey];
}
/**
* @description
* store `result` in `$$cache` container, based on the hashKey.
* add $destroy listener and return result
* @param filterName
* @param args
* @param scope
* @param result
* @returns {*}
*/
function $$memoize(filterName, args, scope, result) {
var hashKey = getHashKey(filterName, args);
//store result in `$$cache` container
$$cache[hashKey] = result;
//add `$destroy` listener
addListener(scope, hashKey);
return result;
}
return {
$watch: _watch,
$destroy: _destroy
isMemoized: $$isMemoized,
memoize: $$memoize
}
}];
});
});
/**

@@ -2031,2 +2123,3 @@ * @ngdoc module

'a8m.uri-encode',
'a8m.uri-component-encode',
'a8m.slugify',

@@ -2033,0 +2126,0 @@ 'a8m.strip-tags',

/**
* Bunch of useful filters for angularJS(with no external dependencies!)
* @version v0.4.9 - 2014-10-14 * @link https://github.com/a8m/angular-filter
* @version v0.5.0 - 2014-11-12 * @link https://github.com/a8m/angular-filter
* @author Ariel Mashraki <ariel@mashraki.co.il>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/!function(a,b,c){"use strict";function d(a){return D(a)?a:Object.keys(a).map(function(b){return a[b]})}function e(a){return null===a}function f(a,b){var c=Object.keys(a);return-1==c.map(function(c){return!(!b[c]||b[c]!=a[c])}).indexOf(!1)}function g(a,b){if(""===b)return a;var c=a.indexOf(b.charAt(0));return-1===c?!1:g(a.substr(c+1),b.substr(1))}function h(a,b,c){var d=0;return a.filter(function(a){var e=x(c)?b>d&&c(a):b>d;return d=e?d+1:d,e})}function i(a,b,c){return c.round(a*c.pow(10,b))/c.pow(10,b)}function j(a,b,c){b=b||[];var d=Object.keys(a);return d.forEach(function(d){if(C(a[d])&&!D(a[d])){var e=c?c+"."+d:c;j(a[d],b,e||d)}else{var f=c?c+"."+d:d;b.push(f)}}),b}function k(){return function(a,b){return a>b}}function l(){return function(a,b){return a>=b}}function m(){return function(a,b){return b>a}}function n(){return function(a,b){return b>=a}}function o(){return function(a,b){return a==b}}function p(){return function(a,b){return a!=b}}function q(){return function(a,b){return a===b}}function r(){return function(a,b){return a!==b}}function s(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?!0:b.some(function(b){return C(b)||z(c)?a(c)(b):b===c})}}function t(a,b){return b=b||0,b>=a.length?a:D(a[b])?t(a.slice(0,b).concat(a[b],a.slice(b+1)),b):t(a,b+1)}function u(a){var b=[];return a.forEach(function(c,d){b.push(a[a.length-d-1])}),b}function v(a){return function(b,c){function e(a,b){return y(b)?!1:a.some(function(a){return H(a,b)})}if(b=C(b)?d(b):b,!D(b))return b;var f=[],g=a(c);return b.filter(y(c)?function(a,b,c){return c.indexOf(a)===b}:function(a){var b=g(a);return e(f,b)?!1:(f.push(b),!0)})}}function w(a,b,c){return b?a+c+w(a,--b,c):a}var x=b.isDefined,y=b.isUndefined,z=b.isFunction,A=b.isString,B=b.isNumber,C=b.isObject,D=b.isArray,E=b.forEach,F=b.extend,G=b.copy,H=b.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),b.module("a8m.angular",[]).filter("isUndefined",function(){return function(a){return b.isUndefined(a)}}).filter("isDefined",function(){return function(a){return b.isDefined(a)}}).filter("isFunction",function(){return function(a){return b.isFunction(a)}}).filter("isString",function(){return function(a){return b.isString(a)}}).filter("isNumber",function(){return function(a){return b.isNumber(a)}}).filter("isArray",function(){return function(a){return b.isArray(a)}}).filter("isObject",function(){return function(a){return b.isObject(a)}}).filter("isEqual",function(){return function(a,c){return b.equals(a,c)}}),b.module("a8m.conditions",[]).filter({isGreaterThan:k,">":k,isGreaterThanOrEqualTo:l,">=":l,isLessThan:m,"<":m,isLessThanOrEqualTo:n,"<=":n,isEqualTo:o,"==":o,isNotEqualTo:p,"!=":p,isIdenticalTo:q,"===":q,isNotIdenticalTo:r,"!==":r}),b.module("a8m.is-null",[]).filter("isNull",function(){return function(a){return e(a)}}),b.module("a8m.after-where",[]).filter("afterWhere",function(){return function(a,b){if(a=C(a)?d(a):a,!D(a)||y(b))return a;var c=a.map(function(a){return f(b,a)}).indexOf(!0);return a.slice(-1===c?0:c)}}),b.module("a8m.after",[]).filter("after",function(){return function(a,b){return a=C(a)?d(a):a,D(a)?a.slice(b):a}}),b.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(a,b){if(a=C(a)?d(a):a,!D(a)||y(b))return a;var c=a.map(function(a){return f(b,a)}).indexOf(!0);return a.slice(0,-1===c?a.length:++c)}}),b.module("a8m.before",[]).filter("before",function(){return function(a,b){return a=C(a)?d(a):a,D(a)?a.slice(0,b?--b:b):a}}),b.module("a8m.concat",[]).filter("concat",[function(){return function(a,b){if(y(b))return a;if(D(a))return a.concat(C(b)?d(b):b);if(C(a)){var c=d(a);return c.concat(C(b)?d(b):b)}return a}}]),b.module("a8m.contains",[]).filter({contains:["$parse",s],some:["$parse",s]}),b.module("a8m.count-by",[]).filter("countBy",["$parse",function(a){return function(b,c){var e,f={},g=a(c);return b=C(b)?d(b):b,!D(b)||y(c)?b:(b.forEach(function(a){e=g(a),f[e]||(f[e]=0),f[e]++}),f)}}]),b.module("a8m.defaults",[]).filter("defaults",["$parse",function(a){return function(b,c){if(b=C(b)?d(b):b,!D(b)||!C(c))return b;var e=j(c);return b.forEach(function(b){e.forEach(function(d){var e=a(d),f=e.assign;y(e(b))&&f(b,e(c))})}),b}}]),b.module("a8m.every",[]).filter("every",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?!0:b.every(function(b){return C(b)||z(c)?a(c)(b):b===c})}}]),b.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(a){return function(b,e,f){var g;return f=A(f)||B(f)?String(f).toLowerCase():c,b=C(b)?d(b):b,!D(b)||y(f)?b:b.filter(function(b){return e.some(function(c){if(~c.indexOf("+")){var d=c.replace(new RegExp("\\s","g"),"").split("+");g=d.reduce(function(c,d,e){return 1===e?a(c)(b)+" "+a(d)(b):c+" "+a(d)(b)})}else g=a(c)(b);return A(g)||B(g)?String(g).toLowerCase().contains(f):!1})})}}]),b.module("a8m.first",[]).filter("first",["$parse",function(a){return function(b){var e,f,g;return b=C(b)?d(b):b,D(b)?(g=Array.prototype.slice.call(arguments,1),e=B(g[0])?g[0]:1,f=B(g[0])?B(g[1])?c:g[1]:g[0],g.length?h(b,e,f?a(f):f):b[0]):b}}]),b.module("a8m.flatten",[]).filter("flatten",function(){return function(a,b){return b=b||!1,a=C(a)?d(a):a,D(a)?b?[].concat.apply([],a):t(a,0):a}}),b.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(a){return function(b,c,e,f){var h,i,j=f||!1;return b=C(b)?d(b):b,!D(b)||y(c)||y(e)?b:(i=a(c),b.filter(function(a){return h=i(a),A(h)?(h=j?h:h.toLowerCase(),e=j?e:e.toLowerCase(),g(h,e)!==!1):!1}))}}]),b.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(a,b,c){function e(a,b){var c,d,e=Object.keys(a);return 0<e.filter(function(e){return c=a[e],d?!0:A(c)?(c=f?c:c.toLowerCase(),d=g(c,b)!==!1):!1}).length}var f=c||!1;return a=C(a)?d(a):a,!D(a)||y(b)?a:(b=f?b:b.toLowerCase(),a.filter(function(a){return A(a)?(a=f?a:a.toLowerCase(),g(a,b)!==!1):C(a)?e(a,b):!1}))}}),b.module("a8m.group-by",["a8m.filter-watcher"]).filter("groupBy",["$parse","filterWatcher",function(a,b){return function(c,d){var e,f,g=a(d);return!C(c)||y(d)?c:(e=b.$watch("groupBy",c),E(c,function(a){f=g(a),e[f]||(e[f]=[]),-1===e[f].indexOf(a)&&e[f].push(a)}),b.$destroy("groupBy",c),e)}}]),b.module("a8m.is-empty",[]).filter("isEmpty",function(){return function(a){return C(a)?!d(a).length:!a.length}}),b.module("a8m.last",[]).filter("last",["$parse",function(a){return function(b){var e,f,g,i=G(b);return i=C(i)?d(i):i,D(i)?(g=Array.prototype.slice.call(arguments,1),e=B(g[0])?g[0]:1,f=B(g[0])?B(g[1])?c:g[1]:g[0],g.length?h(i.reverse(),e,f?a(f):f).reverse():i[i.length-1]):i}}]),b.module("a8m.map",[]).filter("map",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.map(function(b){return a(c)(b)})}}]),b.module("a8m.omit",[]).filter("omit",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.filter(function(b){return!a(c)(b)})}}]),b.module("a8m.pick",[]).filter("pick",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.filter(function(b){return a(c)(b)})}}]),b.module("a8m.remove-with",[]).filter("removeWith",function(){return function(a,b){return y(b)?a:(a=C(a)?d(a):a,a.filter(function(a){return!f(b,a)}))}}),b.module("a8m.remove",[]).filter("remove",function(){return function(a){a=C(a)?d(a):a;var b=Array.prototype.slice.call(arguments,1);return D(a)?a.filter(function(a){return!b.some(function(b){return H(b,a)})}):a}}),b.module("a8m.reverse",[]).filter("reverse",[function(){return function(a){return a=C(a)?d(a):a,A(a)?a.split("").reverse().join(""):D(a)?u(a):a}}]),b.module("a8m.search-field",[]).filter("searchField",["$parse",function(a){return function(b){var c,e;b=C(b)?d(b):b;var f=Array.prototype.slice.call(arguments,1);return D(b)&&f.length?b.map(function(b){return e=f.map(function(d){return(c=a(d))(b)}).join(" "),F(b,{searchField:e})}):b}}]),b.module("a8m.to-array",[]).filter("toArray",function(){return function(a,b){return C(a)?b?Object.keys(a).map(function(b){return F(a[b],{$key:b})}):d(a):a}}),b.module("a8m.unique",[]).filter({unique:["$parse",v],uniq:["$parse",v]}),b.module("a8m.where",[]).filter("where",function(){return function(a,b){return y(b)?a:(a=C(a)?d(a):a,a.filter(function(a){return f(b,a)}))}}),b.module("a8m.xor",[]).filter("xor",["$parse",function(a){return function(b,c,e){function f(b,c){var d=a(e);return c.some(function(a){return e?H(d(a),d(b)):H(a,b)})}return e=e||!1,b=C(b)?d(b):b,c=C(c)?d(c):c,D(b)&&D(c)?b.concat(c).filter(function(a){return!(f(a,b)&&f(a,c))}):b}}]),b.module("a8m.math.byteFmt",["a8m.math"]).filter("byteFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1024>b?i(b,c,a)+" B":1048576>b?i(b/1024,c,a)+" KB":1073741824>b?i(b/1048576,c,a)+" MB":i(b/1073741824,c,a)+" GB":"NaN"}}]),b.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(a){return function(b,c){if(B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)){var d=180*b/a.PI;return a.round(d*a.pow(10,c))/a.pow(10,c)}return"NaN"}}]),b.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1024>b?i(b,c,a)+" KB":1048576>b?i(b/1024,c,a)+" MB":i(b/1048576,c,a)+" GB":"NaN"}}]),b.module("a8m.math",[]).factory("$math",["$window",function(a){return a.Math}]),b.module("a8m.math.max",["a8m.math"]).filter("max",["$math",function(a){return function(b){return D(b)?a.max.apply(a,b):b}}]),b.module("a8m.math.min",["a8m.math"]).filter("min",["$math",function(a){return function(b){return D(b)?a.min.apply(a,b):b}}]),b.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(a,b){return function(c,d,e){var f=A(c)?b.Number(c):c;return d=d||100,e=e||!1,!B(f)||b.isNaN(f)?c:e?a.round(f/d*100):f/d*100}}]),b.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(a){return function(b,c){if(B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)){var d=3.14159265359*b/180;return a.round(d*a.pow(10,c))/a.pow(10,c)}return"NaN"}}]),b.module("a8m.math.radix",[]).filter("radix",function(){return function(a,b){var c=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return B(a)&&c.test(b)?a.toString(b).toUpperCase():a}}),b.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1e3>b?b:1e6>b?i(b/1e3,c,a)+" K":1e9>b?i(b/1e6,c,a)+" M":i(b/1e9,c,a)+" B":"NaN"}}]),b.module("a8m.math.sum",[]).filter("sum",function(){return function(a,b){return D(a)?a.reduce(function(a,b){return a+b},b||0):a}}),b.module("a8m.ends-with",[]).filter("endsWith",function(){return function(a,b,c){var d,e=c||!1;return!A(a)||y(b)?a:(a=e?a:a.toLowerCase(),d=a.length-b.length,-1!==a.indexOf(e?b:b.toLowerCase(),d))}}),b.module("a8m.ltrim",[]).filter("ltrim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp("^"+c+"+"),""):a}}),b.module("a8m.repeat",[]).filter("repeat",[function(){return function(a,b,c){var d=~~b;return A(a)&&d?w(a,--b,c||""):a}}]),b.module("a8m.rtrim",[]).filter("rtrim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp(c+"+$"),""):a}}),b.module("a8m.slugify",[]).filter("slugify",[function(){return function(a,b){var c=b||"-";return A(a)?a.toLowerCase().replace(/\s+/g,c):a}}]),b.module("a8m.starts-with",[]).filter("startsWith",function(){return function(a,b,c){var d=c||!1;return!A(a)||y(b)?a:(a=d?a:a.toLowerCase(),!a.indexOf(d?b:b.toLowerCase()))}}),b.module("a8m.stringular",[]).filter("stringular",function(){return function(a){var b=Array.prototype.slice.call(arguments,1);return a.replace(/{(\d+)}/g,function(a,c){return y(b[c])?a:b[c]})}}),b.module("a8m.strip-tags",[]).filter("stripTags",function(){return function(a){return A(a)?a.replace(/<\S[^><]*>/g,""):a}}),b.module("a8m.trim",[]).filter("trim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp("^"+c+"+|"+c+"+$","g"),""):a}}),b.module("a8m.truncate",[]).filter("truncate",function(){return function(a,b,c,d){return b=y(b)?a.length:b,d=d||!1,c=c||"",!A(a)||a.length<=b?a:a.substring(0,d?-1===a.indexOf(" ",b)?a.length:a.indexOf(" ",b):b)+c}}),b.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(a){return b.isString(a)?a.split(" ").map(function(a){return a.charAt(0).toUpperCase()+a.substring(1)}).join(" "):a}}]),b.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(a){return function(b){return A(b)?a.encodeURI(b):b}}]),b.module("a8m.wrap",[]).filter("wrap",function(){return function(a,b,c){return!A(a)||y(b)?a:[b,a,c||b].join("")}}),b.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){var a="_$$";this.setPrefix=function(b){return a=b,this},this.$get=["$window",function(b){function c(b){return a+b}function d(a,b){return x(b[a])}function e(a,b){var e=c(a);return d(e,b)||Object.defineProperty(b,e,{enumerable:!1,configurable:!0,value:{}}),b[e]}function f(a,b){return g(function(){delete b[c(a)]})}var g=b.setTimeout;return{$watch:e,$destroy:f}}]}),b.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.slugify","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular);
*/!function(a,b,c){"use strict";function d(a){return D(a)?a:Object.keys(a).map(function(b){return a[b]})}function e(a){return null===a}function f(a,b){var c=Object.keys(a);return-1==c.map(function(c){return!(!b[c]||b[c]!=a[c])}).indexOf(!1)}function g(a,b){if(""===b)return a;var c=a.indexOf(b.charAt(0));return-1===c?!1:g(a.substr(c+1),b.substr(1))}function h(a,b,c){var d=0;return a.filter(function(a){var e=x(c)?b>d&&c(a):b>d;return d=e?d+1:d,e})}function i(a,b,c){return c.round(a*c.pow(10,b))/c.pow(10,b)}function j(a,b,c){b=b||[];var d=Object.keys(a);return d.forEach(function(d){if(C(a[d])&&!D(a[d])){var e=c?c+"."+d:c;j(a[d],b,e||d)}else{var f=c?c+"."+d:d;b.push(f)}}),b}function k(a){return a&&a.$evalAsync&&a.$watch}function l(){return function(a,b){return a>b}}function m(){return function(a,b){return a>=b}}function n(){return function(a,b){return b>a}}function o(){return function(a,b){return b>=a}}function p(){return function(a,b){return a==b}}function q(){return function(a,b){return a!=b}}function r(){return function(a,b){return a===b}}function s(){return function(a,b){return a!==b}}function t(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?!0:b.some(function(b){return C(b)||z(c)?a(c)(b):b===c})}}function u(a,b){return b=b||0,b>=a.length?a:D(a[b])?u(a.slice(0,b).concat(a[b],a.slice(b+1)),b):u(a,b+1)}function v(a){return function(b,c){function e(a,b){return y(b)?!1:a.some(function(a){return H(a,b)})}if(b=C(b)?d(b):b,!D(b))return b;var f=[],g=a(c);return b.filter(y(c)?function(a,b,c){return c.indexOf(a)===b}:function(a){var b=g(a);return e(f,b)?!1:(f.push(b),!0)})}}function w(a,b,c){return b?a+c+w(a,--b,c):a}var x=b.isDefined,y=b.isUndefined,z=b.isFunction,A=b.isString,B=b.isNumber,C=b.isObject,D=b.isArray,E=b.forEach,F=b.extend,G=b.copy,H=b.equals;String.prototype.contains||(String.prototype.contains=function(){return-1!==String.prototype.indexOf.apply(this,arguments)}),b.module("a8m.angular",[]).filter("isUndefined",function(){return function(a){return b.isUndefined(a)}}).filter("isDefined",function(){return function(a){return b.isDefined(a)}}).filter("isFunction",function(){return function(a){return b.isFunction(a)}}).filter("isString",function(){return function(a){return b.isString(a)}}).filter("isNumber",function(){return function(a){return b.isNumber(a)}}).filter("isArray",function(){return function(a){return b.isArray(a)}}).filter("isObject",function(){return function(a){return b.isObject(a)}}).filter("isEqual",function(){return function(a,c){return b.equals(a,c)}}),b.module("a8m.conditions",[]).filter({isGreaterThan:l,">":l,isGreaterThanOrEqualTo:m,">=":m,isLessThan:n,"<":n,isLessThanOrEqualTo:o,"<=":o,isEqualTo:p,"==":p,isNotEqualTo:q,"!=":q,isIdenticalTo:r,"===":r,isNotIdenticalTo:s,"!==":s}),b.module("a8m.is-null",[]).filter("isNull",function(){return function(a){return e(a)}}),b.module("a8m.after-where",[]).filter("afterWhere",function(){return function(a,b){if(a=C(a)?d(a):a,!D(a)||y(b))return a;var c=a.map(function(a){return f(b,a)}).indexOf(!0);return a.slice(-1===c?0:c)}}),b.module("a8m.after",[]).filter("after",function(){return function(a,b){return a=C(a)?d(a):a,D(a)?a.slice(b):a}}),b.module("a8m.before-where",[]).filter("beforeWhere",function(){return function(a,b){if(a=C(a)?d(a):a,!D(a)||y(b))return a;var c=a.map(function(a){return f(b,a)}).indexOf(!0);return a.slice(0,-1===c?a.length:++c)}}),b.module("a8m.before",[]).filter("before",function(){return function(a,b){return a=C(a)?d(a):a,D(a)?a.slice(0,b?--b:b):a}}),b.module("a8m.concat",[]).filter("concat",[function(){return function(a,b){if(y(b))return a;if(D(a))return a.concat(C(b)?d(b):b);if(C(a)){var c=d(a);return c.concat(C(b)?d(b):b)}return a}}]),b.module("a8m.contains",[]).filter({contains:["$parse",t],some:["$parse",t]}),b.module("a8m.count-by",[]).filter("countBy",["$parse",function(a){return function(b,c){var e,f={},g=a(c);return b=C(b)?d(b):b,!D(b)||y(c)?b:(b.forEach(function(a){e=g(a),f[e]||(f[e]=0),f[e]++}),f)}}]),b.module("a8m.defaults",[]).filter("defaults",["$parse",function(a){return function(b,c){if(b=C(b)?d(b):b,!D(b)||!C(c))return b;var e=j(c);return b.forEach(function(b){e.forEach(function(d){var e=a(d),f=e.assign;y(e(b))&&f(b,e(c))})}),b}}]),b.module("a8m.every",[]).filter("every",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?!0:b.every(function(b){return C(b)||z(c)?a(c)(b):b===c})}}]),b.module("a8m.filter-by",[]).filter("filterBy",["$parse",function(a){return function(b,e,f){var g;return f=A(f)||B(f)?String(f).toLowerCase():c,b=C(b)?d(b):b,!D(b)||y(f)?b:b.filter(function(b){return e.some(function(c){if(~c.indexOf("+")){var d=c.replace(new RegExp("\\s","g"),"").split("+");g=d.reduce(function(c,d,e){return 1===e?a(c)(b)+" "+a(d)(b):c+" "+a(d)(b)})}else g=a(c)(b);return A(g)||B(g)?String(g).toLowerCase().contains(f):!1})})}}]),b.module("a8m.first",[]).filter("first",["$parse",function(a){return function(b){var e,f,g;return b=C(b)?d(b):b,D(b)?(g=Array.prototype.slice.call(arguments,1),e=B(g[0])?g[0]:1,f=B(g[0])?B(g[1])?c:g[1]:g[0],g.length?h(b,e,f?a(f):f):b[0]):b}}]),b.module("a8m.flatten",[]).filter("flatten",function(){return function(a,b){return b=b||!1,a=C(a)?d(a):a,D(a)?b?[].concat.apply([],a):u(a,0):a}}),b.module("a8m.fuzzy-by",[]).filter("fuzzyBy",["$parse",function(a){return function(b,c,e,f){var h,i,j=f||!1;return b=C(b)?d(b):b,!D(b)||y(c)||y(e)?b:(i=a(c),b.filter(function(a){return h=i(a),A(h)?(h=j?h:h.toLowerCase(),e=j?e:e.toLowerCase(),g(h,e)!==!1):!1}))}}]),b.module("a8m.fuzzy",[]).filter("fuzzy",function(){return function(a,b,c){function e(a,b){var c,d,e=Object.keys(a);return 0<e.filter(function(e){return c=a[e],d?!0:A(c)?(c=f?c:c.toLowerCase(),d=g(c,b)!==!1):!1}).length}var f=c||!1;return a=C(a)?d(a):a,!D(a)||y(b)?a:(b=f?b:b.toLowerCase(),a.filter(function(a){return A(a)?(a=f?a:a.toLowerCase(),g(a,b)!==!1):C(a)?e(a,b):!1}))}}),b.module("a8m.group-by",["a8m.filter-watcher"]).filter("groupBy",["$parse","filterWatcher",function(a,b){return function(c,d){function e(a,b){var c,d={};return E(a,function(a){c=b(a),d[c]||(d[c]=[]),d[c].push(a)}),d}if(!C(c)||y(d))return c;var f=a(d);return k(this)?b.isMemoized("groupBy",arguments)||b.memoize("groupBy",arguments,this,e(c,f)):e(c,f)}}]),b.module("a8m.is-empty",[]).filter("isEmpty",function(){return function(a){return C(a)?!d(a).length:!a.length}}),b.module("a8m.last",[]).filter("last",["$parse",function(a){return function(b){var e,f,g,i=G(b);return i=C(i)?d(i):i,D(i)?(g=Array.prototype.slice.call(arguments,1),e=B(g[0])?g[0]:1,f=B(g[0])?B(g[1])?c:g[1]:g[0],g.length?h(i.reverse(),e,f?a(f):f).reverse():i[i.length-1]):i}}]),b.module("a8m.map",[]).filter("map",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.map(function(b){return a(c)(b)})}}]),b.module("a8m.omit",[]).filter("omit",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.filter(function(b){return!a(c)(b)})}}]),b.module("a8m.pick",[]).filter("pick",["$parse",function(a){return function(b,c){return b=C(b)?d(b):b,!D(b)||y(c)?b:b.filter(function(b){return a(c)(b)})}}]),b.module("a8m.remove-with",[]).filter("removeWith",function(){return function(a,b){return y(b)?a:(a=C(a)?d(a):a,a.filter(function(a){return!f(b,a)}))}}),b.module("a8m.remove",[]).filter("remove",function(){return function(a){a=C(a)?d(a):a;var b=Array.prototype.slice.call(arguments,1);return D(a)?a.filter(function(a){return!b.some(function(b){return H(b,a)})}):a}}),b.module("a8m.reverse",[]).filter("reverse",[function(){return function(a){return a=C(a)?d(a):a,A(a)?a.split("").reverse().join(""):D(a)?a.slice().reverse():a}}]),b.module("a8m.search-field",[]).filter("searchField",["$parse",function(a){return function(b){var c,e;b=C(b)?d(b):b;var f=Array.prototype.slice.call(arguments,1);return D(b)&&f.length?b.map(function(b){return e=f.map(function(d){return(c=a(d))(b)}).join(" "),F(b,{searchField:e})}):b}}]),b.module("a8m.to-array",[]).filter("toArray",function(){return function(a,b){return C(a)?b?Object.keys(a).map(function(b){return F(a[b],{$key:b})}):d(a):a}}),b.module("a8m.unique",[]).filter({unique:["$parse",v],uniq:["$parse",v]}),b.module("a8m.where",[]).filter("where",function(){return function(a,b){return y(b)?a:(a=C(a)?d(a):a,a.filter(function(a){return f(b,a)}))}}),b.module("a8m.xor",[]).filter("xor",["$parse",function(a){return function(b,c,e){function f(b,c){var d=a(e);return c.some(function(a){return e?H(d(a),d(b)):H(a,b)})}return e=e||!1,b=C(b)?d(b):b,c=C(c)?d(c):c,D(b)&&D(c)?b.concat(c).filter(function(a){return!(f(a,b)&&f(a,c))}):b}}]),b.module("a8m.math.byteFmt",["a8m.math"]).filter("byteFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1024>b?i(b,c,a)+" B":1048576>b?i(b/1024,c,a)+" KB":1073741824>b?i(b/1048576,c,a)+" MB":i(b/1073741824,c,a)+" GB":"NaN"}}]),b.module("a8m.math.degrees",["a8m.math"]).filter("degrees",["$math",function(a){return function(b,c){if(B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)){var d=180*b/a.PI;return a.round(d*a.pow(10,c))/a.pow(10,c)}return"NaN"}}]),b.module("a8m.math.kbFmt",["a8m.math"]).filter("kbFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1024>b?i(b,c,a)+" KB":1048576>b?i(b/1024,c,a)+" MB":i(b/1048576,c,a)+" GB":"NaN"}}]),b.module("a8m.math",[]).factory("$math",["$window",function(a){return a.Math}]),b.module("a8m.math.max",["a8m.math"]).filter("max",["$math","$parse",function(a,b){function c(c,d){var e=c.map(function(a){return b(d)(a)});return e.indexOf(a.max.apply(a,e))}return function(b,d){return D(b)?y(d)?a.max.apply(a,b):b[c(b,d)]:b}}]),b.module("a8m.math.min",["a8m.math"]).filter("min",["$math","$parse",function(a,b){function c(c,d){var e=c.map(function(a){return b(d)(a)});return e.indexOf(a.min.apply(a,e))}return function(b,d){return D(b)?y(d)?a.min.apply(a,b):b[c(b,d)]:b}}]),b.module("a8m.math.percent",["a8m.math"]).filter("percent",["$math","$window",function(a,b){return function(c,d,e){var f=A(c)?b.Number(c):c;return d=d||100,e=e||!1,!B(f)||b.isNaN(f)?c:e?a.round(f/d*100):f/d*100}}]),b.module("a8m.math.radians",["a8m.math"]).filter("radians",["$math",function(a){return function(b,c){if(B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)){var d=3.14159265359*b/180;return a.round(d*a.pow(10,c))/a.pow(10,c)}return"NaN"}}]),b.module("a8m.math.radix",[]).filter("radix",function(){return function(a,b){var c=/^[2-9]$|^[1-2]\d$|^3[0-6]$/;return B(a)&&c.test(b)?a.toString(b).toUpperCase():a}}),b.module("a8m.math.shortFmt",["a8m.math"]).filter("shortFmt",["$math",function(a){return function(b,c){return B(c)&&isFinite(c)&&c%1===0&&c>=0&&B(b)&&isFinite(b)?1e3>b?b:1e6>b?i(b/1e3,c,a)+" K":1e9>b?i(b/1e6,c,a)+" M":i(b/1e9,c,a)+" B":"NaN"}}]),b.module("a8m.math.sum",[]).filter("sum",function(){return function(a,b){return D(a)?a.reduce(function(a,b){return a+b},b||0):a}}),b.module("a8m.ends-with",[]).filter("endsWith",function(){return function(a,b,c){var d,e=c||!1;return!A(a)||y(b)?a:(a=e?a:a.toLowerCase(),d=a.length-b.length,-1!==a.indexOf(e?b:b.toLowerCase(),d))}}),b.module("a8m.ltrim",[]).filter("ltrim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp("^"+c+"+"),""):a}}),b.module("a8m.repeat",[]).filter("repeat",[function(){return function(a,b,c){var d=~~b;return A(a)&&d?w(a,--b,c||""):a}}]),b.module("a8m.rtrim",[]).filter("rtrim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp(c+"+$"),""):a}}),b.module("a8m.slugify",[]).filter("slugify",[function(){return function(a,b){var c=y(b)?"-":b;return A(a)?a.toLowerCase().replace(/\s+/g,c):a}}]),b.module("a8m.starts-with",[]).filter("startsWith",function(){return function(a,b,c){var d=c||!1;return!A(a)||y(b)?a:(a=d?a:a.toLowerCase(),!a.indexOf(d?b:b.toLowerCase()))}}),b.module("a8m.stringular",[]).filter("stringular",function(){return function(a){var b=Array.prototype.slice.call(arguments,1);return a.replace(/{(\d+)}/g,function(a,c){return y(b[c])?a:b[c]})}}),b.module("a8m.strip-tags",[]).filter("stripTags",function(){return function(a){return A(a)?a.replace(/<\S[^><]*>/g,""):a}}),b.module("a8m.trim",[]).filter("trim",function(){return function(a,b){var c=b||"\\s";return A(a)?a.replace(new RegExp("^"+c+"+|"+c+"+$","g"),""):a}}),b.module("a8m.truncate",[]).filter("truncate",function(){return function(a,b,c,d){return b=y(b)?a.length:b,d=d||!1,c=c||"",!A(a)||a.length<=b?a:a.substring(0,d?-1===a.indexOf(" ",b)?a.length:a.indexOf(" ",b):b)+c}}),b.module("a8m.ucfirst",[]).filter("ucfirst",[function(){return function(a){return b.isString(a)?a.split(" ").map(function(a){return a.charAt(0).toUpperCase()+a.substring(1)}).join(" "):a}}]),b.module("a8m.uri-component-encode",[]).filter("uriComponentEncode",["$window",function(a){return function(b){return A(b)?a.encodeURIComponent(b):b}}]),b.module("a8m.uri-encode",[]).filter("uriEncode",["$window",function(a){return function(b){return A(b)?a.encodeURI(b):b}}]),b.module("a8m.wrap",[]).filter("wrap",function(){return function(a,b,c){return!A(a)||y(b)?a:[b,a,c||b].join("")}}),b.module("a8m.filter-watcher",[]).provider("filterWatcher",function(){this.$get=[function(){function a(a,b){return[a,JSON.stringify(b)].join("#").replace(/"/g,"")}function b(a){var b=a.targetScope.$id;E(g[b],function(a){delete f[a]}),delete g[b]}function c(a,c){var d=a.$id;return y(g[d])&&(a.$on("$destroy",b),g[d]=[]),g[d].push(c)}function d(b,c){var d=a(b,c);return f[d]}function e(b,d,e,g){var h=a(b,d);return f[h]=g,c(e,h),g}var f={},g={};return{isMemoized:d,memoize:e}}]}),b.module("angular.filter",["a8m.ucfirst","a8m.uri-encode","a8m.uri-component-encode","a8m.slugify","a8m.strip-tags","a8m.stringular","a8m.truncate","a8m.starts-with","a8m.ends-with","a8m.wrap","a8m.trim","a8m.ltrim","a8m.rtrim","a8m.repeat","a8m.to-array","a8m.concat","a8m.contains","a8m.unique","a8m.is-empty","a8m.after","a8m.after-where","a8m.before","a8m.before-where","a8m.defaults","a8m.where","a8m.reverse","a8m.remove","a8m.remove-with","a8m.group-by","a8m.count-by","a8m.search-field","a8m.fuzzy-by","a8m.fuzzy","a8m.omit","a8m.pick","a8m.every","a8m.filter-by","a8m.xor","a8m.map","a8m.first","a8m.last","a8m.flatten","a8m.math","a8m.math.max","a8m.math.min","a8m.math.percent","a8m.math.radix","a8m.math.sum","a8m.math.degrees","a8m.math.radians","a8m.math.byteFmt","a8m.math.kbFmt","a8m.math.shortFmt","a8m.angular","a8m.conditions","a8m.is-null","a8m.filter-watcher"])}(window,window.angular);
{
"name": "angular-filter",
"description": "Bunch of useful filters for angularJS(with no external dependencies!)",
"version": "0.4.9",
"version": "0.5.0",
"filename": "angular-filter.min.js",

@@ -6,0 +6,0 @@ "main": "dist/angular-filter.min.js",

#Angular-filter &nbsp; [![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)
>Bunch of useful filters for angularJS (with no external dependencies!), **v0.4.9**
>Bunch of useful filters for AngularJS (with no external dependencies!), **v0.5.0**
**Notice:** if you want to use `angular-filter` out of AngularJS(e.g: Node, etc..), check [Agile.js repo](https://github.com/a8m/agile)
##Table of contents:

@@ -8,3 +10,3 @@ - [Get Started](#get-started)

- [Changelog](#changelog)
- [Development](#development)
- [Contributing](#contributing)
- [TODO](#todo)

@@ -33,5 +35,5 @@ - [Collection](#collection)

- [pluck](#pluck)
- [reverse](#reverse-collection)
- [reverse](#reverse)
- [remove](#remove)
- [removeWith](#remove-with)
- [removeWith](#removewith)
- [searchField](#searchfield)

@@ -46,3 +48,3 @@ - [some](#contains)

- [repeat](#repeat)
- [reverse](#reverse-string)
- [reverse](#reverse-1)
- [slugify](#slugify)

@@ -58,2 +60,3 @@ - [startsWith](#startswith)

- [uriEncode](#uriencode)
- [uriComponentEncode](#uricomponentencode)
- [wrap](#wrap)

@@ -111,4 +114,4 @@ - [Math](#math)

...
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="bower_components/js/angular-filter.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.0/angular.min.js"></script>
<script src="bower_components/angular-filter/dist/angular-filter.min.js"></script>
...

@@ -173,3 +176,3 @@ <script>

{ id:4, customer: { name: 'William', id: 20 } },
{ id:5, customer: { name: 'Clive', id: 30 } },
{ id:5, customer: { name: 'Clive', id: 30 } }
];

@@ -906,2 +909,9 @@ }

###uriComponentEncode
get string as parameter and return encoded uri component
```html
<a ng-href="http://domain.com/fetch/{{ 'Some&strange=chars' | uriComponentEncode }}">Link</a>
```
###slugify

@@ -1038,3 +1048,3 @@ Transform text into a URL slug. Replaces whitespaces, with dash("-"), or given argument

Repeats a string n times<br/>
usage: ```string | repeat: n: separator[optional]```
**Usage:** ```string | repeat: n: separator[optional]```
```html

@@ -1048,24 +1058,40 @@ <p>{{ 'foo' | repeat: 3: '-' }}</p>

###max
max find and return the largest number in a given array
max find and return the largest number in a given array.
if an `expression` is provided, will return max value by expression.
**Usage:** ```array | max: expression[optional]```
```js
$scope.users = [
{ user: { score: 988790 } },
{ user: { score: 123414 } },
{ user: { rank : 988999 } },
{ user: { score: 987621 } }
];
```
```html
<p> {{ [1,2,3,4,7,8,9] | max }}</p>
<p> {{ users | max: 'user.score || user.rank' }}</p>
<!--
result:
9
-->
* 9
* { user: { rank : 988999 } }
```
###min
min find and return the lowest number in a given array
min find and return the lowest number in a given array.
if an `expression` is provided, will return min value by expression.
**Usage:** ```array | min: expression[optional]```
```js
$scope.users = [
{ user: { score: 988790 } },
{ user: { score: 123414 } },
{ user: { score: 987621 } }
];
```
```html
<p> {{ [1,2,3,4,7,8,9] | min }}</p>
<p> {{ users | min: 'user.score' }}</p>
<!--
result:
1
* 1
* { user: { score: 123414 } }
```

@@ -1220,2 +1246,5 @@ ###percent

#Changelog
###0.4.9
* fix issue #38 with [reverseFilter](#reverse)
###0.4.8

@@ -1233,5 +1262,5 @@ * add [defaultsFilter](#defaults)

#Development
#Contributing
* If you planning add some feature please **create issue before**.
* Don't forget about tests.
* If you planning add some feature please create issue before.

@@ -1238,0 +1267,0 @@ Clone the project: <br/>

@@ -138,2 +138,12 @@ /*jshint globalstrict:true*/

return stack
}
/**
* @description
* Test if given object is a Scope instance
* @param obj
* @returns {Boolean}
*/
function isScope(obj) {
return obj && obj.$evalAsync && obj.$watch;
}

@@ -16,6 +16,2 @@ /**

var result,
get = $parse(property),
prop;
if(!isObject(collection) || isUndefined(property)) {

@@ -25,23 +21,34 @@ return collection;

//Add collection instance to watch list
result = filterWatcher.$watch('groupBy', collection);
var getterFn = $parse(property);
forEach( collection, function( elm ) {
prop = get(elm);
// If it's called outside the DOM
if(!isScope(this)) {
return _groupBy(collection, getterFn);
}
// Return the memoized|| memozie the result
return filterWatcher.isMemoized('groupBy', arguments) ||
filterWatcher.memoize('groupBy', arguments, this,
_groupBy(collection, getterFn));
if(!result[prop]) {
result[prop] = [];
}
/**
* groupBy function
* @param collection
* @param getter
* @returns {{}}
*/
function _groupBy(collection, getter) {
var result = {};
var prop;
if(result[prop].indexOf( elm ) === -1) {
forEach( collection, function( elm ) {
prop = getter(elm);
if(!result[prop]) {
result[prop] = [];
}
result[prop].push(elm);
}
});
//kill instance
filterWatcher.$destroy('groupBy', collection);
return result;
});
return result;
}
}
}]);

@@ -21,18 +21,4 @@ /**

return (isArray(input)) ? reverseArray(input) : input;
return (isArray(input)) ? input.slice().reverse() : input;
}
}]);
/**
* @description
* Get an array, reverse it manually.
* @param arr
* @returns {Array}
*/
function reverseArray(arr) {
var res = [];
arr.forEach(function(e, i) {
res.push(arr[arr.length - i -1]);
});
return res;
}

@@ -7,4 +7,4 @@ /**

* @description
* Math.max
*
* Math.max will get an array and return the max value. if an expression
* is provided, will return max value by expression.
*/

@@ -14,10 +14,26 @@

.filter('max', ['$math', function ($math) {
return function (input) {
.filter('max', ['$math', '$parse', function ($math, $parse) {
return function (input, expression) {
return (isArray(input)) ?
$math.max.apply($math, input) :
input;
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? $math.max.apply($math, input)
: input[indexByMax(input, expression)];
};
/**
* @private
* @param array
* @param exp
* @returns {number|*|Number}
*/
function indexByMax(array, exp) {
var mappedArray = array.map(function(elm){
return $parse(exp)(elm);
});
return mappedArray.indexOf($math.max.apply($math, mappedArray));
}
}]);
}]);

@@ -7,4 +7,4 @@ /**

* @description
* Math.min
*
* Math.min will get an array and return the min value. if an expression
* is provided, will return min value by expression.
*/

@@ -14,10 +14,26 @@

.filter('min', ['$math', function ($math) {
return function (input) {
.filter('min', ['$math', '$parse', function ($math, $parse) {
return function (input, expression) {
return (isArray(input)) ?
$math.min.apply($math, input) :
input;
if(!isArray(input)) {
return input;
}
return isUndefined(expression)
? $math.min.apply($math, input)
: input[indexByMin(input, expression)];
};
/**
* @private
* @param array
* @param exp
* @returns {number|*|Number}
*/
function indexByMin(array, exp) {
var mappedArray = array.map(function(elm){
return $parse(exp)(elm);
});
return mappedArray.indexOf($math.min.apply($math, mappedArray));
}
}]);
}]);

@@ -15,3 +15,3 @@ /**

var replace = sub || '-';
var replace = (isUndefined(sub)) ? '-' : sub;

@@ -18,0 +18,0 @@ if(isString(input)) {

@@ -7,5 +7,4 @@ /**

* @description
* filterWatchers is a _privateProvider
* It's created to solve the problem of $rootScope:infdig(Infinite $digest loop) when using
* some filters on the view.
* store specific filters result in $$cache, based on scope life time(avoid memory leak).
* on scope.$destroy remove it's cache from $$cache container
*/

@@ -16,28 +15,29 @@

var filterPrefix = '_$$';
this.$get = [function() {
/**
* @description
* change the prefix name for filters on watch phase
* @param prefix
* @returns {filterWatcher}
*/
this.setPrefix = function(prefix) {
filterPrefix = prefix;
return this;
};
/**
* Cache storing
* @type {Object}
*/
var $$cache = {};
this.$get = ['$window', function($window) {
/**
* Scope listeners container
* scope.$destroy => remove all cache keys
* bind to current scope.
* @type {Object}
*/
var $$listeners = {};
var $$timeout = $window.setTimeout;
/**
* @description
* return the filter full name
* @param name
* get `HashKey` string based on the given arguments.
* @param fName
* @param args
* @returns {string}
* @private
*/
function _getFullName(name) {
return filterPrefix + name;
function getHashKey(fName, args) {
return [fName, JSON.stringify(args)]
.join('#')
.replace(/"/g,'');
}

@@ -47,10 +47,13 @@

* @description
* return whether or not this object is watched in current phase
* @param fName
* @param object
* @returns {boolean}
* @private
* fir on $scope.$destroy,
* remove cache based scope from `$$cache`,
* and remove itself from `$$listeners`
* @param event
*/
function _isWatched(fName, object) {
return isDefined(object[fName]);
function removeCache(event) {
var id = event.targetScope.$id;
forEach($$listeners[id], function(key) {
delete $$cache[key];
});
delete $$listeners[id];
}

@@ -60,19 +63,15 @@

* @description
* return the object.$$filterName instance in current phase
* @param name
* @param object
* @private
* Store hashKeys in $$listeners container
* on scope.$destroy, remove them all(bind an event).
* @param scope
* @param hashKey
* @returns {*}
*/
function _watch(name, object) {
var fName = _getFullName(name);
if(!_isWatched(fName, object)) {
//Create new instance
Object.defineProperty(object, fName, {
enumerable: false,
configurable: true,
value: {}
});
function addListener(scope, hashKey) {
var id = scope.$id;
if(isUndefined($$listeners[id])) {
scope.$on('$destroy', removeCache);
$$listeners[id] = [];
}
return object[fName];
return $$listeners[id].push(hashKey);
}

@@ -82,20 +81,56 @@

* @description
* destroy/delete current watch instance
* @param name
* @param object
* @private
* return the `cacheKey` or undefined.
* @param filterName
* @param args
* @returns {*}
*/
function _destroy(name, object) {
return $$timeout(function() {
delete object[_getFullName(name)];
});
function $$isMemoized(filterName, args) {
var hashKey = getHashKey(filterName, args);
return $$cache[hashKey];
}
/**
* @description
* store `result` in `$$cache` container, based on the hashKey.
* add $destroy listener and return result
* @param filterName
* @param args
* @param scope
* @param result
* @returns {*}
*/
function $$memoize(filterName, args, scope, result) {
var hashKey = getHashKey(filterName, args);
//store result in `$$cache` container
$$cache[hashKey] = result;
//add `$destroy` listener
addListener(scope, hashKey);
return result;
}
return {
$watch: _watch,
$destroy: _destroy
isMemoized: $$isMemoized,
memoize: $$memoize
}
}];
});
});

@@ -12,2 +12,3 @@ /**

'a8m.uri-encode',
'a8m.uri-component-encode',
'a8m.slugify',

@@ -14,0 +15,0 @@ 'a8m.strip-tags',

@@ -27,7 +27,5 @@ 'use strict';

});
});
it('should support nested properties to', function() {
var orders = [

@@ -47,3 +45,2 @@ { id:10, customer: { name: 'foo', id: 1 } },

});
});

@@ -54,3 +51,2 @@

'returns the composed aggregate object.', function() {
var dataObject = {

@@ -67,7 +63,5 @@ 0: { id: 1, data: {} },

});
});
it('should get !collection and return it as-is ', function() {
expect(filter('string')).toEqual('string');

@@ -77,5 +71,29 @@ expect(filter(1)).toEqual(1);

expect(filter(null)).toBeNull();
});
describe('inside the DOM', function() {
it('should not throw and not trigger the infinite digest exception',
inject(function($rootScope, $compile) {
var scope = $rootScope.$new();
scope.players = [
{ name: 'foo', team: 'a' },
{ name: 'lol', team: 'b' },
{ name: 'bar', team: 'b' },
{ name: 'baz', team: 'a' }
];
scope.search = '';
var elm = angular.element(
'<ul>' +
'<li ng-repeat="(key, val) in players | filter: search | groupBy: \'team\'">' +
'{{ key }}' +
'<p ng-repeat="v in val"> {{ v }}</p>' +
'</li>' +
'</ul>'
);
var temp = $compile(elm)(scope);
expect(function() { scope.$digest() }).not.toThrow();
expect(temp.children().length).toEqual(2);
}));
});
});

@@ -14,17 +14,24 @@ 'use strict';

it('should get an array of numbers and return the biggest one', function() {
expect(filter([1,2,3,4,5])).toEqual(5);
expect(filter([2,2,2,2,2])).toEqual(2);
expect(filter([1])).toEqual(1);
});
it('should get an array and expression and return an object', function() {
var users = [
{ user: { score: 988790 } },
{ user: { score: 123414 } },
{ user: { rank : 988999 } },
{ user: { score: 987621 } }
];
expect(filter(users, 'user.score || user.rank')).toEqual(users[2]);
expect(filter(users, 'user.score || 0')).toEqual(users[0]);
});
it('should get an !array and return it as-is', function() {
expect(filter('string')).toEqual('string');
expect(filter({})).toEqual({});
expect(filter(!0)).toBeTruthy();
});
});

@@ -14,17 +14,25 @@ 'use strict';

it('should get an array of numbers and return the lowest one', function() {
expect(filter([1,2,3,4,5])).toEqual(1);
expect(filter([2,0,2,2,2])).toEqual(0);
expect(filter([1])).toEqual(1);
});
it('should get an array and expression and return an object', function() {
var users = [
{ user: { score: 988790 } },
{ user: { score: 123414 } },
{ user: { rank : 100000 } },
{ user: { score: 987621 } }
];
expect(filter(users, 'user.score || user.rank')).toEqual(users[2]);
expect(filter(users, 'user.score || 1e9')).toEqual(users[1]);
});
it('should get an !array and return it as-is', function() {
expect(filter('string')).toEqual('string');
expect(filter({})).toEqual({});
expect(filter(!0)).toBeTruthy();
});
});

@@ -19,3 +19,3 @@ 'use strict';

it('should get a string with replacer and replace spaces withit', function() {
it('should get a string with replacer and replace spaces with it', function() {
expect(filter('a a', 1)).toEqual('a1a');

@@ -25,2 +25,3 @@ expect(filter('foo bar baz', '!')).toEqual('foo!bar!baz');

expect(filter('Lorem ipsum dolor sit amet', '-')).toEqual('lorem-ipsum-dolor-sit-amet');
expect(filter('Lorem ipsum dolor sit amet', '')).toEqual('loremipsumdolorsitamet');
});

@@ -27,0 +28,0 @@

@@ -5,53 +5,56 @@ 'use strict';

//Provider
function setPrefix(name) {
return function(filterWatcherProvider) {
filterWatcherProvider.setPrefix(name);
}
}
//helpers
function n(n) { return n; }
var stub = { fn: function(x) { return n(x) } };
beforeEach(module('a8m.filter-watcher', function ($provide) {
//mock setTimeout
$provide.value('$window', {
setTimeout: function(fn, mill) {
fn.apply(null, [].slice.call(arguments, 2));
return +new Date();
}
});
}));
beforeEach(module('a8m.filter-watcher'));
it('should register watcher and return new object', inject(function(filterWatcher) {
var watched = {},
flag = filterWatcher.$watch('foo', watched);
expect(flag).toEqual({});
expect(watched).toEqual({ _$$foo : {} });
it('should have 2 main functions `isMemoized` and `memozie`', inject(function(filterWatcher) {
expect(filterWatcher.isMemoized).toEqual(jasmine.any(Function));
expect(filterWatcher.memoize).toEqual(jasmine.any(Function));
}));
it('should return the same watcher instance if already exist', inject(function(filterWatcher) {
var watched = { _$$bar: [ 1, 2, 3] },
flag = filterWatcher.$watch('bar', watched);
expect(flag).toEqual([ 1, 2, 3]);
it('should called the function if it\'s not cached',
inject(function(filterWatcher) {
var spy = spyOn(stub, 'fn');
(function memoizedOnly(n) {
return filterWatcher.isMemoized('fName',n) || stub.fn(n);
})();
expect(spy).toHaveBeenCalled();
expect(spy.callCount).toEqual(1);
}));
it('should be able to remove specific watcher instance', inject(function(filterWatcher) {
var watched = { _$$bar: [ 1, 2, 3] };
filterWatcher.$destroy('bar', watched);
expect(watched).toEqual({});
it('should get the result from cache if it\'s memoize',
inject(function(filterWatcher, $rootScope) {
var scope = $rootScope.$new();
var spy = spyOn(stub, 'fn').andCallFake(function() {
return 1;
});
function memoize(n) {
return filterWatcher.isMemoized('fName', n) ||
filterWatcher.memoize('fName', n, scope, stub.fn(n));
}
[1,1,1,1,4,4,4,4,4].forEach(function(el) {
memoize(el);
});
expect(spy).toHaveBeenCalled();
expect(spy.callCount).toEqual(2);
}));
it('should be able to change the watcherPrefix', function() {
module(setPrefix('a8m_'));
inject(function(filterWatcher) {
var watched = {},
flag = filterWatcher.$watch('foo', watched);
expect(flag).toEqual({});
//TODO:(Ariel) this expectation broke travis build, check why
// expect(watched).toEqual({ a8m_foo : {} });
});
});
it('should clear cache from scope listeners on `$destroy`',
inject(function(filterWatcher, $rootScope) {
var scope;
var spy = spyOn(stub, 'fn').andCallFake(function() {
return 1;
});
function memoize(n) {
return filterWatcher.isMemoized('fName', n) ||
filterWatcher.memoize('fName', n, scope = $rootScope.$new(), stub.fn(n));
}
[1,1,1,1,1,1,1,1,1,1].forEach(function(el) {
memoize(el);
scope.$destroy();
});
expect(spy.callCount).toEqual(10);
}));
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc