Angular 2+ String Helper
Just a simple lightweight Angular 2+ string helper
Installation
Install via npm
$ npm i ngx-string-helper --save
API Usage
To use it in your Angular 2 app import the module in your root module(app.module.ts) as shown below.
import { NgxStringHelperModule } from 'ngx-string-helper';
...
...
@NgModule({
imports:[
NgxStringHelperModule
],
})
In your components simply import the service.
import { NgxStringHelper } from 'ngx-string-helper';
...
...
export class YOUR_MODULE {
constructor(private ngxStringHelper: NgxStringHelper) {
console.log(ngxStringHelper.isNullOrEmpty(''));
}
}
NgxStringHelper.isNullOrEmpty();
let sampleString = "This is a sample string";
let isNullOrEmpty = ngxStringHelper.isNullOrEmpty(sampleString);
console.log(isNullOrEmpty);
NgxStringHelper.contains();
if (Str.contains('this is a sample string', 'sample')) {
}
NgxStringHelper.truncate();
var sampleString = "This is a sample string";
var str = Str.truncate(sampleString, 9);
console.log(str);
Thanks and enjoy!