Skip to content

Commit e340e8c

Browse files
committed
feat(config-files): add simple parsers and validators
1 parent e7edebe commit e340e8c

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
3+
import { ConfigFileParser, ConfigFileParsingException } from './parser';
4+
5+
@Injectable({ providedIn: 'root' })
6+
export class TextParser implements ConfigFileParser {
7+
parse(value: string): object {
8+
return { value };
9+
}
10+
}
11+
12+
@Injectable({ providedIn: 'root' })
13+
export class JsonParser implements ConfigFileParser {
14+
parse(raw: string): object {
15+
try {
16+
return JSON.parse(raw);
17+
} catch (error) {
18+
throw new ConfigFileParsingException(String(error));
19+
}
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@angular/core';
2+
3+
import { ConfigFileValidator } from './validator';
4+
5+
@Injectable({ providedIn: 'root' })
6+
export class NoopValidator implements ConfigFileValidator<object> {
7+
validate(): void {}
8+
}

0 commit comments

Comments
 (0)