Skip to content

Commit

Permalink
Percentage and Booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed Nov 27, 2016
1 parent c7ddb49 commit 9bba98d
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 50 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- [Math](#Math)
- [min](#min)
- [max](#max)
- [percent](#percent)
- [percentage](#percentage)
- [ceil](#ceil)
- [floor](#floor)
- [round](#round)
Expand Down Expand Up @@ -470,9 +470,9 @@ API: `array | sum`
<p>{{ [1, 2, 3, 4] | sum }}</p> <!-- Output: "10" -->
```

### percent
### percentage

Returns percent between numbers
Returns percentage between numbers

API: `number | percentage: [total | default = 100]: [floor | default = false]`

Expand Down Expand Up @@ -564,7 +564,7 @@ Returns bytes with a unit symbol
API: `number | bytes`

```html
<p>{{ 10 | bytes }}</p> <!-- Output: "1 B" -->
<p>{{ 10 | bytes }}</p> <!-- Output: "10 B" -->
<p>{{ 1000 | bytes }}</p> <!-- Output: "1 KB" -->
<p>{{ 1000000 | bytes }}</p> <!-- Output: "1 MB" -->
<p>{{ 1000000000 | bytes }}</p> <!-- Output: "1 GB" -->
Expand Down
2 changes: 1 addition & 1 deletion bin/app/pipes/boolean/boolean.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IsGreaterEqualThanPipe } from "./is-greater-equal-than";
import { IsGreaterEqualThanPipe } from './is-greater-equal-than';
export declare const BOOLEAN_PIPES: typeof IsGreaterEqualThanPipe[];
34 changes: 18 additions & 16 deletions bin/app/pipes/boolean/boolean.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/app/pipes/boolean/boolean.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/app/pipes/math/math.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/app/pipes/math/math.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bin/app/pipes/math/percentage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PipeTransform } from '@angular/core';
export declare class PercentagePipe implements PipeTransform {
transform(num: number, total?: number, floor?: boolean): number;
}
33 changes: 33 additions & 0 deletions bin/app/pipes/math/percentage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/app/pipes/math/percentage.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-pipes",
"version": "0.4.10",
"version": "0.4.12",
"author": "Dan Revah",
"description": "Useful angular2 pipes",
"license": "MIT",
Expand Down
34 changes: 18 additions & 16 deletions src/app/pipes/boolean/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import {IsDefinedPipe} from "./is-defined";
import {IsNullPipe} from "./is-null";
import {IsUndefinedPipe} from "./is-undefined";
import {IsStringPipe} from "./is-string";
import {IsFunctionPipe} from "./is-function";
import {IsNumberPipe} from "./is-number";
import {IsArrayPipe} from "./is-array";
import {IsObjectPipe} from "./is-object";
import {IsGreaterEqualThanPipe} from "./is-greater-equal-than";
import {IsGreaterThanPipe} from "./is-greater-than";
import {IsLessEqualThanPipe} from "./is-less-equal-than";
import {IsEqualToPipe} from "./is-equal-to";
import {IsNotEqualToPipe} from "./is-not-equal-to";
import {IsIdenticalToPipe} from "./is-identical-to";
import {IsNotIdenticalToPipe} from "./is-not-identical-to";
import {IsDefinedPipe} from './is-defined';
import {IsNullPipe} from './is-null';
import {IsUndefinedPipe} from './is-undefined';
import {IsStringPipe} from './is-string';
import {IsFunctionPipe} from './is-function';
import {IsNumberPipe} from './is-number';
import {IsArrayPipe} from './is-array';
import {IsObjectPipe} from './is-object';
import {IsGreaterEqualThanPipe} from './is-greater-equal-than';
import {IsGreaterThanPipe} from './is-greater-than';
import {IsLessEqualThanPipe} from './is-less-equal-than';
import {IsEqualToPipe} from './is-equal-to';
import {IsNotEqualToPipe} from './is-not-equal-to';
import {IsIdenticalToPipe} from './is-identical-to';
import {IsNotIdenticalToPipe} from './is-not-identical-to';
import {IsLessThanPipe} from './is-less-than';

export const BOOLEAN_PIPES = [
IsDefinedPipe, IsNullPipe, IsUndefinedPipe, IsStringPipe, IsFunctionPipe, IsNumberPipe,
IsArrayPipe, IsObjectPipe, IsGreaterEqualThanPipe, IsGreaterThanPipe, IsLessEqualThanPipe,
IsLessEqualThanPipe, IsEqualToPipe, IsNotEqualToPipe, IsIdenticalToPipe, IsNotIdenticalToPipe
IsLessEqualThanPipe, IsEqualToPipe, IsNotEqualToPipe, IsIdenticalToPipe, IsNotIdenticalToPipe,
IsLessThanPipe
];
4 changes: 2 additions & 2 deletions src/app/pipes/math/math.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {MaxPipe} from './max';
import {MinPipe} from './min';
import {PercentPipe} from './percent';
import {PercentagePipe} from './percentage';
import {SumPipe} from './sum';
import {FloorPipe} from './floor';
import {RoundPipe} from './round';
Expand All @@ -12,6 +12,6 @@ import {BytesPipe} from './bytes';
import {RadiansPipe} from "./radians";

export const MATH_PIPES = [
MaxPipe, MinPipe, PercentPipe, SumPipe, FloorPipe, RoundPipe, SqrtPipe, PowerPipe,
MaxPipe, MinPipe, PercentagePipe, SumPipe, FloorPipe, RoundPipe, SqrtPipe, PowerPipe,
CeilPipe, DegreesPipe, BytesPipe, RadiansPipe
];
8 changes: 4 additions & 4 deletions src/app/pipes/math/percent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {PercentPipe} from "./percent";
import {PercentagePipe} from './percentage';

describe('PercentPipe', () => {
let pipe: PercentPipe;
describe('PercentagePipe', () => {
let pipe: PercentagePipe;

beforeEach(() => {
pipe = new PercentPipe();
pipe = new PercentagePipe();
});

it('should return percent between numbers', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {PipeTransform, Pipe, Injectable} from '@angular/core';

@Injectable()
@Pipe({name: 'percent'})
export class PercentPipe implements PipeTransform {
@Pipe({name: 'percentage'})
export class PercentagePipe implements PipeTransform {

transform(num: number, total: number = 100, floor: boolean = false): number {
if (isNaN(num)) {
Expand Down

0 comments on commit 9bba98d

Please sign in to comment.