All files / src/types/kmx/kmx-plus-builder build-disp.ts

54% Statements 27/50
100% Branches 0/0
0% Functions 0/1
54% Lines 27/50

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                
import { constants } from '@keymanapp/ldml-keyboard-constants';
import { KMXPlus } from "@keymanapp/common-types";
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
import { BUILDER_SECTION } from './builder-section.js';
 
import KMXPlusData = KMXPlus.KMXPlusData;
 
/* ------------------------------------------------------------------
 * disp section
   ------------------------------------------------------------------ */
 
/**
 * Builder for the 'disp' section
 */
interface BUILDER_DISP_ITEM {
  to: BUILDER_STR_REF;
  id: BUILDER_STR_REF;
  display: BUILDER_STR_REF;
};
 
export interface BUILDER_DISP extends BUILDER_SECTION {
  count: number;
  baseCharacter: BUILDER_STR_REF;
  items: BUILDER_DISP_ITEM[];
};
 
export function build_disp(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS): BUILDER_DISP {
  if(!kmxplus.disp.disps.length && !kmxplus.disp.baseCharacter.value) {
    return null;
  }

  const disp: BUILDER_DISP = {
    ident: constants.hex_section_id(constants.section.disp),
    size: constants.length_disp + constants.length_disp_item * kmxplus.disp.disps.length,
    _offset: 0,
    count: kmxplus.disp.disps.length,
    baseCharacter: build_strs_index(sect_strs, kmxplus.disp.baseCharacter),
    items: []
  };

  for(const item of kmxplus.disp.disps) {
    disp.items.push({
      to: build_strs_index(sect_strs, item.to),
      id: build_strs_index(sect_strs, item.id),
      display: build_strs_index(sect_strs, item.display),
    });
  }

  return disp;
}