@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
27 lines • 938 B
JavaScript
import { AnyArraySchema } from '../../schemas/index.js';
import { Node } from '../../programmatic/node.js';
export default class NodeDefinition extends Node {
static title = 'Array flatten';
static type = 'studio.tokens.array.flatten';
static description = 'Flattens an array of arrays into a single array.';
constructor(props) {
super(props);
this.addInput('array', {
type: AnyArraySchema
});
this.addOutput('array', {
type: AnyArraySchema
});
}
execute() {
const array = this.inputs.array;
//Attempt to determine the type of the array
const type = array.type.items;
if (type.type !== 'array') {
throw new Error('Input array must be an array of arrays');
}
const calculated = array.value.flat();
this.outputs.array.set(calculated, type);
}
}
//# sourceMappingURL=flatten.js.map