@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
53 lines • 1.69 kB
JavaScript
import { AnySchema, BooleanSchema, StringSchema } from '../../schemas/index.js';
import { Node } from '../../programmatic/node.js';
import { Operator } from '../../schemas/operators.js';
export default class NodeDefinition extends Node {
static title = 'Compare';
static type = 'studio.tokens.logic.compare';
static description = 'Compare node allows you to compare two values using multiple operators.';
constructor(props) {
super(props);
this.addInput('a', {
type: AnySchema
});
this.addInput('b', {
type: AnySchema
});
this.addInput('operator', {
type: {
...StringSchema,
enum: Object.values(Operator),
default: Operator.EQUAL
}
});
this.addOutput('value', {
type: BooleanSchema
});
}
execute() {
const { operator, a, b } = this.getAllInputs();
let answer = false;
switch (operator) {
case Operator.EQUAL:
answer = a === b;
break;
case Operator.NOT_EQUAL:
answer = a !== b;
break;
case Operator.GREATER_THAN:
answer = a > b;
break;
case Operator.LESS_THAN:
answer = a < b;
break;
case Operator.GREATER_THAN_OR_EQUAL:
answer = a >= b;
break;
case Operator.LESS_THAN_OR_EQUAL:
answer = a <= b;
break;
}
this.outputs.value.set(answer);
}
}
//# sourceMappingURL=compare.js.map