Assert
Usage
import { assert } from '@xethya/utils';
assert(condition, 'message');Example
import { assert } from '@xethya/utils';
import { Die } from '@xethya/dice';
const hexColorPattern = /^#?[0-9a-fA-F]{3}[0-9a-fA-F]{3}?$/;
class ColoredDie extends Die {
public readonly color: string;
constructor(faces: number, color: string) {
super(faces);
assert(color.match(hexColorPattern), 'You must provide a valid hexadecimal color');
}
}Last updated
Was this helpful?