AngularJS filters are awesome and convenient.
Unfortunately AngularJS only contains a few basic filters.
This filter pack conveniently provides your AngularJS application with an additional set of filters.
Lightweight and tested.
Install via bower:
$ bower install angular-filter-pack
Then include the module in your AngularJS app:
angular.module('yourApp', ['angularFilterPack']);
Trims a string:
- lowercases the string
- replaces whitespace a dash
Signature: trim(input [,characters])
- input: string (in a view template this is the piped expression)
- characters: characters to trim, defaults to whitespace
In a view template:
{{ ' hello world ' | trim }}
{{ '-hello world-' | trim:'-' }}
In JavaScript code:
angular.controller('someCtrl', ['slugifyFilter', function(slugify){
slugify('Hello world'); // hello-world
slugify('Hello World'); // hello-world
slugify('HelloWorld'); // helloworld
slugify('Hello_World'); // hello-world
}]);
Slugifies a string:
- lowercases the string
- replaces whitespace a dash
Signature: slugify(input)
- input: string (in a view template this is the piped expression)
In a view template:
{{ 'hello world' | slugify }}
In JavaScript code:
angular.controller('someCtrl', ['slugifyFilter', function(slugify){
slugify('Hello world'); // hello-world
slugify('Hello World'); // hello-world
slugify('HelloWorld'); // helloworld
slugify('Hello_World'); // hello-world
}]);
Dasherizes a string:
- lowercases the string
- replaces whitespace with dash
- replaces underscores with dash
- leaves existing dashes untouched
- replaces capitals with dash and lowercase
Signature: dasherize(input)
- input: string (in a view template this is the piped expression)
In a view template:
{{ 'hello world' | dasherize }}
In JavaScript code:
angular.controller('someCtrl', ['dasherizeFilter', function(dasherize){
dasherize('Hello world'); // hello-world
dasherize('Hello World'); // hello-world
dasherize('HelloWorld'); // hello-world
}]);
- Added dasherize filter
- Added trim filter
- Added slugify filter
- Initial version