All files / src/clarity/types optionalCV.ts

85.71% Statements 6/7
0% Branches 0/2
66.66% Functions 2/3
85.71% Lines 6/7

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 2621x                           21x 9x     21x 13x     21x      
import { ClarityType } from '../common/constants';
import { ClarityValue } from '../clarity-value/types';
 
export type OptionalCV<T extends ClarityValue> = NoneCV | SomeCV<T>;
 
export interface NoneCV {
  readonly type: ClarityType.OptionalNone;
}
 
export interface SomeCV<T extends ClarityValue = ClarityValue> {
  readonly type: ClarityType.OptionalSome;
  readonly value: T;
}
 
export function noneCV(): NoneCV {
  return { type: ClarityType.OptionalNone };
}
 
export function someCV<T extends ClarityValue = ClarityValue>(value: T): OptionalCV<T> {
  return { type: ClarityType.OptionalSome, value };
}
 
export function optionalCVOf<T extends ClarityValue = ClarityValue>(value?: T): OptionalCV<T> {
  return value ? someCV(value) : noneCV();
}