TypeScript library containing a set of useful pipes. See README for mode details
npm install @nudgeit/nit-pipesThis is a collection of useful pipes for AngularIO (v>=4) with no external dependencies.
- Installation
- Pipes
- first
- last
- impureJoin
- initials
- isArray
- isBoolean
- isDate
- isFunction
- isNull
- isString
- join
- ~safeUrl~
- safe
- sanitize
- xfilter
1. Use npm to install the package
``terminal`
$ npm install @nudgeit/nit-pipes --save
2. Add into your module imports the NitPipesModule in order to add all of the pipes.
`typescript
import {NitPipesModule} from ' @nudgeit/nit-pipes';
@NgModule({
// ...
imports: [
// ...
NitPipesModule
]
})
`
Returns the first n elements of the array. Any negative value of n is treated as 0 and an empty array will be returned.
Usage: array | first: n
` {{ [1, 2, 3, 4] | first: 2 }}html`
Returns the last n elements of the array. Any negative value of n is treated as 0 and an empty array will be returned.
Usage: array | last: n
` {{ [1, 2, 3, 4] | last: 2 }}html`
Joins the elements of an array.
Usage: array | join: [separator|optional]
` {{ [1, 2] | join: ', ' }}html`
The impure version of join.
Tests if a value is an array and returns true if it is or false otherwise.
Usage: value | isArray
` {{ [1, 2] | isArray }} {{ "12" | isArray }}html`
Tests if a value is a boolean and returns true if it is or false otherwise.
Usage: value | isBoolean
` {{ false | isBoolean }} {{ "12" | isBoolean }}html`
Tests if a value is a date and returns true if it is or false otherwise.
Usage: value | isDate
Tests if a value is a function and returns true if it is or false otherwise.
Usage: value | isFunction
Tests if a value is null or undefined and returns true if it is or false otherwise.
Usage: value | isNull
` {{ null | isNull }} {{ undefined | isNull }} {{ "12" | isNull }} {{ "" | isNull }}html`
Tests if a value is a string and returns true if it is or false otherwise.
Usage: value | isString
Deprecated - better use safe!
Returns the safe version of an URL. Use this with care!
Usage: url | safeUrl
Returns the initials of the words in a string.
Usage: string | join: [maxLength|optional, default:3]
` {{ "Nibo AI" | initials }}html`$3
Returns the safe version of an URL or HTML. Use this with care!
Usage: string | safe: context
Context can be one of 'HTML', 'STYLE', 'SCRIPT', 'URL', 'RESOURCE_URL' (case insensitive)
depending on what content you would like to sanitize.
`html`
Returns the sanitized version of an URL or HTML. Use this with care!
Usage: string | sanitize: context
Context can be one of 'HTML', 'STYLE', 'SCRIPT', 'URL', 'RESOURCE_URL' (case insensitive)
depending on what content you would like to sanitize.
`html`
Joins the elements of an array.
Usage: array | xfilter: customFilter
`typescript`
isOdd = (x) => x % 2 === 1;
` {{ [1, 2, 3, 4] | xfilter: isOdd }}html`
This section is solely for the developers of this library, not for its users/consumers.
, package-lock.json and projects\nit-pipes\package.json.
2. Run npm run publish-lib`. You'll need an OTP to authenticate and publish.