ng-filters
Version:
Useful filters for AngularJS
103 lines (80 loc) • 1.77 kB
Markdown
[](http://bower.io/search/?q=ng-filters)
[](https://slack.exceptionless.com)
[](https://donorbox.org/exceptionless)
Useful filters for AngularJS
Install
-------
```html
bower install ng-filters --save-dev
```
Usage
-------
Prints a number in a friendly byte representation<br/>
```html
{{1536 | bytes}}
{{'1536' | bytes}}
{{1536 | bytes:2}}
Result:
1.5 kB
1.5 kB
1.50 kB
```
Joins an array into a string<br/>
```html
{{[1, 2] | join}}
{{[1, null, 2, undefined] | join}}
{{[1, 2] | join:', '}}
Result:
1,2
1,2
1, 2
```
Returns a number formatted as a percentage. Numbers between 0 and 1 will be rounded up to 10th decimal place.<br/>
```html
{{123 | percentage}}
{{null | percentage}}
{{60.0 | percentage}}
{{0 | percentage}}
{{0.000001 | percentage}}
{{100.000001 | percentage:100}}
Result:
123%
0%
60%
0%
0.1%
100%
```
Replaces string content<br/>
```html
{{'blake' | replace:'b':'B'}}
Result:
Blake
```
Reverses as string or array<br/>
```html
{{'blake' | reverse}}
{{[1, 2] | reverse}}
Result:
ekalb
[]
```
Splits a single word into multiple words<br/>
```html
{{'blake' | toSpacedWords}}
{{'blakeIsAwesome' | toSpacedWords}}
Result:
Blake
Blake Is Awesome
```
Acknowledgements
-------
I used [Restangular](https://github.com/mgonto/restangular) as a template for this project as no one has yet to create a project template for new projects.
The bytes filter originated from [Thom Seddon](https://gist.github.com/thomseddon/3511330) before some improvements were made.