import type { NodeDef } from '../../NodeRegistry'; import { asNumber, asString } from '../../values'; import { int, str } from '../shared'; export const Substring: NodeDef = { type: 'Substring', label: 'Substring', category: 'data', description: 'A part of a text: "count" characters starting at "start" (the first is 0). ' + 'A negative count reaches to the end.', inputs: [str('text'), int('start'), int('count', -1)], outputs: [str('text')], params: [], run: (_ctx, inputs) => { const text = asString(inputs.text); const start = Math.max(0, Math.floor(asNumber(inputs.start))); const count = Math.floor(asNumber(inputs.count)); return { outputs: { text: count < 0 ? text.slice(start) : text.slice(start, start + count) } }; }, };