An open API service indexing awesome lists of open source software.

https://github.com/manishjanky/ngx-custom-pipes

ngx-custom-pipes are custom pipes for angular 4 and above application.
https://github.com/manishjanky/ngx-custom-pipes

angular angular4 custom custom-pipes pipes

Last synced: 8 months ago
JSON representation

ngx-custom-pipes are custom pipes for angular 4 and above application.

Awesome Lists containing this project

README

          

# ngx-custom-pipes

[![GitHub license](https://img.shields.io/github/license/manishjanky/ngx-custom-pipes.svg)](https://github.com/me-and/mdf/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/ngx-custom-pipes.svg)]()
[![Build Status](https://travis-ci.org/manishjanky/ngx-custom-pipes.svg?branch=master)](https://travis-ci.org/manishjanky/ngx-custom-pipes)
[![Codecov branch](https://codecov.io/gh/manishjanky/ngx-custom-pipes/branch/master/graphs/badge.svg)]()
[![npm](https://img.shields.io/npm/dt/ngx-custom-pipes.svg)]()
[![GitHub top language](https://img.shields.io/github/languages/top/manishjanky/ngx-custom-pipes.svg)]()
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/manishjanky/ngx-custom-pipes.svg)]()
[![GitHub issues](https://img.shields.io/github/issues/manishjanky/ngx-custom-pipes.svg)]()
[![GitHub closed issues](https://img.shields.io/github/issues-closed/manishjanky/ngx-custom-pipes.svg)]()
[![GitHub contributors](https://img.shields.io/github/contributors/manishjanky/ngx-custom-pipes.svg)]()

`ngx-custom-pipes` custom pipes module for angular 4 and above applications.

## Installation

* `npm install ngx-custom-pipes`

### For webpack and tsc builds/ angular-cli builds

* import `CustomPipesModule` from `ngx-custom-pipes`:

```
import { CustomPipesModule } from 'ngx-custom-pipes'
```

* If you dont want all the pipes and want pipes for `String` or `Math` or `Array` only then import only the required module.

```
import { MathPipesModule } from 'ngx-custom-pipes';
// or
import { ArrayPipesModule } from 'ngx-custom-pipes'
// or
import { StringPipesModule } from 'ngx-custom-pipes'
```

* add `CustomPipesModule` or `MathPipesModule` or `ArrayPipesModule` or `StringPipesModule` to the imports of your NgModule: as per your requirements

```
@NgModule({
imports: [
...,

CustomPipesModule, MathPipesModule, ArrayPipesModule, StringPipesModule
],
...
})
class YourModule { ... }
```

## Usage
### String Pipes
* **`cuurencyAbbrev`** : Currency short name/ abbreviation
````
{{10000 | cuurencyAbbrev}}
{{'1,000,000,000' | cuurencyAbbrev}}
````
````
10.00K
1.00B
````
* **`camelCase`** : Converts the string to camel case with seperators ``(-,_, )``
`````
{{'hello world' | camelCase}}
{{'hello_world' | camelCase}}
{{'hello-world' | camelCase}}
`````
````
HelloWorld
HelloWorld
HelloWorld
````
* **`ltrim`** : trims the characters from left if match found.
````
Usage: str | ltrim: [chars?: string]
````
````
{{'hello-world' | ltrim : 'hello'}}
````
````
-world
````
* **`padEnd`** : pads the string at end where target length of string will be string length + `count`. Default character for padding is space.
````
Usage: str | padEnd: [padCount: number] : [chars?: string]
````
````
{{'hello-world' | padEnd : 3 : 'hello'}}
````
````
hello-worldhel
````
* **`padStart`** : pads the string at start where target length of string will be string length + `count`. Default character for padding is space.
````
Usage: str | padStart: [padCount: number] : [chars?: string]
````
````
{{'hello-world' | padStart : 3 : 'hello'}}
````
````
helhello-world
````
* **`repeat`** : repeats the string n number of times.
````
Usage: str | repeat: [repeatCount: number]
````
````
{{'hello world' | repeat : 3}}
````
````
hello worldhello worldhello world
````
* **`replaceFirst`** : replaces the first occurance of particular character with specified characters or just replace them with empty string if replacWith not specified.
````
Usage: str | replaceFirst: [replaceChar: string] : [replaceWith?: string]
````
````
{{'hello world' | replaceFirst : 'h' : 'def'}}
````
````
defello world
````
* **`replaceLast`** : replaces last occurance of of particular character with specified characters.
````
Usage: str | replaceLast: [replaceChar: string] : [replaceWith?: string]
````
````
{{'hello world' | replaceLast : 'h' : 'def'}}
{{'hello world hello' | replaceLast : 'hello' : 'howdy'}}
````
````
defello world
hello world howdy
````
* **`replace`** : replaces all occurrances of particular character with specified characters.
````
Usage: str | replace: [replaceChar: string] : [replaceWith?: string]
````
````
{{'hello world hello' | replace : 'h' : 'def'}}
````
````
defello world defello
````
* **`reverse`** : reverses the string
````
Usage: str | reverse
````
````
{{'hello world' | reverse}}
````
````
dlrow olleh
````
* **`rtrim`** : trims off the chars from right side if match found.
````
{{'hello-world' | rtrim : 'ld'}}
````
````
hello-wor
````
* **`profileName`** : returns the short profile user name for a string.
````
Usage: str | profileName
````
````
{{'hello world' | profileName}}
{{'user name' | profileName}}
````
````
HW
UN
````
* **`trim`** : trims off specified characters from start and end if match found.
````
Usage: str | trim : [chars?: string]
````
````
{{'hello world hello' | trim : 'hello'}}
````
````
world
````
* **`ucfirst`** : changes first letter of string to uppercase.
````
Usage: str | ucfirst
````
````
{{'hello world' | ucfirst}}
````
````
Hello world
````
* **`ucwords`** : change first letter of each word to uppercase.
````
Usage: str | ucwords
````
````
{{'hello world' | ucwords}}
````
````
Hello World
````

### Math Pipes
* **`ceil`** : returns the ceiling value of a floating point number.
````
Usage: number | ceil
````
````
{{1.234 | ceil}}
````
````
2
````
* **`degrees`** : converts radians to degrees.
````
Usage: number | degrees
````
````
{{5 | degrees}}
````
````
286.479
````
* **`floor`** : returns the floor value of a floating point number.
````
Usage: number | floor
````
````
{{286.479 | floor}}
````
````
286
````
* **`fromBinary`** : returns the decimal representation of a binary , octal, hexadecimal etc. number.
````
Usage: number | fromBinary :[base?: number]
````
````
{{'00001100' | fromBinary}}
{{2322 | fromBinary : 8}}
````
````
12
1234
````
* **`mean`** : returns the mean of an array of numbers.
````
Usage: number[] | mean
````
````
{{[1, 2, 34, 5, 6, 7] | mean}}
````
````
9.166666666
````
* **`median`** : returns the median of an array of numbers.
````
Usage: number[] | median
````
````
{{[1, 2, 4, 5, 7] | median}}
{{[1, 2, 4, 5, 7, 8] | median}}
````
````
4
4.5
````
* **`mode`** : returns the mode of an array of numbers.
````
Usage: number[] | mode
````
````
{{[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6] | mode}}
````
````
[3]
````
* **`prcnt`** : returns the percentage of value of a number.
````
Usage: number | prcnt :[total?: number]
````
````
{{23 | prcnt}}
{{23 | prcnt : 200}}
````
````
23%
11.5%
````
* **`pow`** : returns a number raised to power.
````
Usage: number | pow : [power: number]
````
````
{{5 | pow : 3}}
{{23 | pow : 4}}
````
````
125
279841
````
* **`radians`** : converts degrees to radians.
````
Usage: number | radians
````
````
{{90 | radians}}
````
````
1.5708
````
* **`roundoff`** : rounds off the number to specified decimal places and nearest integer if digits not specified.
````
Usage: number | roundoff : [digits?: number]
````
````
{{123.566767 | roundoff : 3}}
{{876.566767 | roundoff}}
````
````
123.566
877
````
* **`sqrt`** : returns the square root of a number.
````
Usage: number | sqrt
````
````
{{225 | sqrt}}
````
````
15
````
* **`toBinary`** : returns binary or octal or hexadecimal representation of a decimal number.
````
Usage: number | toBinary : [base?: number]
````
````
{{12 | toBinary}}
{{1234 | toBinary: 8}}
````
````
1100
2322
````

### Array Pipes
* **`contains`** : returns `true/false` if the item is present in the array or not.
````
Usage: array | contains : [item: any]
````
````
{{[1, 2, 3, 4, 5] | contains : 4 }}
````
````
true
````
* **`diff`** : returns difference between two arrays i.e the items unique to both arrays.
````
Usage: array | diff : [array_2: any[]]
````
````
{{[1, 2, 3, 4, 5] | diff : [2, 3, 7, 8, 1] }}
````
````
[4, 7, 5, 8]
````
* **`dupes`** : returns the items which occur more than once in array i.e duplicates.
````
Usage: array | dupes
````
````
{{[1, 2, 3, 3, 8, 5, 2, 4, 5] | dupes}}
````
````
[2, 3, 5]
````
* **`filterBy`** : filters an array based on searctext.
````
Usage: array | filterBy : [searchText: string] : [keyName?: string]
keyName: in case array of objects and filter required for a particular key
````
````
{{['star', 'galaxy', 'sun', 'moon', 'earth'] | filterBy: 'ar'}}
````
````
['star', 'earth']
````
* **`limitTo`** : limit the records to specified number of items from particular index.
````
Usage: array | limitTo : [itemsCount: number] : [startIndex?: number]
````
````
{{['star', 'galaxy', 'sun', 'moon', 'earth'] | limitTo: 3 : 0}}
````
````
['star', 'galaxy', 'sun']
````
* **`ltrim`** : trims an array from left for specified count of numbers.
````
Usage: array | ltrim : [itemsCount: number]
````
````
{{[12, 34, 5, 56, 546, 34, 3, 54] | ltrim: 3}}
````
````
[56, 546, 34, 3, 54]
````
* **`max`** : returns the max value in a array of numbers.
````
Usage: array | max
````
````
{{[12, 34, 5, 56, 546, 34, 3, 54] | max}}
````
````
546
````
* **`merge`** : merges/concats two or more arrays.
````
Usage: array | merge : [...arrays: any[]]
````
````
{{[1, 2, 3, 4] | merge : [21, 32, 4] : ['a', 'f']}}
````
````
[1, 2, 3, 4, 21, 32, 4, 'a', 'f']
````
* **`min`** : returns the minimum value in a array of numbers.
````
Usage: array | min
````
````
{{[12, 34, 5, 56, 546, 34, 3, 54] | min}}
````
````
3
````
* **`omit`** : returns an array after omiting the specified items.
````
Usage: array | omit : [omitItems: any[]]
````
````
{{[1, 2, 3, 4, 5, 6, 7] | omit : [4, 7, 9]}}
````
````
[1, 2, 3, 5, 6]
````
* **`range`** : returns an array containing the items in specified range.
````
Usage: array | range : [startIndex: number] : [endIndex?: numbers]
````
````
{{[1, 2, 3, 4, 5, 6, 7] | range : 2 : 5}}
{{[1, 2, 3, 4, 5, 6, 7] | range : 2}}
````
````
[3, 4, 5]
[3, 4, 5, 6, 7]
````
* **`reverse`** : reverses an array.
````
Usage: array | reverse
````
````
{{[1, 2, 3, 4, 5, 6, 7] | reverse}}
````
````
[7, 6, 5, 4, 3, 2, 1]
````
* **`rtrim`** : trims an array from right with specified count of numbers.
````
Usage: array | rtrim : [itemcCount: number]
````
````
{{[1, 2, 3, 4, 5, 6, 7] | rtrim: 3}}
````
````
[1, 2, 3, 4]
````
* **`shuffle`** : returns an array with items shuffled.
````
Usage: array | shuffle
````
````
{{[1, 2, 3, 4, 5, 6, 7] | shuffle}}
````
````
[3, 7, 1, 2, 6, 5, 4]
````
* **`sortBy`** : returns a sorted array
````
Usage: array | sortBy : [reverse: boolean] : [keyName?: string]
keyName: the key according to which the array needs to be sorted in case array of objects
````
````
{{['asd', 'def', 'bghi', 'nhm'] | sortBy}}
{{[2, 8, 3, 6, 34, 12] | sortBy: true}}
{{[{name:'name2'} , {name:'name1'} , {name:'name3'}] | sortBy: true : 'name'}}
````
````
['asd', 'bghi', 'def', 'nhm']
[34, 12, 8, 6, 3, 2]
[{name:'name1'} , {name:'name2'} , {name:'name3'}]
````
* **`sum`** : returns sum of an array of numbers.
````
Usage: array | sum
````
````
{{[1, 2, 8, 9, 19] | sum}}
````
````
39
````
* **`trim`** : trims an array from both ends with specified count of numbers.
````
Usage: array | trim : [itemsCount : number]
````
````
{{[1, 2, 3, 4, 5, 6, 7, 8, 9] | trim : 2}}
````
````
[3, 4, 5, 6, 7]
````
* **`unique`** : returns array with unique entries eleiminating duplicates.
````
Usage: array | unique
````
````
{{[1, 2, 33, 4, 4, 5, 66, 33, 4] | unique}}
````
````
[1, 2, 33, 4, 5, 66]
````

## Help Improve

Found a bug or an issue with this? [Open a new issue](https://github.com/manishjanky/ngx-custom-pipes/issues) here on GitHub.

## Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to
review the [guidelines for contributing](CONTRIBUTING.md).

* [Bug reports](CONTRIBUTING.md#bugs)
* [Feature requests](CONTRIBUTING.md#features)
* [Pull requests](CONTRIBUTING.md#pull-requests)