lotus-sdk
Version:
Central repository for several classes of tools for integrating with, and building for, the Lotusia ecosystem
32 lines (31 loc) • 1.2 kB
JavaScript
import { BitcoreError } from '../errors.js';
export class Preconditions {
static checkState(condition, message) {
if (!condition) {
throw new BitcoreError.Precondition.InvalidState(message);
}
}
static checkArgument(condition, argumentName, message, docsPath) {
if (!condition) {
throw new BitcoreError.Precondition.InvalidArgument(argumentName, message, docsPath);
}
}
static checkArgumentType(argument, type, argumentName) {
argumentName = argumentName || '(unknown name)';
if (typeof type === 'string') {
if (type === 'Buffer') {
if (!Buffer.isBuffer(argument)) {
throw new BitcoreError.Precondition.InvalidArgumentType(argument, type, argumentName);
}
}
else if (typeof argument !== type) {
throw new BitcoreError.Precondition.InvalidArgumentType(argument, type, argumentName);
}
}
else {
if (!(argument instanceof type)) {
throw new BitcoreError.Precondition.InvalidArgumentType(argument, type.name, argumentName);
}
}
}
}