UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

47 lines 1.74 kB
import { Node } from '../../programmatic/node.js'; import { NumberSchema } from '../../schemas/index.js'; import { arrayOf } from '../../schemas/utils.js'; import { setToPrecision } from '../../utils/precision.js'; export default class NodeDefinition extends Node { static title = 'Alternating Series'; static type = 'studio.tokens.series.alternating'; static description = 'Generates a sequence that alternates between positive and negative values based on a pattern'; constructor(props) { super(props); this.addInput('sequence', { type: { ...arrayOf(NumberSchema), default: [1, 2, 3, 4] } }); this.addInput('pattern', { type: { ...arrayOf(NumberSchema), default: [1, -1] // Default alternating pattern } }); this.addInput('precision', { type: { ...NumberSchema, default: 2 } }); this.addOutput('array', { type: arrayOf(NumberSchema) }); } execute() { const { sequence, pattern, precision } = this.getAllInputs(); const values = new Array(sequence.length).fill(0); // Create a new variable for the pattern to use const patternToUse = pattern.length === 0 ? [1] : pattern; sequence.forEach((num, i) => { const patternIndex = i % patternToUse.length; const patternValue = patternToUse[patternIndex]; const value = setToPrecision(num * patternValue, precision); values[i] = value; }); this.outputs.array.set(values); } } //# sourceMappingURL=alternating.js.map