Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular2-pipes

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular2-pipes

[![Build Status](https://travis-ci.org/danrevah/ng2-pipes.svg?branch=master)](https://travis-ci.org/danrevah/ng2-pipes) [![npm version](https://badge.fury.io/js/ng2-pipes.svg)](https://badge.fury.io/js/ng2-pipes)

  • 0.2.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
81
decreased by-21.36%
Maintainers
1
Weekly downloads
 
Created
Source

Angular2 Pipes

Build Status npm version

Useful pipes for Angular2.

Table of contents

Installation

  1. Use npm to install the package
$ npm install ng2-pipes --save 
  1. Add into your module imports the PipesModule
import {NgPipesModule} from 'ng2-pipes';

@NgModule({
 // ...
 imports: [
   // ...
   NgPipesModule
 ]
})

String

repeat

Repeats a string n times Api: string | repeat: times: [separator|optional] Example:

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

scan

Scans string and replace {i} placeholders by equivalent member of the array Api: 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

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

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

strip-tags

Strips a HTML tags from string and providing which tags should not be removed Api: string | strip-tags: [ARRAY]

<p>{{'<a href="">foo</a> <p class="foo">bar</p>' | strip-tags }}</p> <!-- Output: "foo bar" -->
<p>{{'<a href="">foo</a> <p class="foo">bar</p>' | strip-tags: ['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" -->

trim

Strips characters from the beginning and end of a string (default character is space). Api: string | trim: [characters|optional]

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

ltrim

Strips characters from the beginning of a string (default character is space). Api: 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). Api: string | rtrim: [characters|optional]

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

reverse

Reverses a string Api: string | reverse

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

Array

diff

Returns array of diff between arrays Api: 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 Api: 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 Api: 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 Api: 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 Api: array | intersection: [ARRAY]: [ARRAY]: ... : [ARRAY]

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

reverse

Reverses an array Api: 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 Api: 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

Removes un-truthy values from array Api: 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 Api: array | unique

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 Api: array | without: [ARRAY]

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

FAQs

Package last updated on 25 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc