htte-plugin-builtin
Version:
htte plugin builtin
20 lines (19 loc) • 710 B
JavaScript
module.exports = function(options) {
return {
name: 'exist',
kind: 'scalar',
diff: function(context, literal, actual) {
if (literal !== null && typeof literal !== 'string') {
context.throw('literal value must be string if exists');
}
if (actual === undefined) context.throw('actual value does not exist');
const shouldCheckType = literal !== '' && literal !== null;
if (!shouldCheckType) return;
if (typeof actual !== literal) {
if (Array.isArray(actual) && literal === 'array') return;
if (actual === null && literal === 'null') return;
context.throw(`actual value is not ${literal}`);
}
}
};
};