code review - change from object array to number tuples. Move to proposed api

This commit is contained in:
Sandeep Somavarapu
2018-10-22 16:50:37 +02:00
parent b1e6a681ed
commit 90052ff8c4
6 changed files with 42 additions and 26 deletions

View File

@@ -28,11 +28,12 @@ function toTreeItemLabel(label: any): ITreeItemLabel {
if (label
&& typeof label === 'object'
&& typeof label.label === 'string') {
if (Array.isArray(label.highlights) && label.highlights.every(highlight => typeof highlight === 'object' && typeof highlight.start === 'number' && typeof highlight.end === 'number')) {
return label;
} else {
return { label: label.label };
let highlights: [number, number][] = void 0;
if (Array.isArray(label.highlights)) {
highlights = (<[number, number][]>label.highlights).filter((highlight => highlight.length === 2 && typeof highlight[0] === 'number' && typeof highlight[1] === 'number'));
highlights = highlights.length ? highlights : void 0;
}
return { label: label.label, highlights };
}
return void 0;