ngx-trust v0.0.1
ngx-trust
Because I'm tired of copying this stuff between projects. https://www.npmjs.com/package/ngx-trust
About
It's a good idea to read about the DomSanitizer and Angular Security first in order to understand the implications of bypassing the sanitizer.
This trivial library adds a few Pipes to make bypassing the DomSanitizer more convenient.
Getting Started
- Install via npm or yarn
npm i -S ngx-trust
//------------- OR --------------
yarn add ngx-trust
- Import
NgxTrustModule
in your application
import { NgxTrustModule } from 'ngx-trust';
@NgModule({
...
imports: [NgxTrustModule],
...
})
export class AppModule { }
Usage
Use the Pipes as needed. For example:
<!-- Injects HTML without sanitizing -->
<div [innerHtml]="someHtml | trustHtml"></div>
<!-- Alternative Pipe syntax -->
<div [innerHtml]="someHtml | trustAs:'html'"></div>
Pipes introduces for trusting (bypassing):
trustHtml
trustResourceUrl
trustScript
trustStyle
trustUrl
trustAs
(used liketrustAs:'html|resourceUrl|script|style|url'
)
Local Development
If you wish to contribute to this repository, below are the steps for local development.
- Clone the repository
git clone https://github.com/cf91/ngx-trust.git
- Run
npm install
to install the dependencies - Run
npm build
to build both the library and demo app and create a link - Run
npm start
to build and watch the demo app (opens the app athttp://localhost:4200/
automatically) - Run
npm watch:lib
to build and watch the library
Build
Run npm run build
to build the library and demo app together. The build artifacts will be stored in the dist/
directory.
This step is used by CircleCI to build both library and demo app. After a succesful build, a new semantic version of library is published to npm.
Tests
Run npm run test:lib
or npm run test:app
to execute the unit tests via Karma.