main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { ArrayElement } from 'minim';
|
---|
2 | import { isUndefined } from 'ramda-adjunct';
|
---|
3 | class ParseResult extends ArrayElement {
|
---|
4 | constructor(content, meta, attributes) {
|
---|
5 | super(content, meta, attributes);
|
---|
6 | this.element = 'parseResult';
|
---|
7 | }
|
---|
8 | get api() {
|
---|
9 | return this.children.filter(item => item.classes.contains('api')).first;
|
---|
10 | }
|
---|
11 | get results() {
|
---|
12 | return this.children.filter(item => item.classes.contains('result'));
|
---|
13 | }
|
---|
14 | get result() {
|
---|
15 | return this.results.first;
|
---|
16 | }
|
---|
17 | get annotations() {
|
---|
18 | return this.children.filter(item => item.element === 'annotation');
|
---|
19 | }
|
---|
20 | get warnings() {
|
---|
21 | return this.children.filter(item => item.element === 'annotation' && item.classes.contains('warning'));
|
---|
22 | }
|
---|
23 | get errors() {
|
---|
24 | return this.children.filter(item => item.element === 'annotation' && item.classes.contains('error'));
|
---|
25 | }
|
---|
26 | get isEmpty() {
|
---|
27 | return this.children.reject(item => item.element === 'annotation').isEmpty;
|
---|
28 | }
|
---|
29 | replaceResult(replacement) {
|
---|
30 | const {
|
---|
31 | result
|
---|
32 | } = this;
|
---|
33 | if (isUndefined(result)) {
|
---|
34 | return false;
|
---|
35 | }
|
---|
36 |
|
---|
37 | // @ts-ignore
|
---|
38 | const searchIndex = this.content.findIndex(e => e === result);
|
---|
39 | if (searchIndex === -1) {
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 | this.content[searchIndex] = replacement;
|
---|
43 | return true;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | export default ParseResult; |
---|
Note:
See
TracBrowser
for help on using the repository browser.