-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to set a max percentage
- Loading branch information
Showing
8 changed files
with
90 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
/** | ||
* Useful filters for AngularJS | ||
* @version v1.3.0 - 2016-04-04 * @link https://github.com/exceptionless/angular-filters | ||
* @version v1.3.1 - 2016-09-26 * @link https://github.com/exceptionless/ng-filters | ||
* @author Blake Niemyjski <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
*/(function () { | ||
*/ | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('angular-filters', []); | ||
|
@@ -74,21 +75,31 @@ | |
|
||
angular.module('angular-filters') | ||
.filter('percentage', ['$filter', function ($filter) { | ||
return function(input) { | ||
if (isNaN(input) || input === null || input === '' || input === false || input === true) { | ||
function roundUpToNextTenth(input) { | ||
input = parseFloat(input.toFixed(5)); | ||
|
||
// Shift | ||
input = input.toString().split('e'); | ||
input = Math.ceil(+(input[0] + 'e' + (input[1] ? (+input[1] + 1) : 1))); | ||
// Shift back | ||
input = input.toString().split('e'); | ||
|
||
return +(input[0] + 'e' + (input[1] ? (+input[1] - 1) : -1)); | ||
} | ||
|
||
return function(input, max) { | ||
input = parseFloat(input); | ||
if (!isFinite(input)) { | ||
return '0%'; | ||
} | ||
|
||
if (input > 0.0 && input < 1) { | ||
// Shift | ||
input = input.toString().split('e'); | ||
input = Math.ceil(+(input[0] + 'e' + (input[1] ? (+input[1] + 1) : 1))); | ||
// Shift back | ||
input = input.toString().split('e'); | ||
return +(input[0] + 'e' + (input[1] ? (+input[1] - 1) : -1)) + '%'; | ||
input = Math.floor(input) + roundUpToNextTenth(input - Math.floor(input)); | ||
max = parseFloat(max); | ||
if (isFinite(max) && input > max) { | ||
return max + '%'; | ||
} | ||
|
||
return $filter('number')(input, (input % 1 === 0) ? 0 : 1) + '%'; | ||
return parseFloat($filter('number')(input, (input % 1 === 0) ? 0 : 1)) + '%'; | ||
}; | ||
}]); | ||
}()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"name": "ng-filters", | ||
"description": "Useful filters for AngularJS", | ||
"version": "1.3.0", | ||
"filename": "angular-filters.min.js", | ||
"main": "./dist/angular-filters.min.js", | ||
"homepage": "https://github.com/exceptionless/angular-filters", | ||
"version": "1.3.1", | ||
"filename": "ng-filters.js", | ||
"main": "./dist/ng-filters.js", | ||
"homepage": "https://github.com/exceptionless/ng-filters", | ||
"author": "Blake Niemyjski <[email protected]>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/exceptionless/angular-filters.git" | ||
"url": "git://github.com/exceptionless/ng-filters.git" | ||
}, | ||
"keywords": [ | ||
"angular", | ||
|
@@ -27,25 +27,25 @@ | |
} | ||
], | ||
"dependencies": { | ||
"angular": "^1.5.3", | ||
"angular-mocks": "^1.5.3" | ||
"angular": "^1.5.8", | ||
"angular-mocks": "^1.5.8" | ||
}, | ||
"devDependencies": { | ||
"grunt": "0.4.5", | ||
"grunt": "1.0.1", | ||
"grunt-bower": "0.21", | ||
"grunt-bower-task": "0.4", | ||
"grunt-cli": "1.2.0", | ||
"grunt-contrib-concat": "1.0", | ||
"grunt-contrib-jshint": "1.0", | ||
"grunt-contrib-uglify": "1.0", | ||
"grunt-conventional-changelog": "6.1.0", | ||
"grunt-karma": "0.12", | ||
"jasmine-core": "2.4.1", | ||
"karma": "0.13.22", | ||
"karma-jasmine": "0.3.8", | ||
"karma-mocha-reporter": "2.0.0", | ||
"karma-phantomjs-launcher": "1.0.0", | ||
"phantomjs-prebuilt": "2.1.7" | ||
"grunt-karma": "2.0", | ||
"jasmine-core": "2.5.2", | ||
"karma": "1.3.0", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-jasmine": "1.0.2", | ||
"karma-mocha-reporter": "2.2.0", | ||
"karma-phantomjs-launcher": "1.0.2", | ||
"phantomjs-prebuilt": "2.1.12" | ||
}, | ||
"scripts": { | ||
"test": "grunt test --verbose" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters