0.0.2 • Published 3 years ago
ng-string-parser v0.0.2
Requirements
Angular 11.*.*
Install
npm install ng-string-parser --save-dev
or
yarn add ng-string-parser --dev
Usage example
// some.component.ts
import { ParserService } from "ng-string-parser";
interface IPatterns {
[key: string]: string;
}
interface IValues {
[key: string]: string | number | boolean;
}
interface IResult {
[key: string]: string;
}
@Component({
// ...
providers: [ParserService],
})
export class SomeComponent implements OnInit {
patterns: IPatterns = {
first: "Boolean is {value}",
second: "Number is {value}",
third: "There is no pattern",
fourth: "String is {value}",
fifth: "No value for this one: {value}",
};
values: IValues = {
first: true,
second: 42,
fourth: "Bill Gates",
};
results: IResult;
constructor(private parser: ParserService) {}
ngOnInit() {
this.results = this.parser.parse<IResult>(this.patterns, this.values);
}
}
Result will be:
{
first: "Boolean is true",
second: "Number is 42",
third: "There is no pattern",
fourth: "String is Bill Gates",
fifth: "No value for this one: {value}",
}
Change pattern
Default pattern is {value}
. You can change it for each instance via changePattern(newPattern: string)
public method.