Angular: Foo Pluralize Filter
http://angularjs.org/
by johnwun
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<div ng-controller="appCtrl">
<div ng-bind-html-unsafe="m.a | fooFilter"></div>
<div ng-bind-html-unsafe="m.b | fooFilter"></div>
<div ng-bind-html-unsafe="m.c | fooFilter"></div>
<div ng-bind-html-unsafe="m.d | fooFilter"></div>
<div ng-bind-html-unsafe="m.e | fooFilter"></div>
<div ng-bind-html-unsafe="m.f | fooFilter"></div>
</div>
JavaScript
'use strict';
var myApp = angular.module('myApp', []);
myApp.controller('appCtrl',['$scope',function($scope){
var m = $scope.m = {};
m.a=0;
m.b=1;
m.c=2;
m.d=4;
m.e=26;
m.f = 'rhinoceros';
}])
myApp.filter('fooFilter',function(){
return function(text,offset){
var val= parseInt(text);
if(isNaN(val)){return ('Promise not to stop when I say "<b>'+ text+'</b>".')}
if(val==0){return '<b>Not</b> like the others.'};
if(val==1){return '<b>One</b> of these things is not like the others'};
if(val<5){
var arr = ["of you."];
var best = "the <b>best</b>, ";
for(var c = 0;c < val;c++){arr.unshift(best);}
return arr.join("");
};
}
});