Skip to content

sumitchawla/angularjs-filters

Repository files navigation

Build Status Dependency Status devDependency Status

angularjs-filters

A library of common AngularJS filters. Each filter is individually tested for various inputs. The module can be used by using the filter.js in your browser includes, or by using npm module ( with browserify).

Installation

bower install angularjs-filters

String Filters

Filter Usage Result
format 'Hello {0}. What are you been doing this {1}?' | string.format : 'Sam' : 'evening' Hello Sam. What are you been doing this evening?
html2string 'Hello <br/>. How are you?' | string.html2string Hello . How are you?
shorten 'A long story cut into short' | string.shorten : 12 A long story...
replace
String Replace. Pattern can be a string or regex
'Hello Mr How are you doing' | string.replace : 'Mr': 'Sir'
"hello help"| string.replace:"he[a-z]{2}":"Yell"
Hello Sir How are you doing
Yello Yell
camelcase 'A long story cut into short' | string.camelcase A Long Story Cut Into Short
lowercase 'Convert to LOWERCASE' | string.lowercase convert to lowercase
uppercase 'uppercase all' | string.uppercase UPPERCASE ALL
trim, trimstart, trimend
String Trim Functions
' Hello Mr. ' | string.trim Hello Mr.

Array Filters

Filter Usage Result
join ['Hello','Mr.','How','Are','You?'] | array.join : '-' Hello-Mr.-How-Are-You?
reverse ng-repeat='["Banana", "Orange", "Apple", "Mango"] | array.reverse' "Mango","Apple","Orange", "Banana"

Math Filters

Filter Usage Result
max [8, 1, 2, 3, 7] | math.max 8
min [8, 1, 2, 3, 7] | math.min 1

Boolean Filters

Filter Usage Result
YesNo
Converts boolean value to Yes/No
A == B | binary.YesNo Yes/No?

Debug Filters

Filter Usage Result
print
Debug prints the bound value
'MyValue' | debug.print MyValue

Other

Filter Usage Result
utixtimeconvertor
Converts unix timestamp to human readable (friedly) time.
'1596971407' | utixtimeconvertor 9 Aug 2020 - 4:10:7

Unit Testing

Each of the filter is covered by Unit Test extensively. If you find any input unhandelled, please let me know. Run the unit tests using following commands:

npm run karma 
npm run karma2

Contributions

Please feel free to add your contributions to set of filters.