Giter VIP home page Giter VIP logo

ngx-pipes's Introduction

NGX-PIPES

npm Package Quality Travis Coveralls npm npm MIT licensed

Useful pipes for Angular with no external dependencies

Table of contents

Installation

  1. Use npm to install the package
$ npm install ngx-pipes --save 
  1. You could either add into your module imports the NgPipesModule in order to add all of the pipes, Or add a specific module such as NgArrayPipesModule, NgObjectPipesModule, NgStringPipesModule, NgMathPipesModule, NgDatePipesModule or NgBooleanPipesModule.
import {NgPipesModule} from 'ngx-pipes';

@NgModule({
 // ...
 imports: [
   // ...
   NgPipesModule
 ]
})
  1. Pipes are also injectable and can be used in Components / Services / etc..
import {ReversePipe} from 'ngx-pipes';

@Component({
  // ..
  providers: [ReversePipe]
})
export class AppComponent {
  constructor(private reversePipe: ReversePipe) {
    this.reversePipe.transform('foo'); // Returns: "oof"
  }
  // ..
}
  1. You can also use pipes as part of your template for ex.
<p>{{ 'foo' | reverse }}</p> <!-- Output: "oof" -->

and it's also possible to stack multiple pipes

<p>{{ ' foo' | ltrim | reverse }}</p> <!-- Output: "oof" -->

Date

timeAgo

Time ago pipe converts date to 'just now', 'X days ago', 'last week', 'X days ago', etc..

Usage: string | timeAgo

import * as moment from 'moment';

const now = new Date();

// timeAgo also supports moment.js objects
const lastWeek = moment().subtract(10, 'days');
<span>Updated: {{now | timeAgo}}</span> <!-- Output: "just now" -->
<span>Updated: {{lastWeek | timeAgo}}</span> <!-- Output: "last week" -->

String

aOrAn

Prefixes input string with "a" or "an".

Usage: string | aOrAn

<span>This is a picture of {{imageDescription | aOrAn}}</span>

repeat

Repeats a string n times

Usage: string | repeat: times: [separator|optional]

<p>{{ 'example' | repeat: 3: '@' }}</p> <!-- Output: "example@example@example" -->

scan

Scans string and replace {i} placeholders by equivalent member of the array

Usage: string | scan: [ARRAY]

<p>{{'Hey {0}, {1}' | scan: ['foo', 'bar']}}</p> <!-- Output: "Hey foo, bar" -->

shorten

Shortening a string by length and providing a custom string to denote an omission

Usage: string | shorten: length: [suffix|optional]: [wordBreak boolean|optional]

<p>{{'Hey foo bar' | shorten: 3: '...'}}</p> <!-- Output: "Hey..." -->

stripTags

Strips a HTML tags from string and providing which tags should not be removed

Usage: string | stripTags: [ARRAY]

<p>{{'<a href="">foo</a> <p class="foo">bar</p>' | stripTags }}</p> <!-- Output: "foo bar" -->
<p>{{'<a href="">foo</a> <p class="foo">bar</p>' | stripTags: 'p'}}</p> <!-- Output: foo <p class="foo">bar</p> -->

ucfirst

Uppercase first letter of first word

<p>{{'foo bar' | ucfirst }}</p> <!-- Output: "Foo bar" -->

ucwords

Uppercase first letter every word

<p>{{'foo bar' | ucwords }}</p> <!-- Output: "Foo Bar" -->
<p>{{'shaquille o'neal' | ucwords }}</p> <!-- Output: "Shaquille O'Neal" -->

trim

Strips characters from the beginning and end of a string (default character is space).

Usage: string | trim: [characters|optional]

<p>{{'  foo  ' | trim }}</p> <!-- Output: "foo" -->
<p>{{'foobarfoo' | trim: 'foo' }}</p> <!-- Output: "bar" -->

ltrim

Strips characters from the beginning of a string (default character is space).

Usage: string | ltrim: [characters|optional]

<p>{{'  foo  ' | ltrim }}</p> <!-- Output: "foo  " -->
<p>{{'foobarfoo' | ltrim: 'foo' }}</p> <!-- Output: "barfoo" -->

rtrim

Strips characters from the end of a string (default character is space).

Usage: string | rtrim: [characters|optional]

<p>{{'  foo  ' | rtrim }}</p> <!-- Output: "  foo" -->
<p>{{'foobarfoo' | rtrim: 'foo' }}</p> <!-- Output: "foobar" -->

reverse

Reverses a string

Usage: string | reverse

<p>{{'foo bar' | reverse }}</p> <!-- Output: "rab oof" -->

slugify

Slugify a string (lower case and add dash between words).

Usage: string | slugify

<p>{{'Foo Bar' | slugify }}</p> <!-- Output: "foo-bar" -->
<p>{{'Some Text To Slugify' | slugify }}</p> <!-- Output: "some-text-to-slugify" -->

camelize

Camelize a string replaces dashes and underscores and converts to camelCase string.

Usage: string | camelize

<p>{{'foo_bar' | camelize }}</p> <!-- Output: "fooBar" -->
<p>{{'some_dashed-with-underscore' | camelize }}</p> <!-- Output: "someDashedWithUnderscore" -->
<p>{{'-dash_first-' | camelize }}</p> <!-- Output: "dashFirst" -->

latinise

Removes accents from Latin characters.

Usage: string | latinise

<p>{{'Féé' | latinise }}</p> <!-- Output: "Fee" -->
<p>{{'foo' | latinise }}</p> <!-- Output: "foo" -->

lines

Converts a string with new lines into an array of each line.

Usage: string | lines

<p>{{'Some\nSentence with\r\nNew line' | lines }}</p> <!-- Output: "['Some', 'Sentence with', 'New line']" -->

underscore

Converts camelCase string to underscore.

Usage: string | underscore

<p>{{'angularIsAwesome' | underscore }}</p> <!-- Output: "angular_is_awesome" -->
<p>{{'FooBar' | underscore }}</p> <!-- Output: "foo_bar" -->

test

Tests if a string matches a pattern.

Usage: string | test: {RegExp}: {Flags}

<p>{{'foo 42' | test: '[\\d]+$': 'g' }}</p> <!-- Output: true -->
<p>{{'42 foo' | test: '[\\d]+$': 'g' }}</p> <!-- Output: false -->
<p>{{'FOO' | test: '^foo': 'i' }}</p> <!-- Output: true -->

match

Returns array of matched elements in string.

Usage: string | match: {RegExp}: {Flags}

<p>{{'foo 42' | match: '[\\d]+$': 'g' }}</p> <!-- Output: '42' -->
<p>{{'42 foo' | match: '[\\d]+$': 'g' }}</p> <!-- Output: null -->
<p>{{'FOO' | match: '^foo': 'i' }}</p> <!-- Output: 'FOO' -->

lpad

Left pad a string to a given length using a given pad character (default is a space)

Usage: string | lpad: length: [padCharacter:string|optional]

<p>{{'foo' | lpad: 5}}</p> <!-- Output: "  foo" -->
<!-- Cast a number to string in order to left pad it with zeros -->
<p>{{String(3) | lpad: 5: '0'}}</p> <!-- Output: "00003" -->

rpad

Right pad a string to a given length using a given pad character (default is a space)

Usage: string | rpad: length: [padCharacter:string|optional]

<p>{{'Foo' | rpad: 5: '#'}}</p> <!-- Output: "Foo##" -->

makePluralString

Make a singular string plural. Optional quantity argument specifies how many of the singular string there are.

Usage: string | makePluralString: [quantity:string|optional]

<span>{{'Painting' | makePluralString}}</span> <!-- Output: "Paintings" -->
<span>{{'Painting' | makePluralString: 1}}</span> <!-- Output: "Painting" -->
<span>{{'One Painting' | makePluralString: 1}}</span> <!-- Output: "One Painting" -->
<span>{{'Painting' | makePluralString: 4}}</span> <!-- Output: "Paintings" -->
<span>{{'Four Painting' | makePluralString: 4}}</span> <!-- Output: "Four Paintings" -->

wrap

Wrap a string between a prefix and a suffix

Usage: string | wrap: prefix: suffix

<p>{{'Foo' | wrap: 'nice prefix ': ' and awesome suffix!'}}</p> <!-- Output: "nice prefix Foo and awesome suffix!" -->

Array

diff

Returns array of diff between arrays

Usage: array | diff: [ARRAY]: [ARRAY]: ... : [ARRAY]

this.items = [1, 2, 3, 4];
<li *ngFor="let item of items | diff: [1, 2]"> <!-- Array: [3, 4] -->

flatten

Flattens nested array, passing shallow will mean it will only be flattened a single level

Usage: array | flatten: [shallow|optional]

this.items = [1,2,3,[4,5,6,[7,8,9],[10,11,12,13,[14],[15],[16, [17]]]]];
<li *ngFor="let item of items | flatten"> 
<!-- Array: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] -->

initial

Slicing off the end of the array by n elements

Usage: array | initial: n

this.items = [first, second, third];
<li *ngFor="let item of items | initial: 1"> <!-- Array: [first, second] -->

tail

Slicing off the start of the array by n elements

Usage: array | tail: n

this.items = [first, second, third];
<li *ngFor="let item of items | tail: 1"> <!-- Array: [second, third] -->

intersection

Returns the intersections of an arrays

Usage: array | intersection: [ARRAY]: [ARRAY]: ... : [ARRAY]

this.items = [1, 2, 3, 4, 5];
<li *ngFor="let item of items | intersection: [1, 2, 3]: [3, 6]"> <!-- Array: [3] -->

range

Returns an array with range of numbers

Usage: range: [start: number, default = '1']: [count: number]: [step: number | optional, default = '1']

this.items = this.rangePipe.transform(1, 5); // Returns: [1, 2, 3, 4, 5]
<li *ngFor="let item of items"> <!-- Array: [1, 2, 3, 4, 5] -->

reverse

Reverses an array

Usage: array | reverse

this.items = [1, 2, 3];
<li *ngFor="let item of items | reverse"> <!-- Array: [3, 2, 1] -->

truthify

Removes un-truthy values from array

Usage: array | truthify

this.items = [null, 1, false, undefined, 2, 0, 3, NaN, 4, ''];
<li *ngFor="let item of items | truthify"> <!-- Array: [1, 2, 3, 4] -->

union

Combine two arrays

Usage: array | union: [ARRAY]

this.items = [1, 2, 3];
<li *ngFor="let item of items | union: [[4]]"> <!-- Array: [1, 2, 3, 4] -->

unique

Removes duplicates from array

Usage: array | unique: 'Property (Optional)'

this.items = [1, 2, 3, 1, 2, 3];
<li *ngFor="let item of items | unique"> <!-- Array: [1, 2, 3] -->

without

Returns array without specific elements

Usage: array | without: [ARRAY]

this.items = [1, 2, 3, 1, 2, 3];
<li *ngFor="let item of items | without: [1,3]"> <!-- Array: [2, 2] -->

pluck

Returns array of properties values

Usage: array | pluck: propertyName

this.items = [
  {
    a: 1, 
    b: {
      c: 4
    }
  }, 
  {
    a: 2, 
    b: {
      c: 5
    }
  }, 
  {
    a: 3, 
    b: {
      c: 6
    }
  }, 
];
<li *ngFor="let item of items | pluck: 'a'"> <!-- Array: [1, 2, 3] -->
<li *ngFor="let item of items | pluck: 'b.c'"> <!-- Array: [4, 5, 6] -->

shuffle

Returns randomly shuffled array

Usage: array | shuffle

this.items = [1, 2, 3, 4, 5, 6];
<li *ngFor="let item of items | shuffle"> <!-- Array: [4, 1, 6, 2, 5, 3] -->

every

Returns true if every elements of the array fits the predicate otherwise false

Usage: array | every: predicate

this.itemsOne = [1, 1, 1];
this.itemsTwo = [1, 1, 2];
this.itemsThree = [2, 2, 2];
this.predicate = (value: any, index: number, array: any[]): boolean => {
  return value === 1;
};
<p>{{ itemsOne | every: predicate }}</p> <!-- Output: "true" -->
<p>{{ itemsTwo | every: predicate }}</p> <!-- Output: "false" -->
<p>{{ itemsThree | every: predicate }}</p> <!-- Output: "false" -->

some

Returns true if some elements of the array fits the predicate otherwise false

Usage: array | some: predicate

this.itemsOne = [1, 1, 1];
this.itemsTwo = [1, 1, 2];
this.itemsThree = [2, 2, 2];
this.predicate = (value: any, index: number, array: any[]): boolean => {
  return value === 1;
};
<p>{{ itemsOne | some: predicate }}</p> <!-- Output: "true" -->
<p>{{ itemsTwo | some: predicate }}</p> <!-- Output: "true" -->
<p>{{ itemsThree | some: predicate }}</p> <!-- Output: "false" -->

sample

Returns sample items randomly from array

Usage: array | sample: [amount | default = 1]

<p>{{ [1, 2, 3, 4] | sample }}</p> <!-- Output: "[2]" -->
<p>{{ [1, 2, 3, 4] | sample: 2 }}</p> <!-- Output: "[4, 3]" -->

groupBy

Returns object of grouped by items by discriminator, and supports nested properties.

Usage: array | groupBy: [string[] | string | Function]: [delimiter: string | optional, default = '|']

this.arrayObject = [
  {id: 1, elm: 'foo', value: 0}, 
  {id: 2, elm: 'bar', value: 1}, 
  {id: 3, elm: 'foo', value: 2}, 
  {id: 4, elm: 'foo', value: 2}
];

this.arrayNestedObject = [
  {id: 1, prop: { deep: 'foo' }},
  {id: 2, prop: { deep: 'bar' }},
  {id: 3, prop: { deep: 'foo' }},
  {id: 4, prop: { deep: 'bar' }}
];
<p>{{ arrayObject | groupBy: 'elm' }}</p> 
<!-- Output: "{foo: [{id: 1, elm: 'foo', value: 0}, {id: 3, elm: 'foo', value: 2}, {id: 4, elm: 'foo', value: 2}], bar: [{id: 2, elm: 'bar', value: 1}]}" -->

<p>{{ arrayObject | groupBy: ['elm', 'value'] }}</p> 
<!-- Output: "{'foo|0': [{elm: foo, value: 0}], 'bar|1': [{elm:bar,value: 1}], 'foo|2': [{elm:foo, value: 2}], 'bar|3': [{elm:bar, value: 3}]}" -->

<p>{{ arrayObject | groupBy: ['elm', 'value']: '_' }}</p> 
<!-- Output: "{foo_0: [{elm: foo, value: 0}], bar_1: [{elm:bar,value: 1}], foo_2: [{elm:foo, value: 2}], bar_3: [{elm:bar, value: 3}]}" -->

<p>{{ arrayNestedObject | groupBy: 'prop.deep' }}</p> 
<!-- Output:{foo: [{id: 1, prop: {deep: foo}}, {id: 3, prop: {deep: foo}}], bar: [{id: 2, prop: {deep: bar}}, {id: 4, prop: {deep: bar}}]}" -->

groupByImpure

Identical to groupBy pipe, the only difference is that it's an impure pipe.

Impure pipes: https://angular.io/guide/pipes#impure-pipes

filterBy

Returns object array of grouped by items by discriminator

Usage: array | filterBy: [prop, nested.prop, ...]: search: [strict | optional]

this.users = [
   {id: 1, first_name: 'John', last_name: 'Doe', work: { company: 'Foo Tech' }},
   {id: 2, first_name: 'Jane', last_name: 'West', work: { company: 'AAA Solutions' }},
   {id: 3, first_name: 'Bruce', last_name: 'John', work: { company: 'Bar Tech' }},
   {id: 4, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]}
];
<!-- Returns users with `id` of 1 -->
<p>{{ users | filterBy: ['id']: 1 }}</p> 
<!-- Output: "[{id: 1, first_name: 'John', last_name: 'Doe', work: { company: 'Foo Tech', previous_company: '' }}]" -->

<!-- filterBy also support nested properties -->
<p>{{ users | filterBy: ['work.company']: 'Bar Tech' }}</p> 
<!-- Output: "[{ "id": 3, "first_name": "Bruce", "last_name": "John", "work": { "company": "Bar Tech", "previous_company": "" } }]" -->

<!-- filterBy also support nested properties inside of an array -->
<p>{{ users | filterBy: ['arr.name']: 'foo' }}</p> 
<!-- Output: "[{id: 4, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]}]" -->

<!-- Return users whose first name or last name is 'John'. -->
<p>{{ users | filterBy: ['first_name', 'last_name']: 'John' }}</p>
<!-- Output: "[{id: 1, first_name: 'John', last_name: 'Doe', work: { company: 'Foo Tech', previous_company: '' }}]" -->

<!-- Return users whose first name or last name is 'John' or 'Cent'. -->
<p>{{ users | filterBy: ['first_name', 'last_name']: ['John', 'Cent'] }}</p>
<!-- Output: "[{id: 1, first_name: 'John', last_name: 'Doe', work: { company: 'Foo Tech', previous_company: '' }}, {id: 3, first_name: 'Bruce', last_name: 'John', work: { company: 'Bar Tech' }}, {id: 4, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]}]" -->

filterByImpure

Identical to filterBy pipe, the only difference is that it's an impure pipe.

Impure pipes: https://angular.io/guide/pipes#impure-pipes

orderBy

Returns ordered array by configuration

Usage: array | orderBy: [prop, nested.prop, array of props, ...]

const numbers = [2, 1, 3];

const obj = [
  {id: 4, name: 'Dave', amount: 2},
  {id: 2, name: 'Michael', amount: 2},
  {id: 3, name: 'Dan', amount: 1},
  {id: 1, name: 'John', amount: 1}
];

const deepObj = [
  {id: 1, name: 'John', amount: 1337, deep: {prop: 4}},
  {id: 2, name: 'Michael', amount: 42, deep: {prop: 2}},
  {id: 3, name: 'Dan', amount: 1, deep: {prop: 1}},
  {id: 4, name: 'Dave', amount: 2, deep: {prop: 3}}
];
<!-- Returns array ordered by value -->
<p>{{ numbers | orderBy }}</p>  <!-- Output: [1, 2, 3] -->
<p>{{ numbers | orderBy: '-' }}</p>  <!-- Output: [3, 2, 1] -->

<!-- Returns array ordered by value of property -->
<p>{{ deepObj | orderBy: 'amount' }}</p>  
<!-- Output: [{id: 3, ...}, {id: 4, ...}, {id: 2, ...}, {id: 1, ...}] -->
<p>{{ deepObj | orderBy: '-amount' }}</p>  
<!-- Output: [{id: 1, ...}, {id: 2, ...}, {id: 4, ...}, {id: 3, ...}] -->

<!-- Returns array ordered by value of deep property -->
<p>{{ deepObj | orderBy: 'deep.prop' }}</p>  
<!-- Output: [{id: 3, ...}, {id: 2, ...}, {id: 4, ...}, {id: 1, ...}] -->
<p>{{ deepObj | orderBy: '-deep.prop' }}</p>  
<!-- Output: [{id: 1, ...}, {id: 4, ...}, {id: 2, ...}, {id: 3, ...}] -->

<!-- Returns array ordered by mutliple properties -->
<p>{{ obj | orderBy: ['amount', 'id'] }}</p>  
<!-- Output: [{id: 1, ...}, {id: 3, ...}, {id: 2, ...}, {id: 4, ...}] -->

orderByImpure

Identical to orderBy pipe, the only difference is that it's an impure pipe.

Impure pipes: https://angular.io/guide/pipes#impure-pipes

chunk

Returns chunked array or string by size

Usage: array | size: [number | default = 1]

<p>{{ [1, 2, 3, 4, 5] | chunk: 2 }}</p>
<!-- Output: "[[1, 2], [3, 4], [5]]" -->

fromPairs

Returns object of an array of key value pairs

Usage: array | fromPairs

<p>{{ [['foo', 1], ['bar', 2]] | fromPairs }}</p> <!-- Output: "{foo: 1, bar: 2}" -->
<p>{{ [['foo', [1, 2]], ['bar', [3, 4]]] | fromPairs }}</p> <!-- Output: "{foo: [1, 2], bar: [3, 4]}" -->

Object

keys

Returns array of object keys

Usage: object | keys

<p>{{ {foo: 1, bar: 2} | keys }}</p> <!-- Output: "['foo', 'bar']" -->

values

Returns array of object values

Usage: object | values

<p>{{ {foo: 1, bar: 2} | values }}</p> <!-- Output: "[1, 2]" -->

pairs

Returns array of an object key value pairs

Usage: object | pairs

<p>{{ {foo: 1, bar: 2} | pairs }}</p> <!-- Output: "[['foo', 1], ['bar', 2]]" -->
<p>{{ {foo: [1, 2], bar: [3, 4]} | pairs }}</p> <!-- Output: "[['foo', [1, 2]], ['bar', [3, 4]]]" -->

pick

Returns object with picked keys from object

Usage: object | pick: [key | string]]

<p>{{ {foo: 1, bar: 2} | pick: 'foo' }}</p> <!-- Output: "{foo: 1}" -->
<p>{{ {foo: 1, bar: 2} | pick: 'foo': 'bar' }}</p> <!-- Output: "{foo: 1, bar: 2}" -->

omit

Returns object after omitting keys from object (opposite of pick)

Usage: object | omit: [key | string]]

<p>{{ {foo: 1, bar: 2} | omit: 'foo' }}</p> <!-- Output: "{bar: 2}" -->
<p>{{ {foo: 1, bar: 2} | omit: 'foo': 'bar' }}</p> <!-- Output: "{}" -->

invert

Returns object with inverted keys and values. in case of equal values, subsequent values overwrite property assignments of previous values.

Usage: object | invert

<p>{{ {foo: 1, bar: 2} | invert }}</p> <!-- Output: "{1: 'foo', 2: 'bar'}" -->

invertBy

Returns object with inverted keys and values. in case of equal values, will add to an array.

Usage: object | invertBy: [Function | optional]

this.cb = (value): string => {
  return `name_${value}`;
};
<p>{{ {foo: 1, bar: 2} | invertBy }}</p> <!-- Output: "{1: ['foo'], 2: ['bar']}" -->
<p>{{ {foo: 1, bar: 2} | invertBy: cb }}</p> <!-- Output: "{name_1: ['foo'], name_2: ['bar']}" -->
<p>{{ {a: 1, b: 2, c: 1, d: 2} | invertBy }}</p> <!-- Output: "{1: ['a', 'c'], 2: ['b', 'd']}" -->

diffObj

Returns a diff object of two objects

Usage: object | diffObj: Object

<p>{{ {a: 1} | diffObj: {a: 1} }}</p> <!-- Output: "{}" -->
<p>{{ {a: 1} | diffObj: {a: 2} }}</p> <!-- Output: "{a: 1}" -->
<p>{{ {a: 1, b: 2} | diffObj: {a: 1, b: 1} }}</p> <!-- Output: "{b: 2}" -->
<p>{{ {a: 1, b: 2, c: {d: 3} } | diffObj: {a: 1, b: 1, c: {d: 1} } }}</p> <!-- Output: "{b: 2, c: {d: 3}}" -->

Math

min

Returns the minimum of a given array

Usage: array | min

<p>{{ [1, 2, 3, 1, 2, 3] | min }}</p> <!-- Output: "1" -->

max

Returns the maximum of a given array

Usage: array | max

<p>{{ [1, 2, 3, 1, 2, 3] | max }}</p> <!-- Output: "3" -->

sum

Returns the sum of a given array

Usage: array | sum

<p>{{ [1, 2, 3, 4] | sum }}</p> <!-- Output: "10" -->

average

Returns the average of a given array

Usage: array | average

<p>{{ [1, 2, 3] | average }}</p> <!-- Output: "2" -->
<p>{{ [1, 2] | average }}</p> <!-- Output: "1.5" -->

percentage

Returns percentage between numbers

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

<p>{{ 5 | percentage }}</p> <!-- Output: "5" -->
<p>{{ 5 | percentage: 160 }}</p> <!-- Output: "3.125" -->
<p>{{ 5 | percentage: 160: true }}</p> <!-- Output: "3" -->

ceil

Returns ceil of a number by precision

Usage: number | ceil: [precision | default = 0]

<p>{{ 42.123 | ceil }}</p> <!-- Output: "43" -->
<p>{{ 42.123 | ceil: 2 }}</p> <!-- Output: "42.13" -->

floor

Returns floor of a number by precision

Usage: number | floor: [precision | default = 0]

<p>{{ 42.123 | floor }}</p> <!-- Output: "42" -->
<p>{{ 42.123 | floor: 2 }}</p> <!-- Output: "42.12" -->

round

Returns round of a number by precision

Usage: number | round: [precision | default = 0]

<p>{{ 42.4 | round }}</p> <!-- Output: "42" -->
<p>{{ 42.5 | round }}</p> <!-- Output: "43" -->
<p>{{ 42.123 | round: 2 }}</p> <!-- Output: "42.12" -->

sqrt

Returns the square root of a number

Usage: number | sqrt

<p>{{ 9 | sqrt }}</p> <!-- Output: "3" -->

pow

Returns the power of a number

Usage: number | pow: [power | default = 2]

<p>{{ 3 | pow }}</p> <!-- Output: "9" -->
<p>{{ 3 | pow: 3 }}</p> <!-- Output: "27" -->

degrees

Returns the degrees of a number in radians

Usage: number | degrees

<p>{{ 3.141592653589793 | degrees }}</p> <!-- Output: "180" -->

radians

Returns the radians of a number in degrees

Usage: number | radians

<p>{{ 180 | radians }}</p> <!-- Output: "3.141592653589793" -->

bytes

Returns bytes with a unit symbol

Usage: number | bytes: [precision]

<p>{{ 10 | bytes }}</p> <!-- Output: "10 B" -->
<p>{{ 1048576 | bytes }}</p> <!-- Output: "1 KB" -->
<p>{{ 1073741824 | bytes }}</p> <!-- Output: "1 MB" -->
<p>{{ 1.0995116e12 | bytes }}</p> <!-- Output: "1 GB" -->

Boolean

isNull

Usage: any | isNull

<p>{{ null | isNull }}</p> <!-- Output: "true" -->
<p>{{ 1 | isNull }}</p> <!-- Output: "false" -->

isDefined

Usage: any | isDefined

<p>{{ 1 | isDefined }}</p> <!-- Output: "true" -->
<p>{{ undefined | isDefined }}</p> <!-- Output: "false" -->

isUndefined

Usage: any | isUndefined

<p>{{ 1 | isUndefined }}</p> <!-- Output: "false" -->
<p>{{ undefined | isUndefined }}</p> <!-- Output: "true" -->

isString

Usage: any | isString

<p>{{ 1 | isString }}</p> <!-- Output: "false" -->
<p>{{ '' | isString }}</p> <!-- Output: "true" -->

isNumber

Usage: any | isNumber

this.func = () => {};
this.num = 1;
<p>{{ num | isNumber }}</p> <!-- Output: "true" -->
<p>{{ func | isNumber }}</p> <!-- Output: "false" -->

isArray

Usage: any | isArray

this.arr = [1, 2];
this.num = 1;
<p>{{ num | isArray }}</p> <!-- Output: "false" -->
<p>{{ arr | isArray }}</p> <!-- Output: "true" -->

isObject

Usage: any | isObject

this.obj = {a: 1, b: 2};
this.num = 1;
<p>{{ num | isObject }}</p> <!-- Output: "false" -->
<p>{{ obj | isObject }}</p> <!-- Output: "true" -->

isGreaterThan

Usage: number | isGreaterThan: otherNumber

<p>{{ 1 | isGreaterThan: 1 }}</p> <!-- Output: "false" -->
<p>{{ 1 | isGreaterThan: 2 }}</p> <!-- Output: "false" -->
<p>{{ 2 | isGreaterThan: 1 }}</p> <!-- Output: "true" -->

isGreaterEqualThan

Usage: number | isGreaterEqualThan: otherNumber

<p>{{ 1 | isGreaterEqualThan: 1 }}</p> <!-- Output: "true" -->
<p>{{ 1 | isGreaterEqualThan: 2 }}</p> <!-- Output: "false" -->
<p>{{ 2 | isGreaterEqualThan: 1 }}</p> <!-- Output: "true" -->

isLessThan

Usage: number | isLessThan: otherNumber

<p>{{ 1 | isLessThan: 1 }}</p> <!-- Output: "false" -->
<p>{{ 1 | isLessThan: 2 }}</p> <!-- Output: "true" -->
<p>{{ 2 | isLessThan: 1 }}</p> <!-- Output: "false" -->

isLessEqualThan

Usage: number | isLessEqualThan: otherNumber

<p>{{ 1 | isLessEqualThan: 1 }}</p> <!-- Output: "true" -->
<p>{{ 1 | isLessEqualThan: 2 }}</p> <!-- Output: "true" -->
<p>{{ 2 | isLessEqualThan: 1 }}</p> <!-- Output: "false" -->

isEqualTo

Usage: number | isEqualTo: otherNumber

<p>{{ 1 | isEqualTo: 1 }}</p> <!-- Output: "true" -->
<p>{{ 1 | isEqualTo: '1' }}</p> <!-- Output: "true" -->
<p>{{ 1 | isEqualTo: 2 }}</p> <!-- Output: "false" -->
<p>{{ 2 | isEqualTo: 1 }}</p> <!-- Output: "false" -->

isNotEqualTo

Usage: number | isNotEqualTo: otherNumber

<p>{{ 1 | isNotEqualTo: 1 }}</p> <!-- Output: "false" -->
<p>{{ 1 | isNotEqualTo: '1' }}</p> <!-- Output: "false" -->
<p>{{ 1 | isNotEqualTo: 2 }}</p> <!-- Output: "true" -->
<p>{{ 2 | isNotEqualTo: 1 }}</p> <!-- Output: "true" -->

isIdenticalTo

Usage: number | isIdenticalTo: otherNumber

<p>{{ 1 | isIdenticalTo: 1 }}</p> <!-- Output: "true" -->
<p>{{ 1 | isIdenticalTo: '1' }}</p> <!-- Output: "false" -->
<p>{{ 1 | isIdenticalTo: 2 }}</p> <!-- Output: "false" -->
<p>{{ 2 | isIdenticalTo: 1 }}</p> <!-- Output: "false" -->

isNotIdenticalTo

Usage: number | isNotIdenticalTo: otherNumber

<p>{{ 1 | isNotIdenticalTo: 1 }}</p> <!-- Output: "false" -->
<p>{{ 1 | isNotIdenticalTo: '1' }}</p> <!-- Output: "true" -->
<p>{{ 1 | isNotIdenticalTo: 2 }}</p> <!-- Output: "true" -->
<p>{{ 2 | isNotIdenticalTo: 1 }}</p> <!-- Output: "true" -->

Contributing

  • Before adding any new feature or a fix make sure to open an issue first!

Make sure you have angular-cli & karma installed globally.

$ npm install -g angular-cli karma

Clone the project, and install dependencies.

$ git clone https://github.com/danrevah/ngx-pipes.git
$ npm install

Create a new branch

$ git checkout -b feat/someFeature

Add tests & make sure everything is running properly

$ npm test

Commit & push, and make a pull request!

ngx-pipes's People

Contributors

albejr avatar angular-cli avatar biutas avatar brianjunk avatar cpilson avatar danrevah avatar daraul avatar dependabot[bot] avatar e-cloud avatar felladrin avatar iancamp avatar iarayan avatar maxime1992 avatar nols1000 avatar pavankjadda avatar shaungrady avatar softsimon avatar spyr0s avatar steve3d avatar stumpyfr avatar tiger-seo avatar ttorr3s avatar vdurante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-pipes's Issues

Safe URLs

Create pipes for sanitizing URLs.

ngFor orderBy won't update on array Change

Hello,

I have this code:

<tr *ngFor="let product of products | orderBy: 'id">
   <td>{{ product.id }}</td>
   <td>{{ product.name }}</td>
   <td>{{ product.odooProductId }}</td>
    <td>{{ product.price }} &euro;</td>
</tr>

I also have a button to remove a product.
So, the problem is, that when i remove the object from that products array, nothing changes, even the object that I removed won't dissapear from list.

If i remove orderBy Pipe, the code above updates Ok.

What causes this problem, is there a fix ?

Thanks !!

type of any..

would be great to remove those 'warnings'

/ngx-pipes/src/app/pipes/array/diff.ts(8,29): error TS7006: Parameter 'elm' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/array/intersection.ts(12,28): error TS7006: Parameter 'elm' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/array/sample.ts(11,9): error TS7005: Variable 'sample' implicitly has an 'any[]' type. /ngx-pipes/src/app/pipes/array/union.ts(12,46): error TS7006: Parameter 'noDupArr' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/array/union.ts(12,56): error TS7006: Parameter 'curr' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/helpers/helpers.ts(30,16): error TS7017: Index signature of object type implicitly has an 'any' type. /ngx-pipes/src/app/pipes/object/invert-by.ts(14,28): error TS7017: Index signature of object type implicitly has an 'any'type. /ngx-pipes/src/app/pipes/object/invert-by.ts(15,12): error TS7017: Index signature of object type implicitly has an 'any'type. /ngx-pipes/src/app/pipes/string/camelize.ts(12,55): error TS7006: Parameter 'v' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/camelize.ts(12,70): error TS7006: Parameter 'word' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/camelize.ts(12,76): error TS7006: Parameter 'key' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/latinise.ts(12,39): error TS7006: Parameter '_' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/latinise.ts(12,45): error TS7017: Index signature of object type implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/underscore.ts(9,33): error TS7006: Parameter 'c' implicitly has an 'any' type. /ngx-pipes/src/app/pipes/string/underscore.ts(9,36): error TS7006: Parameter 'k' implicitly has an 'any' type.

Help: Webpack misconfiguration

Hey,

I am trying to import the module on my app, but it is not working directly.
Currently I am building my project with webpack@~0 typesctipt@~2.0 and awesome-typescript-loader@~2

The error I get is:
screenshot from 2017-01-29 12-11-31

After some tests, I wonder if it is a path issue, but all the logs point to tslint.

Weird thing is that I use angular2-text-mask without any issues.
Trying to figure out what is wrong, I see that the ts config is pretty different.

https://github.com/text-mask/text-mask/blob/master/angular2/tsconfig.json

But I don't know yet what is causing this.
Any idea of where the error is coming from? The output is not so helpful also...

Thanks!

Angular Seed & ngx-pipes

Hey there!
I tried to integrate your pipes-module in the angular-seed from mgechev (https://github.com/mgechev/angular-seed/), but got some problems. I opened an issue for it: mgechev/angular-seed#1794.

The last answer was helpful for me - now I can use it in dev. But could you do add this to your project: "The production build won't work out of the box because the author of the library hasn't disabled implicit any. Also, the package is not distributed with metadata.json files which means that AoT won't work neither"

blank page

when i use this one in ts file:
this.feeds = this.groupBy.transform(this.feeds, 'bp');
it seems work great
but whenever i apply to the html file:
{{group | groupBy: 'bp'}}
ionic 2 shows blank page

what i missed out?

Unable to use ngx-pipes with Ionic2

Tried using ngx-pipes with ionic 2 the following error pops up all the time

Module build failed: Error: ENOENT: no such file or directory, open 'node_modules\ngx-pipes\src\app\pipes\array\order-by.js.map' at Error (native)

Can you guide me to right direction?

Thanks

Returns relative number to thousand symbol

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request

Would be great if there is an feature that transform number into a relative values, like bytes already do with a unit symbol.

{{ 1000 | bytes }} <!-- Output: "1 k" -->
{{ 10000 | bytes }} <!-- Output: "10 k" -->
{{ 12000 | bytes }} <!-- Output: "12 k" -->

OrderBy nested object properties, where property is undefined

When i use OrderBy pipe to order my array of objects, depending on a nested object property , which can also be undefined at one or another child of object, i get a strange result. I would expect the result where every object (User), which has the property i orderBy, would be listed before users that dont have that property, but what i get is some users with that propety are at the top, then i get some users with that property undefined or empty stringm then again users which have that property.
How are undefined, empty string or null compared to strings?

Precision parameter for bytes

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request

Currently, there does not appear to be a way to limit the precision of the bytes pipe. {{12345678 | bytes}} outputs 12.345678 MB.

Would be nice to be able to specify the maximum number of digits after the decimal. For example:

{{12345678 | bytes: 2}}

Which would round the output to 12.3 MB.

OrderBy? Any plans to Implement?

So I just stumbled across your library of pipes and it seems quite extensive and you seem to provide updates quite often. I wanted to reach out and see if you've considered an orderBy pipe, and if you have it already please forgive me for not recognizing it.

Thoughts?

Impure pipes

Regarding: #56

Pull-Request are welcome!

  1. Make orderBy pure again
  2. Create orderByImpure & filterByImpure versions
  3. Make sure it's documented in README.md file

If you have any other ideas of filters that should have an impure version comment below.

Separate to modules

Each package should be seprated into a module for ex: NgMathPipes, NgStringPipes, etc..

ngFor doesn't update data with filterBy

I'm submitting a feature request

[ ] bug report
[x] feature request

Current behavior
use filterBy with ngFor and push item into the array, view does not update

Minimal reproduction of the problem with instructions
expression like this
*ngFor="let item of items | filterBy:['name']: keyword;"

What is the motivation / use case for changing the behavior?
use push() instead of creating a new array
ngFor doesn't update data with pipe

Environment:

  • Angular version: 2.4.10

  • Browser: Chrome 57

  • Language: TypeScript 2.2.1

  • Node: node --version = 6.9.5

Module build failed

ERROR in ./~/ngx-pipes/src/app/index.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (C:\Projects\start.slog.no-ng2\node_modules\typescript\lib\typescript.js:6635:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (C:\Projects\start.slog.no-ng2\node_modules\typescript\lib\typescript.js:78683:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (C:\Projects\start.slog.no-ng2\node_modules\typescript\lib\typescript.js:78704:77)
    at refactor.findAstNodes.filter (C:\Projects\start.slog.no-ng2\node_modules\@ngtools\webpack\src\loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (C:\Projects\start.slog.no-ng2\node_modules\@ngtools\webpack\src\loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (C:\Projects\start.slog.no-ng2\node_modules\@ngtools\webpack\src\loader.js:129:10)
    at Promise.resolve.then (C:\Projects\start.slog.no-ng2\node_modules\@ngtools\webpack\src\loader.js:292:33)
 @ ./src/$$_gendir/app/app.module.ngfactory.ts 40:0-52
 @ ./src/main.ts
 @ multi ./src/main.ts

I am using angular cli

Module parse failed Error

I included NgPipesModule in my NgModule imports but I am still getting below error. I'm using this with webpack. Not sure whats going on. Is anyone facing the same issue ?

ERROR in ./~/ngx-pipes/src/app/pipes.module.ts
Module parse failed: /Users/me/Projects/git/app-ui/node_modules/ngx-pipes/src/app/pipes.module.ts Unexpected character '@' (8:0)
You may need an appropriate loader to handle this file type.
| import {NgBooleanPipesModule} from './pipes/boolean/index';
|
| @NgModule({
|   declarations: [],
|   imports: [],
 @ ./~/ngx-pipes/src/app/index.js 5:9-34
 @ ./src/main/webapp/app/vendor.ts
 @ dll vendor

Installation issue

Hello, I have a problem related to the installation.
Folders are there, no errors, package.json its also ok.
Imported on module

I've done everything and I get this on console.log

Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:18 ZoneAwareError

node version 6.9.1

Please help! Thanks !

can't run the solution

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at createSourceFile (F:\ngx-pipes-master\node_modules\typescript\lib\typescript.js:9273:110)
at parseSourceFileWorker (F:\ngx-pipes-master\node_modules\typescript\lib\typescript.js:9231:26)
at Object.parseSourceFile (F:\ngx-pipes-master\node_modules\typescript\lib\typescript.js:9186:26)
at Object.createSourceFile (F:\ngx-pipes-master\node_modules\typescript\lib\typescript.js:9011:29)
at new TypeScriptFileRefactor (F:\ngx-pipes-master\node_modules@ngtools\webpack\src\refactor.js:30:35)
at Object.resolveEntryModuleFromMain (F:\ngx-pipes-master\node_modules@ngtools\webpack\src\entry_resolver.js:105:20)
at AotPlugin._setupOptions (F:\ngx-pipes-master\node_modules@ngtools\webpack\src\plugin.js:138:50)
at new AotPlugin (F:\ngx-pipes-master\node_modules@ngtools\webpack\src\plugin.js:23:14)
at _createAotPlugin (F:\ngx-pipes-master\node_modules@angular\cli\models\webpack-configs\typescript.js:55:12)
at Object.exports.getNonAotConfig (F:\ngx-pipes-master\node_modules@angular\cli\models\webpack-configs\typescript.js:70:19)
at NgCliWebpackConfig.buildConfig (F:\ngx-pipes-master\node_modules@angular\cli\models\webpack-config.js:27:37)
at Class.run (F:\ngx-pipes-master\node_modules@angular\cli\tasks\serve.js:37:98)
at check_port_1.checkPort.then.port (F:\ngx-pipes-master\node_modules@angular\cli\commands\serve.js:103:26)
at process._tickCallback (internal/process/next_tick.js:103:7)
PS F:\ngx-pipes-master>

Cannot read property 'length' of undefined

error_handler.js:47 EXCEPTION: Error in ./AppComponent class AppComponent - inline template:39:110 caused by: Cannot read property 'length' of undefinedErrorHandler.handleError @ error_handler.js:47next @ application_ref.js:272schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74NgZone.triggerError @ ng_zone.js:278onHandleError @ ng_zone.js:257ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157drainMicroTaskQueue @ zone.js:401
error_handler.js:49 ORIGINAL EXCEPTION: Cannot read property 'length' of undefinedErrorHandler.handleError @ error_handler.js:49next @ application_ref.js:272schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74NgZone.triggerError @ ng_zone.js:278onHandleError @ ng_zone.js:257ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157drainMicroTaskQueue @ zone.js:401
error_handler.js:52 ORIGINAL STACKTRACE:ErrorHandler.handleError @ error_handler.js:52next @ application_ref.js:272schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74NgZone.triggerError @ ng_zone.js:278onHandleError @ ng_zone.js:257ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157drainMicroTaskQueue @ zone.js:401
error_handler.js:53 TypeError: Cannot read property 'length' of undefined
    at ShortenPipe.transform (shorten.ts:7)
    at view_utils.js:136
    at View_AppComponent2.detectChangesInternal (component.ngfactory.js:1715)
    at View_AppComponent2.AppView.detectChanges (view.js:288)
    at View_AppComponent2.DebugAppView.detectChanges (view.js:381)
    at ViewContainer.detectChangesInNestedViews (view_container.js:45)
    at CompiledTemplate.proxyViewClass.View_AppComponent0.detectChangesInternal (component.ngfactory.js:1103)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (view.js:288)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (view.js:381)
    at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.detectChangesInternal (host.ngfactory.js:32)ErrorHandler.handleError @ error_handler.js:53next @ application_ref.js:272schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74NgZone.triggerError @ ng_zone.js:278onHandleError @ ng_zone.js:257ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157drainMicroTaskQueue @ zone.js:401
error_handler.js:56 ERROR CONTEXT:ErrorHandler.handleError @ error_handler.js:56next @ application_ref.js:272schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74NgZone.triggerError @ ng_zone.js:278onHandleError @ ng_zone.js:257ZoneDelegate.handleError @ zone.js:236Zone.runTask @ zone.js:157drainMicroTaskQueue @ zone.js:401

my cmponent.ts

  constructor() {
      this.username = userData.username;
}

component template
works well is I just do some random string like
{{'James Go' | shorten: 3: '...'}}
but the below doesn't work even when there is a value.

{{username | shorten: 3: '...'}}

What am I doing wrong?

Pluck not creating an array

Okay, I'm stumped. The question may end up being a broader problem and fall outside of ngx-pipes, but this package has been great so far.

I working with an API (built with Node.js, Express, Mongoose, and Node-Restful) that has a structure similar to this:

finances: [ {
        project_number: Number,
        history: {
            fees: [ {
                amount: Number,
                title: String,
                description: String
            } ]
        }
    } ]

Currently I have two records in fees[ ]. As a simple example:

fees: [ {
   amount: 400,
   title: "Foo",
   description: "Lorem Ipsum"
},
{
   amount: 200,
   title: "Bar",
   description: "Text here"
} ]

I've managed to utilize *ngFor to break down all of the arrays as necessary, and it's all going well:

<span *ngFor="let fee of finances.history.fees">{{ fee.amount }}</span>

That nets me the two Numbers (the type I defined in the API) that I have recorded: 400 and 200. It isn't an array of the two values, just an iteration of the values; it prints out as 400200.

I thought I'd use Pluck to grab the amount values prior to binding:

<span *ngFor="let fee of finances.history.fees | pluck: 'amount'">{{ fee }}</span>

But again, it doesn't come out as an array. (I've double checked this using isArray, which responds as "falsefalse", and isNumber, which responds as "truetrue".)

My end goal is to grab all of the values of each amount and run them through the SumPipe, but I can't figure out a way to collect those values and push them into an array; they come out as Numbers. And thus, the SumPipe doesn't work on them.

I'll admit that I'm brand new to node.js/express APIs, and I only adopted Angular this past autumn. But if anyone has any recommendations for me, I would greatly appreciate the assistance.

Error when adding pipe to for loop

I am getting an error when I add groupBy pipe on a for loop
<div class="row" *ngFor="let tsk of tsks | groupBy: 'MilestoneName'">

And the error that throws is
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

The array that I looping through is an Array

strictNullChecks errors

Getting a few errors from this lib when enabling strictNullChecks in tsconfig.json in my project.

ERROR in [..]/node_modules/ngx-pipes/src/app/pipes/object/invert-by.ts (7,23): Type 'null' is not assignable to type 'Function'.)

ERROR in [..]/node_modules/ngx-pipes/src/app/pipes/helpers/helpers.ts (39,6): An index expression argument must be of type 'string', 'number', 'symbol', or 'any'.)

Failed to compile

ERROR in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/errors.d.ts (9,33): Initializers are not allowed in ambient contexts.
C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/errors.d.ts (10,43): Initializers are not allowed in ambient contexts.
C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/errors.d.ts (11,42): Initializers are not allowed in ambient contexts.
C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/errors.d.ts (12,43): Initializers are not allowed in ambient contexts.
C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/errors.d.ts (13,35): Initializers are not allowed in ambient contexts.

ERROR in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/animation/dsl.d.ts (34,33): Initializers are not allowed in ambient contexts.

ERROR in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/src/animation/animation_metadata_wrapped.d.ts (12,33): Initializers are not allowed in ambient contexts.

ERROR in Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol NgModule in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/node_modules/@angular/core/core.d.ts, resolving symbol NgPipesModule in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/src/app/index.d.ts, resolving symbol NgPipesModule in C:/Users/genti/Desktop/New folder/frontend_software/node_modules/ngx-pipes/src/app/index.d.ts

@angular/cli: 1.0.0
node: 7.6.0
os: win32 x64
@angular/cli: 1.0.0
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/compiler-cli: 2.4.10

`

I am having this issue right now and don't know why using this version "ngx-pipes": "^1.4.6", Can you help me out.

Distance pipe, miles or km for converting km to meters etc.

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request

Hi, it would be nice to have a pipe to convert km to meters and miles to yards || feet when distance value starts with 0.

see attached image

distance_pipe

unique filter is not working on objects

i have an array in app.component.ts as
this.demoarray = [{facility_category_id: 2, facility_category_name: 'test1'}, {facility_category_id: 3, facility_category_name: 'test2'}, {facility_category_id: 3, facility_category_name: 'test2'}]
In my html page the code
i tried in 2 ways
<ion-item *ngFor="let item of items | unique: 'item.facility_category_name'"> <h4>{{item.facility_category_name}}</h4> </ion-item> <ion-item *ngFor="let item of items | unique: 'facility_category_name'"> <h4>{{item.facility_category_name}}</h4> </ion-item>

But unique filter is still not working
Please help me to fix these issue

Need Direction on Nested Table with GroupBy Pipe

Great work on these pipes - they've already helped so much! I was hoping you could either show me how to tweak the results of the GroupBy pipe are maybe even optimize the pipe itself. Basically I'm sending in an array and was hoping I would get an array back so that I could possibly use a nested ngfor and loop through the grouped objects. My ultimate goal is to have a grouped table.

I have table rows with shared dates and tracking numbers, and want to show the user the line item tables grouped into respective divs based on that shared data. Here's some sample data:

[
  {
    "id": 802,
    "shippedCount": 10,
    "receivedCount": 0,
    "productNumber": 1043,
    "shipment": {
      "shippingSeqNumber": 2,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-30T00:00:00",
      "receivedDate": null
    }
  },
  {
    "id": 803,
    "shippedCount": 6,
    "receivedCount": 0,
    "productNumber": 1052,
    "shipment": {
      "shippingSeqNumber": 2,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-30T00:00:00",
      "receivedDate": null
    }
  },
  {
    "id": 804,
    "shippedCount": 39,
    "receivedCount": 0,
    "productNumber": 1085,
    "shipment": {
      "shippingSeqNumber": 2,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-30T00:00:00",
      "receivedDate": null
    }
  },
  {
    "id": 805,
    "shippedCount": 7,
    "receivedCount": 0,
    "productNumber": 1016,
    "shipment": {
      "shippingSeqNumber": 2,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-30T00:00:00",
      "receivedDate": null
    }
  },
  {
    "id": 806,
    "shippedCount": 9,
    "receivedCount": 0,
    "productNumber": 1091,
    "shipment": {
      "shippingSeqNumber": 2,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-30T00:00:00",
      "receivedDate": null
    }
  },
  {
    "id": 807,
    "shippedCount": 32,
    "receivedCount": 32,
    "productNumber": 1043,
    "shipment": {
      "shippingSeqNumber": 1,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-19T00:00:00",
      "receivedDate": "2017-04-19T00:00:00"
    }
  },
  {
    "id": 808,
    "shippedCount": 34,
    "receivedCount": 34,
    "productNumber": 1052,
    "shipment": {
      "shippingSeqNumber": 1,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-19T00:00:00",
      "receivedDate": "2017-04-19T00:00:00"
    }
  },
  {
    "id": 809,
    "shippedCount": 2,
    "receivedCount": 2,
    "productNumber": 1085,
    "shipment": {
      "shippingSeqNumber": 1,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-19T00:00:00",
      "receivedDate": "2017-04-19T00:00:00"
    }
  },
  {
    "id": 810,
    "shippedCount": 5,
    "receivedCount": 5,
    "productNumber": 1016,
    "shipment": {
      "shippingSeqNumber": 1,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-19T00:00:00",
      "receivedDate": "2017-04-19T00:00:00"
    }
  },
  {
    "id": 811,
    "shippedCount": 6,
    "receivedCount": 6,
    "productNumber": 1091,
    "shipment": {
      "shippingSeqNumber": 1,
      "trackingNumber": null,
      "estimatedArrivalDate": "2017-04-19T00:00:00",
      "receivedDate": "2017-04-19T00:00:00"
    }
  }
]

I'm fairly new to Angular so I might have everything I need and just need help connecting the dots haha. A plunker would definitely help if you can.

Thank you!

Convert my JSON Structure

Please share idea using ngx-pipes to transform json structure like this:
[{"name" : "a", "class" : "red", "value" : "5"}, {"name" : "b", "class" : "red", "value" : "6"}, {"name" : "c", "class" : "blue", "value" : "7"}]
to be:

[{"groupbyclass":
[{"class": "red"}, "person":
[{"name" : "a", "class" : "red", "value" : "5"}, {"name" : "b", "class" : "red", "value" : "6"}],
[{"class": "blue"}, "person": [{"name" : "c", "class" : "blue", "value" : "7"}]
}]

thanks in advance

Shouldn't the package name be `ng-pipes`?

Shouldn't the package name be ng-pipes? As Igor said in his tweet:

... but please don't call projects ng2- or angular2-, etc.

There's already a package named by ng-pipes but this could be published with scoping.

filterBy-Pipe Question

Hi,

following situation: I have members that are just club members, then i have players - that have a clubData.passNumber set. How can I filter the players that have this number set and how can i filter the other ones?

Critical dependency: the request of a dependency is an expression

I'm getting this warning which seems to be preventing the package from getting bundled up.

WARNING in .//ngx-pipes//@angular/core/@angular/core.es5.js
5886:15-102 Critical dependency: the request of a dependency is an expression

I'm using webpack, so this could be something to do with me not setting that up correctly, but I'm only getting this when I include ngx-pipes. That seems to be the only one that is throwing this warning.

OrderBy Sort on more Type?

Thanks for adding the OrderBy, however, I'm still unable to swap to using ngx-pipes as your OrderBy only handles strings essentially. It needs to be able to handle more data types. Dates, Booleans, Numbers, etc... I added sorting booleans to the one I linked in the previous ticket.

    if(isBoolean(a) || isBoolean(b)) {
      if (a == b) return 0;
      if (a && !b) return -1;
      if (!a && b) return 1;
    }

Thanks!
Jarvis

unique pipe is not supporting objects

If you have an object with multiply object and one object has the same value over and over but the other object have different values this does not work. As you see ETF will still repeat itself.
Is there a way I can use this with a specific object. {{Name | unique }} << like so.

example.

[{"D":416,"Name":"ETF Trust","PortFiling":false,"SeriesID":1256,"esName":"LP ETF","PortFiling":false},{"ID":416,"Name":"ETF Trust","Filing":false,"SeriesID":1108,"esName":"Equal Sector Weight ETF","PortFiling":false},{"D":416,"Name":"ETF Trust","Filing":false,"ID":998,"esName":"CRealty Majors ETF","PortFiling":false},{"ID":416,"CIKName":"ETF Trust","Filing":false,"ID":1123,"esName":"Global}]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.