1.0.0 • Published 6 years ago

angular1-filters v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Angular1-filters

npm version Bower version

NPM

A collection of useful filters for AngularJS.

Install

You can install the latest version of angular1-filters with npm or bower:

npm

$ npm install --save angular1-filters

bower

$ bower install --save angular1-filters

After running just put inside the modules of your application:

var app = angular.module('myApp', ['ngSanitize', 'angular1-filters']);

How to use

To apply a filter:

{{value | name_of_filter}}

Filters

The included filters are:

age

A filter that converts date to age.

Input:
{{ '1993-04-01' | age }}
{{ '01/04/1993' | age }}
{{ new Date('1993-04-01') | age }}

Output:
25
25
25

cep

A filter to return a number formatted as a cep.

Input:
{{ '47658245' | cep }}

Output:
47658-245

cnpj

A filter to return a number formatted as a cnpj.

Input:
{{ '71619383000129' | cnpj }}

Output:
71.619.383/0001-29

cpf

A filter to return a number formatted as a cpf.

Input:
{{ '08369635040' | cpf }}

Output:
083.696.350-40

cpfCnpj

A filter to return a number formatted as a cpf or cnpj.

Input:
{{ '08369635040' | cpfCnpj }}
{{ '71619383000129' | cpfCnpj }}

Output:
083.696.350-40
71.619.383/0001-29

join

A filter to join an array into a string. Parameters: join : separator (default ',')

Input:
{{ [1, 2, 3] | join }}
{{ [1, null, 2, undefined, 3] | join }}
{{ [1, 2, 3] | join:', ' }}

Output:
1,2,3
1,2,3
1, 2, 3

money

A filter to return a float formatted as a money. Parameters: money : symbol (default '') : precision (default 2) : decimals (default '.') : thousands (default ',')

Input:
{{ 1000000 | money }}
{{ 1000000 | money : 'R$ ' : 2 : ',' : '.' }}
{{ 1000000 | money : '$ ' : 2 : '.' : ',' }}

Output:
1,000,000.00
R$ 1.000.000,00
$ 1,000,000.00

percentage

A filter to return a number formatted as a percentage. Parameters: percentage : decimals (default 2)

Input:
{{ 100 | percentage }}
{{ 100 | percentage : 0 }}
{{ null | percentage }}
{{ undefined | percentage }}
{{ 0 | percentage : 0 }}
{{ 10.5 | percentage }}

Output:
100,00%
100%
0,00%
0,00%
0%
10,50%

phone

A filter to return a number formatted as a phone.

Input:
{{ '71999999999' | phone }}
{{ '7199999999' | phone }}

Output:
(71) 99999-9999
(71) 9999-9999

replace

A filter to replace string content. Parameters: replace : searchValue : newValue

Input:
{{ 'abcdfff' | replace : 'f' : 'e' }}
{{ 'lucas' | replace : 'lucas' : 'ayres' }}

Output:
abcde
ayres

reverse

A filter to reverse order of arrays or strings.

Input:
{{ 'abcde' | reverse }}
{{ [1, 2, 3] | reverse }}

Output:
edcba
[3, 2, 1]