UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

42 lines 1.25 kB
import { AnyArraySchema, StringSchema } from '../../schemas/index.js'; import { Node } from '../../programmatic/node.js'; import { orderBy } from 'lodash-es'; export var Order; (function (Order) { Order["ASC"] = "asc"; Order["DESC"] = "desc"; })(Order || (Order = {})); export const defaults = { order: Order.ASC }; export default class NodeDefinition extends Node { static title = 'Sort Array'; static type = 'studio.tokens.array.sort'; static description = 'Sorts an array'; constructor(props) { super(props); this.addInput('array', { type: AnyArraySchema }); this.addInput('order', { type: { ...StringSchema, enum: [Order.ASC, Order.DESC], default: Order.ASC } }); this.addInput('sortBy', { type: StringSchema }); this.addOutput('value', { type: AnyArraySchema }); } execute() { const { sortBy, order } = this.getAllInputs(); const array = this.inputs.array; const sorted = orderBy(array.value, [sortBy], order); this.outputs.value.set(sorted, array.type); } } //# sourceMappingURL=sort.js.map