0.0.2 • Published 3 years ago

ng-string-parser v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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.

0.0.2

3 years ago

0.0.1-rc.1

3 years ago

1.0.0

3 years ago

0.0.1

3 years ago