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 51 52 53 54 55 | 63x 63x 15308x 14566x 742x 742x 742x 742x 1823x 1823x 1666x 157x 157x 742x 63x 1972x 1972x 1972x 1493x 1493x 1493x 1493x 63x | import {SliceTypeName} from './constants'; import type {SliceType, SliceTypeStep} from '../slice/types'; export const validateType = (type: SliceType) => { switch (typeof type) { case 'string': case 'number': return; case 'object': { Iif (!(type instanceof Array)) throw new Error('INVALID_TYPE'); Iif (type.length > 32) throw new Error('INVALID_TYPE'); const length = type.length; LOOP: for (let i = 0; i < length; i++) { const step = type[i]; switch (typeof step) { case 'string': case 'number': continue LOOP; case 'object': Iif (!Array.isArray(step) || step.length !== 2) throw new Error('INVALID_TYPE'); continue LOOP; default: throw new Error('INVALID_TYPE'); } } return; } default: throw new Error('INVALID_TYPE'); } }; export const getTag = (type: SliceType): string | number => { Iif (!Array.isArray(type)) return type; const length = type.length; if (!length) return ''; const tagWithMaybeDiscriminant = type[length - 1]; const hasDiscriminant = Array.isArray(tagWithMaybeDiscriminant); const tag = hasDiscriminant ? tagWithMaybeDiscriminant[0] : tagWithMaybeDiscriminant; return tag; }; export const formatType = (step: SliceTypeStep): string => { let tag: string | number = ''; let discriminant: number = -1; if (Array.isArray(step)) { tag = step[0]; discriminant = step[1]; } else { tag = step; } Iif (typeof tag === 'number' && Math.abs(tag) <= 64 && SliceTypeName[tag]) tag = SliceTypeName[tag] ?? tag; return '<' + tag + (discriminant >= 0 ? ':' + discriminant : '') + '>'; }; |