You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1018 B
34 lines
1018 B
'use strict';
|
|
|
|
var errors = require('../errors');
|
|
var _ = require('lodash');
|
|
|
|
module.exports = {
|
|
checkState: function(condition, message) {
|
|
if (!condition) {
|
|
throw new errors.InvalidState(message);
|
|
}
|
|
},
|
|
checkArgument: function(condition, argumentName, message) {
|
|
if (!condition) {
|
|
throw new errors.InvalidArgument(argumentName, message);
|
|
}
|
|
},
|
|
checkArgumentType: function(argument, type, argumentName) {
|
|
argumentName = argumentName || '(unknown name)';
|
|
if (_.isString(type)) {
|
|
if (type === 'Buffer') {
|
|
var BufferUtil = require('./buffer');
|
|
if (!BufferUtil.isBuffer(argument)) {
|
|
throw new errors.InvalidArgumentType(argument, type, argumentName);
|
|
}
|
|
} else if (typeof argument !== type) {
|
|
throw new errors.InvalidArgumentType(argument, type, argumentName);
|
|
}
|
|
} else {
|
|
if (!(argument instanceof type)) {
|
|
throw new errors.InvalidArgumentType(argument, type.name, argumentName);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|