From 168aebcf7068af8761c604bab715121b48b5d527 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Wed, 14 Dec 2016 23:35:37 +0200 Subject: [PATCH 01/25] Update README.md --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d4cd8cf1..9255961f 100644 --- a/README.md +++ b/README.md @@ -554,20 +554,12 @@ Returns object of grouped by items by discriminator API: `array | groupBy: [string | Function]` -```javascript -import {GroupByPipe} from 'ng2-pipes/src/app/pipes/array/group-by'; - -@Component({ - // ... - providers: [GroupByPipe] -}) -export class AppComponent { - constructor(private groupByPipe: GroupByPipe) { - // .. - const arrayObject = [{elm: 'foo', value: 0}, {elm: 'bar', value: 1}, {elm: 'foo', value: 2}]; - const groupedObject = groupByPipe.transform(arrayObject, 'elm')); - // `groupedObject` -> Contains: {foo: [{elm: 'foo', value: 0}, {elm: 'foo', value: 2}], bar: [{elm: 'bar', value: 1}]} - } +```typescript +this.arrayObject = [{elm: 'foo', value: 0}, {elm: 'bar', value: 1}, {elm: 'foo', value: 2}]; +``` + +```html +

{{ arrayObject | groupBy: 'elm' }}

``` ## Object From 5076b996db812e1ba6a6a9095f0b10d43bff98c7 Mon Sep 17 00:00:00 2001 From: danrevah Date: Fri, 16 Dec 2016 01:46:30 +0200 Subject: [PATCH 02/25] style(): Code re-order --- src/app/pipes/array/flatten.ts | 7 +++++-- src/app/pipes/array/intersection.ts | 8 ++++++-- src/app/pipes/array/reverse.ts | 11 ++++++----- src/app/pipes/array/union.ts | 15 ++++++++------- src/app/pipes/boolean/is-defined.ts | 3 ++- src/app/pipes/boolean/is-function.ts | 3 ++- src/app/pipes/boolean/is-object.ts | 3 ++- src/app/pipes/boolean/is-string.ts | 3 ++- src/app/pipes/math/bytes.ts | 15 +++++++-------- src/app/pipes/math/pow.ts | 4 +++- src/app/pipes/math/sqrt.ts | 4 +++- src/app/pipes/math/sum.ts | 6 +++--- src/app/pipes/object/invert-by.ts | 11 +++++------ src/app/pipes/string/scan.ts | 2 +- src/app/pipes/string/shorten.ts | 2 ++ 15 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/app/pipes/array/flatten.ts b/src/app/pipes/array/flatten.ts index f106b085..7e83f6f2 100644 --- a/src/app/pipes/array/flatten.ts +++ b/src/app/pipes/array/flatten.ts @@ -14,7 +14,10 @@ export class FlattenPipe implements PipeTransform { } private flatten(array: any[]): any[] { - return array.reduce((arr: any[], elm: any) => elm instanceof Array ? - arr.concat(this.flatten(elm)) : arr.concat(elm), []); + return array.reduce((arr: any[], elm: any) => + Array.isArray(elm) + ? arr.concat(this.flatten(elm)) + : arr.concat(elm) + , []); } } diff --git a/src/app/pipes/array/intersection.ts b/src/app/pipes/array/intersection.ts index 591718ec..5a4fb7a4 100644 --- a/src/app/pipes/array/intersection.ts +++ b/src/app/pipes/array/intersection.ts @@ -4,8 +4,12 @@ import {PipeTransform, Pipe} from '@angular/core'; export class IntersectionPipe implements PipeTransform { transform(arr: any, ...args: any[]): any[] { - return !Array.isArray(arr) ? arr : args.reduce((newArr, currArr) => { - return newArr.filter(elm => !!~currArr.indexOf(elm)) + if (!Array.isArray(arr)) { + return arr; + } + + return args.reduce((newArr, currArr) => { + return newArr.filter(elm => !!~currArr.indexOf(elm)); }, arr); } } diff --git a/src/app/pipes/array/reverse.ts b/src/app/pipes/array/reverse.ts index fc139570..a7d943e6 100644 --- a/src/app/pipes/array/reverse.ts +++ b/src/app/pipes/array/reverse.ts @@ -1,16 +1,17 @@ import {PipeTransform, Pipe} from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'reverse'}) export class ReversePipe implements PipeTransform { transform(value: any): any { - if (typeof value === 'string') { + if (GeneralHelper.isString(value)) { return value.split('').reverse().join(''); } - if (Array.isArray(value)) { - return value.reverse(); - } - return value; + + return Array.isArray(value) + ? value.reverse() + : value; } } diff --git a/src/app/pipes/array/union.ts b/src/app/pipes/array/union.ts index 25666b7e..f21162e6 100644 --- a/src/app/pipes/array/union.ts +++ b/src/app/pipes/array/union.ts @@ -4,14 +4,15 @@ import {PipeTransform, Pipe} from '@angular/core'; export class UnionPipe implements PipeTransform { transform(arr: any, args: any[] = []): any[] { - return (!Array.isArray(arr) || !Array.isArray(args)) - ? arr - : args.reduce((newArr, currArr) => { + if (!Array.isArray(arr) || !Array.isArray(args)) { + return arr; + } + + return args.reduce((newArr, currArr) => { return newArr.concat(currArr.reduce((noDupArr, curr) => { - if (!~noDupArr.indexOf(curr) && !~newArr.indexOf(curr)) { - noDupArr.push(curr); - } - return noDupArr; + return (!~noDupArr.indexOf(curr) && !~newArr.indexOf(curr)) + ? noDupArr.concat([curr]) + : noDupArr; }, [])); }, arr); } diff --git a/src/app/pipes/boolean/is-defined.ts b/src/app/pipes/boolean/is-defined.ts index ea296af6..5d3ccb63 100644 --- a/src/app/pipes/boolean/is-defined.ts +++ b/src/app/pipes/boolean/is-defined.ts @@ -1,9 +1,10 @@ import {PipeTransform, Pipe} from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'isDefined'}) export class IsDefinedPipe implements PipeTransform { transform(value: any): boolean { - return typeof value !== 'undefined'; + return !GeneralHelper.isUndefined(value); } } diff --git a/src/app/pipes/boolean/is-function.ts b/src/app/pipes/boolean/is-function.ts index 17244a3e..d6d94b02 100644 --- a/src/app/pipes/boolean/is-function.ts +++ b/src/app/pipes/boolean/is-function.ts @@ -1,9 +1,10 @@ import {PipeTransform, Pipe} from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'isFunction'}) export class IsFunctionPipe implements PipeTransform { transform(value: any): boolean { - return typeof value === 'function'; + return GeneralHelper.isFunction(value); } } diff --git a/src/app/pipes/boolean/is-object.ts b/src/app/pipes/boolean/is-object.ts index 796cfcbe..76fb92fb 100644 --- a/src/app/pipes/boolean/is-object.ts +++ b/src/app/pipes/boolean/is-object.ts @@ -1,9 +1,10 @@ import {PipeTransform, Pipe} from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'isObject'}) export class IsObjectPipe implements PipeTransform { transform(value: any): boolean { - return value !== null && typeof value === 'object'; + return GeneralHelper.isObject(value); } } diff --git a/src/app/pipes/boolean/is-string.ts b/src/app/pipes/boolean/is-string.ts index 7ac3d2de..e0ba4210 100644 --- a/src/app/pipes/boolean/is-string.ts +++ b/src/app/pipes/boolean/is-string.ts @@ -1,9 +1,10 @@ import {PipeTransform, Pipe} from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'isString'}) export class IsStringPipe implements PipeTransform { transform(value: any): boolean { - return typeof value === 'string'; + return GeneralHelper.isString(value); } } diff --git a/src/app/pipes/math/bytes.ts b/src/app/pipes/math/bytes.ts index 046bf2bb..345b334a 100644 --- a/src/app/pipes/math/bytes.ts +++ b/src/app/pipes/math/bytes.ts @@ -3,20 +3,19 @@ import GeneralHelper from '../helpers/helpers'; @Pipe({name: 'bytes'}) export class BytesPipe implements PipeTransform { + private dictionary: Array<{max: number, type: string}> = [ + { max: 1e3, type: 'B' }, + { max: 1e6, type: 'KB' }, + { max: 1e9, type: 'MB' }, + { max: 1e12, type: 'GB' } + ]; transform(value: number): string | number { if (!GeneralHelper.isNumberFinite(value)) { return NaN; } - const dictionary: Array<{max: number, type: string}> = [ - { max: 1e3, type: 'B' }, - { max: 1e6, type: 'KB' }, - { max: 1e9, type: 'MB' }, - { max: 1e12, type: 'GB' } - ]; - - const format = dictionary.find(d => value < d.max) || dictionary[dictionary.length - 1]; + const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1]; const num = value / (format.max / 1e3); return `${num} ${format.type}`; } diff --git a/src/app/pipes/math/pow.ts b/src/app/pipes/math/pow.ts index 6796d217..f554c945 100644 --- a/src/app/pipes/math/pow.ts +++ b/src/app/pipes/math/pow.ts @@ -4,6 +4,8 @@ import {PipeTransform, Pipe} from '@angular/core'; export class PowerPipe implements PipeTransform { transform(num: number, power: number = 2): number { - return isNaN(num) ? num : num ** power; + return !isNaN(num) + ? num ** power + : num ; } } diff --git a/src/app/pipes/math/sqrt.ts b/src/app/pipes/math/sqrt.ts index e118e45d..7fad19e9 100644 --- a/src/app/pipes/math/sqrt.ts +++ b/src/app/pipes/math/sqrt.ts @@ -4,6 +4,8 @@ import {PipeTransform, Pipe} from '@angular/core'; export class SqrtPipe implements PipeTransform { transform(num: number): number { - return isNaN(num) ? num : Math.sqrt(num); + return !isNaN(num) + ? Math.sqrt(num) + : num; } } diff --git a/src/app/pipes/math/sum.ts b/src/app/pipes/math/sum.ts index 991ba142..5a0947b8 100644 --- a/src/app/pipes/math/sum.ts +++ b/src/app/pipes/math/sum.ts @@ -4,8 +4,8 @@ import {PipeTransform, Pipe} from '@angular/core'; export class SumPipe implements PipeTransform { transform(arr: number[]): number|number[] { - return !Array.isArray(arr) - ? arr - : arr.reduce((sum, curr) => sum + curr, 0); + return Array.isArray(arr) + ? arr.reduce((sum, curr) => sum + curr, 0) + : arr; } } diff --git a/src/app/pipes/object/invert-by.ts b/src/app/pipes/object/invert-by.ts index e0aefeaa..6bd4e63a 100644 --- a/src/app/pipes/object/invert-by.ts +++ b/src/app/pipes/object/invert-by.ts @@ -9,12 +9,11 @@ export class InvertByPipe implements PipeTransform { return obj; } - return Object.keys(obj) - .reduce((o, k) => { - const key = cb ? cb(obj[k]) : obj[k]; - return Array.isArray(o[key]) - ? (o[key].push(k), o) - : Object.assign(o, {[key]: [k]}); + return Object.keys(obj).reduce((o, k) => { + const key = cb ? cb(obj[k]) : obj[k]; + return Array.isArray(o[key]) + ? (o[key].push(k), o) + : Object.assign(o, {[key]: [k]}); }, {}); } } diff --git a/src/app/pipes/string/scan.ts b/src/app/pipes/string/scan.ts index 5a781b86..6f91828e 100644 --- a/src/app/pipes/string/scan.ts +++ b/src/app/pipes/string/scan.ts @@ -6,7 +6,7 @@ export class ScanPipe implements PipeTransform { transform(text: string, args: string[] = []): string { return GeneralHelper.isString(text) - ? text.replace(/\{(\d+)}/g, (match, index) => typeof (args[index]) !== 'undefined' ? args[index] : match) + ? text.replace(/\{(\d+)}/g, (match, index) => !GeneralHelper.isUndefined(args[index]) ? args[index] : match) : text; } } diff --git a/src/app/pipes/string/shorten.ts b/src/app/pipes/string/shorten.ts index f8795f7a..94dd4c73 100644 --- a/src/app/pipes/string/shorten.ts +++ b/src/app/pipes/string/shorten.ts @@ -8,10 +8,12 @@ export class ShortenPipe implements PipeTransform { if (!GeneralHelper.isString(text)) { return text; } + if (text.length > length) { if (wordBreak) { return text.slice(0, length) + suffix; } + if (!!~text.indexOf(' ', length)) { return text.slice(0, text.indexOf(' ', length)) + suffix; } From 211f00a94ae2c75c39eaf8b32c3130bdc6f2a19f Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Wed, 14 Dec 2016 23:35:37 +0200 Subject: [PATCH 03/25] Update README.md --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d4cd8cf1..9255961f 100644 --- a/README.md +++ b/README.md @@ -554,20 +554,12 @@ Returns object of grouped by items by discriminator API: `array | groupBy: [string | Function]` -```javascript -import {GroupByPipe} from 'ng2-pipes/src/app/pipes/array/group-by'; - -@Component({ - // ... - providers: [GroupByPipe] -}) -export class AppComponent { - constructor(private groupByPipe: GroupByPipe) { - // .. - const arrayObject = [{elm: 'foo', value: 0}, {elm: 'bar', value: 1}, {elm: 'foo', value: 2}]; - const groupedObject = groupByPipe.transform(arrayObject, 'elm')); - // `groupedObject` -> Contains: {foo: [{elm: 'foo', value: 0}, {elm: 'foo', value: 2}], bar: [{elm: 'bar', value: 1}]} - } +```typescript +this.arrayObject = [{elm: 'foo', value: 0}, {elm: 'bar', value: 1}, {elm: 'foo', value: 2}]; +``` + +```html +

{{ arrayObject | groupBy: 'elm' }}

``` ## Object From 31aa3ae47f89cab35e37c7fd7378c700ebc7d06f Mon Sep 17 00:00:00 2001 From: danrevah Date: Mon, 19 Dec 2016 14:03:44 +0200 Subject: [PATCH 04/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9255961f..e920cf5d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Angular 2 - Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) +# Angular 2+ - Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular2. From 9c65bde09b20becfa60b430f40326fd406ac7173 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Mon, 19 Dec 2016 14:04:18 +0200 Subject: [PATCH 05/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e920cf5d..538befb3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Angular 2+ - Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) +# Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular2. From 0332cf28ef679cc204dc50184d055c7102b4c212 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Mon, 19 Dec 2016 14:05:27 +0200 Subject: [PATCH 06/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 538befb3..5e215024 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) -> Useful pipes for Angular2. +> Useful pipes for Angular 2. ## Table of contents From 86b7c21e5870b6ce7055a192537f489b97339779 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Mon, 19 Dec 2016 14:05:35 +0200 Subject: [PATCH 07/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e215024..367333bf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) -> Useful pipes for Angular 2. +> Useful pipes for Angular 2 ## Table of contents From 877f64700b27e2de42ede8eabc1ad34eb3bfc7c2 Mon Sep 17 00:00:00 2001 From: danrevah Date: Mon, 19 Dec 2016 14:06:32 +0200 Subject: [PATCH 08/25] Bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 856edfac..d63ec9af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.5.4", + "version": "0.5.5", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", @@ -27,7 +27,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/danrevah/ng2-pipes.git" + "url": "https://github.com/danrevah/ng-pipes.git" }, "devDependencies": { "@angular/common": "^2.1.0", From 7ab0a9cdb9c49162d387a3409a95ba7a8b2d86a1 Mon Sep 17 00:00:00 2001 From: danrevah Date: Mon, 19 Dec 2016 14:07:56 +0200 Subject: [PATCH 09/25] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d63ec9af..701fd621 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.5.5", + "version": "0.5.6", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", From e756f0a89c81356e91c3cd39321e1e707789c28e Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Tue, 20 Dec 2016 23:12:51 +0200 Subject: [PATCH 10/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 367333bf..07c8a347 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng2-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng2-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) +# Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular 2 From 4efcc2a3868e5f4ccd0d4fcea996275093c4a61b Mon Sep 17 00:00:00 2001 From: danrevah Date: Wed, 21 Dec 2016 12:13:00 +0200 Subject: [PATCH 11/25] Bump version --- .gitignore | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f73c0b72..3a766638 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ coverage/ npm-debug.log testem.log /typings +yarn-error.log # e2e /e2e/*.js diff --git a/package.json b/package.json index 701fd621..5883fafb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.5.6", + "version": "0.5.7", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", From b4c45bb108ca0803b9851b3743b9b137d382bc9d Mon Sep 17 00:00:00 2001 From: danrevah Date: Wed, 21 Dec 2016 12:17:43 +0200 Subject: [PATCH 12/25] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5883fafb..6c93f1fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.5.7", + "version": "0.5.8", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", From 0ad21371f12d3dc9c5c33d5a6d694b6c22c1db9c Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Thu, 22 Dec 2016 20:25:17 +0200 Subject: [PATCH 13/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07c8a347..da65800c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) -> Useful pipes for Angular 2 +> Useful pipes for Angular 2+ with no external dependencies! ## Table of contents From 9f6c34c587d515368b63a950250f203300d66ec2 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Thu, 22 Dec 2016 20:28:36 +0200 Subject: [PATCH 14/25] Set theme jekyll-theme-slate --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 00000000..c7418817 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file From fd7705df258986551ec65d01dd90eb2bcf5a9821 Mon Sep 17 00:00:00 2001 From: danrevah Date: Thu, 22 Dec 2016 20:34:06 +0200 Subject: [PATCH 15/25] Remove theme --- _config.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 _config.yml diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c7418817..00000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-slate \ No newline at end of file From 3920891e807f34afdcbb13692d9a38b9f19cfcfd Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sat, 24 Dec 2016 19:09:41 +0200 Subject: [PATCH 16/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da65800c..6ce2b9f8 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ - [every](#every) - [some](#some) - [sample](#sample) - - [groupBy](#groupBy) + - [groupBy](#groupby) - [Object](#object) - [keys](#keys) - [values](#values) From 3a9c8ede860c3a6481104ac72ba0b9e901c9bc0f Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 10:07:39 +0200 Subject: [PATCH 17/25] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ce2b9f8..228541a8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) +# Angular Pipes +[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular 2+ with no external dependencies! From 6cb49377c11e404e9826b943a9147dc24fc61a7b Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 10:08:02 +0200 Subject: [PATCH 18/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 228541a8..1a5067f4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Angular Pipes +# Angular 2+ Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular 2+ with no external dependencies! From 8ce1652c3a874eec3e550ecc5cbc92bde6ea08bb Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 10:09:24 +0200 Subject: [PATCH 19/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a5067f4..228541a8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Angular 2+ Pipes +# Angular Pipes [![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) > Useful pipes for Angular 2+ with no external dependencies! From 95bd450051f7c8455838568112835127779dff01 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 10:11:52 +0200 Subject: [PATCH 20/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 228541a8..8263da90 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Angular Pipes -[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng2-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng2-pipes?branch=master) +[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) > Useful pipes for Angular 2+ with no external dependencies! From 669537a4dc7bfa714a8dee99ee9053ec4d653c3a Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 11:22:16 +0200 Subject: [PATCH 21/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8263da90..e9b4b0ea 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Angular Pipes -[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) +[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) [![npm](https://img.shields.io/npm/dt/ng2-pipes.svg)](https://www.npmjs.com/package/ng2-pipes) > Useful pipes for Angular 2+ with no external dependencies! From 19aba9425ece237148627feb2125a3de2df14b32 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 11:26:04 +0200 Subject: [PATCH 22/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9b4b0ea..cc8baa1e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Angular Pipes -[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) [![npm](https://img.shields.io/npm/dt/ng2-pipes.svg)](https://www.npmjs.com/package/ng2-pipes) +[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) [![npm](https://img.shields.io/npm/dt/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) > Useful pipes for Angular 2+ with no external dependencies! From 5b225ce76024c10c5c6f96293a95f28eaf98f706 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sun, 25 Dec 2016 11:27:21 +0200 Subject: [PATCH 23/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc8baa1e..3cf6ea4b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Angular Pipes -[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) [![npm](https://img.shields.io/npm/dt/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) +[![npm](https://img.shields.io/npm/v/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![Travis](https://img.shields.io/travis/danrevah/ng-pipes.svg?style=flat-square)](https://travis-ci.org/danrevah/ng-pipes) [![Coveralls](https://img.shields.io/coveralls/danrevah/ng-pipes.svg?style=flat-square)](https://coveralls.io/github/danrevah/ng-pipes?branch=master) [![npm](https://img.shields.io/npm/dt/ng2-pipes.svg?style=flat-square)](https://www.npmjs.com/package/ng2-pipes) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/danrevah/ng-pipes/blob/master/LICENSE.md) > Useful pipes for Angular 2+ with no external dependencies! From ecdf9e6187799ae6fd31c919cb87b2a694420aef Mon Sep 17 00:00:00 2001 From: danrevah Date: Sun, 25 Dec 2016 16:10:22 +0200 Subject: [PATCH 24/25] Initial Stable --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c93f1fa..2117d6bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.5.8", + "version": "1.0.0", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", From a645b9f0b92eed75fd684fc60d29501409cb04b4 Mon Sep 17 00:00:00 2001 From: spyr0s Date: Thu, 29 Dec 2016 10:39:23 +0200 Subject: [PATCH 25/25] left pad and right pad string pipes --- README.md | 28 +++++++++++++++++++++++++++- src/app/pipes/string/lpad.spec.ts | 30 ++++++++++++++++++++++++++++++ src/app/pipes/string/lpad.ts | 16 ++++++++++++++++ src/app/pipes/string/rpad.spec.ts | 30 ++++++++++++++++++++++++++++++ src/app/pipes/string/rpad.ts | 16 ++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/app/pipes/string/lpad.spec.ts create mode 100644 src/app/pipes/string/lpad.ts create mode 100644 src/app/pipes/string/rpad.spec.ts create mode 100644 src/app/pipes/string/rpad.ts diff --git a/README.md b/README.md index 3cf6ea4b..0558457e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ - [underscore](#underscore) - [test](#test) - [match](#match) + - [lpad](#lpad) + - [rpad](#rpad) - [Array](#Array) - [diff](#diff) - [flatten](#flatten) @@ -262,7 +264,7 @@ API: `string | latinise` ### lines -Removes accents from Latin characters. +Converts a string with new lines into an array of each line. API: `string | lines` @@ -305,6 +307,30 @@ API: `string | match: {RegExp}: {Flags}`

{{'FOO' | match: '^foo': 'i' }}

``` +### lpad + +Left pad a string to a given length using a given pad character (default is a space) + + +API: `string | lpad: length: [padCharacter:string|optional]` + +```html +

{{'foo' | lpad: 5}}

+ +

{{String(3) | lpad: 5: '0'}}

+``` + +### rpad + +Right pad a string to a given length using a given pad character (default is a space) + + +API: `string | rpad: length: [padCharacter:string|optional]` + +```html +

{{'Foo' | rpad: 5: '#'}}

+``` + ## Array ### diff diff --git a/src/app/pipes/string/lpad.spec.ts b/src/app/pipes/string/lpad.spec.ts new file mode 100644 index 00000000..50f3d0a9 --- /dev/null +++ b/src/app/pipes/string/lpad.spec.ts @@ -0,0 +1,30 @@ +import {LeftPadPipe} from "./lpad"; + +describe('LeftPadPipe Tests', () => { + let pipe:LeftPadPipe; + + beforeEach(() => { + pipe = new LeftPadPipe(); + }); + + it('Should left pad with 2 blanks', () => { + let result = pipe.transform('foo', 5); + expect(result).toEqual(' foo'); + }); + + it('Should left pad a number casted to string with 5 zeros', () => { + let result = pipe.transform(String(2), 6, '0'); + expect(result).toEqual('000002'); + }); + + it('Should not add padding', () => { + let result = pipe.transform('foo', 3); + expect(result).toEqual('foo'); + }); + + it('Should not add padding', () => { + let result = pipe.transform('foofoo', 3); + expect(result).toEqual('foofoo'); + }); + +}); diff --git a/src/app/pipes/string/lpad.ts b/src/app/pipes/string/lpad.ts new file mode 100644 index 00000000..67dc9922 --- /dev/null +++ b/src/app/pipes/string/lpad.ts @@ -0,0 +1,16 @@ +import { PipeTransform, Pipe } from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; + +@Pipe({ name: 'lpad' }) +export class LeftPadPipe implements PipeTransform { + + transform(str: string, length: number, padCharacter: string = ' '): string { + if (!GeneralHelper.isString(str) || str.length >= length) { + return str; + } + while (str.length < length) { + str = padCharacter + str; + } + return str; + } +} diff --git a/src/app/pipes/string/rpad.spec.ts b/src/app/pipes/string/rpad.spec.ts new file mode 100644 index 00000000..499014ec --- /dev/null +++ b/src/app/pipes/string/rpad.spec.ts @@ -0,0 +1,30 @@ +import {RightPadPipe} from "./rpad"; + +describe('RightPadPipe Tests', () => { + let pipe: RightPadPipe; + + beforeEach(() => { + pipe = new RightPadPipe(); + }); + + it('Should right pad with 2 blanks', () => { + let result = pipe.transform('foo', 5); + expect(result).toEqual('foo '); + }); + + it('Should right pad a number casted to string with 5 zeros', () => { + let result = pipe.transform(String(2), 6, '0'); + expect(result).toEqual('200000'); + }); + + it('Should not add padding if sting length is the same as length', () => { + let result = pipe.transform('foo', 3); + expect(result).toEqual('foo'); + }); + + it('Should not add padding if sting length is greater than length', () => { + let result = pipe.transform('foofoo', 3); + expect(result).toEqual('foofoo'); + }); + +}); diff --git a/src/app/pipes/string/rpad.ts b/src/app/pipes/string/rpad.ts new file mode 100644 index 00000000..ba7e308d --- /dev/null +++ b/src/app/pipes/string/rpad.ts @@ -0,0 +1,16 @@ +import { PipeTransform, Pipe } from '@angular/core'; +import GeneralHelper from '../helpers/helpers'; + +@Pipe({ name: 'rpad' }) +export class RightPadPipe implements PipeTransform { + + transform(str: string, length: number = 1, padCharacter: string = ' '): string { + if (!GeneralHelper.isString(str) || str.length >= length) { + return str; + } + while (str.length < length) { + str = str + padCharacter; + } + return str; + } +}