All files / json-crdt-extensions/peritext/slice schema.ts

100% Statements 15/15
77.77% Branches 7/9
100% Functions 2/2
100% Lines 11/11

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 1765x     65x 14505x   65x 1278x 175x 175x 175x 175x 175x   1103x    
import {type NodeBuilder, s} from '../../../json-crdt-patch';
import type {SliceType, SliceTypeStep} from './types';
 
export const type = (sliceType: SliceType) =>
  Array.isArray(sliceType) ? s.arr(sliceType.map(step)) : s.con(sliceType);
 
export const step = (sliceStep: SliceTypeStep) => {
  if (Array.isArray(sliceStep)) {
    const tuple: NodeBuilder[] = [s.con(sliceStep[0])];
    const length = sliceStep.length;
    if (length > 1) tuple.push(s.con(+(sliceStep[1] ?? 0)));
    if (length > 2) tuple.push(s.json(sliceStep[2] ?? {}));
    return s.vec(...tuple);
  }
  return s.con(sliceStep);
};