Skip to content

jvandemo/angular-filter-pack

Repository files navigation

AngularJS Filter Pack

Filter Pack for AngularJS

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.

Installation

Install via bower:

$ bower install angular-filter-pack

Then include the module in your AngularJS app:

angular.module('yourApp', ['angularFilterPack']);

Filters

Trim

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

}]);

Slugify

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

}]);

Dasherize

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

}]);

Change log

v0.2.0

  • Added dasherize filter
  • Added trim filter

v0.1.0

  • Added slugify filter
  • Initial version

About

AngularJS Filter Pack

Resources

License

Stars

Watchers

Forks

Packages

No packages published