npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-filters

v1.1.2

Published

A collection of filters for AngularJS.

Downloads

49

Readme

angular-filters Build Status

A collection of useful filters for AngularJS.

You can install the latest version of angular-filters with bower:

$ bower install angular-filters

Then, simply include ./dist/angular-filters.js or ./dist/angular-filters.min.js in your Web app and inject the module frapontillo.ex.filters in your application.

Filters specs

The included filters are:

bool

The bool filter allows to specify true and false values to show depending on the input value. The second parameter will be returned if and only if the first parameter is true; the third parameter will be returned if and only if the first parameter is false.

This filter can be used to print a specific message depending on a boolean value.

Use it as follows:

	<p>{{ someBoolValue | bool:'Candies!':'No candies :(' }}</p>
	$scope.returnValue = $filter('bool')($scope.someBoolValue, 'Candies!', 'No candies :(');

default

The default filter allows to specify a default fallback value if an object is one of the following:

  • null
  • undefined
  • empty string, ''
  • NaN

Please notice that if a value equals to 0, the default value won't be returned, as 0 is accepted.

This filter is useful when another filter return is not safe and when you want to display a fallback value.

Use it as follows:

	<p>{{ someValue | number:2 | default:'No value is available.' }}</p>
	$scope.returnValue = $filter('default')
		($filter('number')($scope.someValue, 2), 'No value is available.');

firstNotNull

The firstNotNull filter returns the first element from an array that is neither null or undefined. This means it returns all numbers and strings, even if empty. It returns undefined if all values aren't set or if the array is empty.

Use it as follows:

	<p>{{ myValues | firstNotNull }}</p>
	$scope.firstValue = $filter('firstNotNull')($scope.myValues);

lastNotNull

The lastNotNull filter returns the last element from an array that is neither null or undefined. This means it returns all numbers and strings, even if empty. It returns undefined if all values aren't set or if the array is empty.

Use it as follows:

	<p>{{ myValues | lastNotNull }}</p>
	$scope.firstValue = $filter('lastNotNull')($scope.myValues);

max

The max filter returns the maximum value from an array that is neither null or undefined. It returns undefined if all values aren't set or if the array is empty.

Use it as follows:

	<p>{{ myValues | max }}</p>
	$scope.maxValue = $filter('max')($scope.myValues);

min

The min filter returns the minimum value from an array that is neither null or undefined. It returns undefined if all values aren't set or if the array is empty.

Use it as follows:

	<p>{{ myValues | min }}</p>
	$scope.minValue = $filter('min')($scope.myValues);

property

The property filter returns an array with only the specified property from the original objects, not altering the null or undefined values.

Use it as follows:

	<p>{{ myObjects | property:'myText' }}</p>
	$scope.allTheTexts = $filter('property')($scope.myObjects, 'myText');

join

The join filter returns the original array as a string, with its elements joined with the specified separator, if any, otherwise defaulting to the comma ,.

Use it as follows:

	<p>{{ myValues | join:', ' }}</p>
	$scope.joinedValues = $filter('join')($scope.myValues, ', ');

Development

Test and build

To test and build the distribution files yourself, do the following:

npm install -g grunt-cli karma bower
npm install
bower install
grunt

These are the available grunt task:

  • karma:travis, run karma tests once, on PhantomJS
  • karma:local, run karma tests once, on Chrome
  • karma:dev, run karma tests indefinitely after every file change, on Chrome
  • jshint:src, run jshint on every source file
  • jshint:test, run jshint on every test file
  • clean:dist, clean the distribution directory
  • clean:temp, clean the temporary directory
  • ngmin, prepares every angular file into the dist/.temp directory
  • concat, concatenates the module declaration and the ngmin-ified file from the dist/.temp into the dist directory, adding the banner
  • uglify, minifies the output file in the dist directory, adding the banner
  • build, builds the regular and minified file
  • test-travis, runs jshint and karma:travis

Use the default task by calling grunt to run tests on PhantomJS and builds the regular and minified file.

Contribute

To contribute, please follow the generic AngularJS Contributing Guidelines, with the only exception to send the PR to the develop branch instead of master.

License

  Copyright 2014-2015 Francesco Pontillo

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.