https://github.com/exceptionless/ng-filters
Awesome generic angular filters
https://github.com/exceptionless/ng-filters
angular angularjs bytes filter javascript join ng-filters percent percentage replace reverse
Last synced: about 1 month ago
JSON representation
Awesome generic angular filters
- Host: GitHub
- URL: https://github.com/exceptionless/ng-filters
- Owner: exceptionless
- License: mit
- Created: 2014-10-02T13:02:09.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-09-26T22:57:07.000Z (over 9 years ago)
- Last Synced: 2025-03-21T08:05:48.181Z (10 months ago)
- Topics: angular, angularjs, bytes, filter, javascript, join, ng-filters, percent, percentage, replace, reverse
- Language: JavaScript
- Size: 23.4 KB
- Stars: 28
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ng-filters
[](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
-------
###bytes
Prints a number in a friendly byte representation
```html
{{1536 | bytes}}
{{'1536' | bytes}}
{{1536 | bytes:2}}
Result:
1.5 kB
1.5 kB
1.50 kB
```
###join
Joins an array into a string
```html
{{[1, 2] | join}}
{{[1, null, 2, undefined] | join}}
{{[1, 2] | join:', '}}
Result:
1,2
1,2
1, 2
```
###percentage
Returns a number formatted as a percentage. Numbers between 0 and 1 will be rounded up to 10th decimal place.
```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%
```
###replace
Replaces string content
```html
{{'blake' | replace:'b':'B'}}
Result:
Blake
```
###reverse
Reverses as string or array
```html
{{'blake' | reverse}}
{{[1, 2] | reverse}}
Result:
ekalb
[2, 1]
```
###toSpacedWords
Splits a single word into multiple words
```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.