util.ts 660 B

123456789101112131415161718
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Field, Category } from '../encoder';
  7. export function getFieldDigitCount(field: Field) {
  8. if (field.defaultFormat && typeof field.defaultFormat.digitCount !== 'undefined') return Math.max(0, Math.min(field.defaultFormat.digitCount, 16));
  9. return 6;
  10. }
  11. export function getIncludedFields(category: Category.Instance) {
  12. return category.fields.some(f => !!f.shouldInclude)
  13. ? category.fields.filter(f => !f.shouldInclude || f.shouldInclude(category.data))
  14. : category.fields;
  15. }