@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
49 lines • 1.48 kB
JavaScript
import { Node } from '../../programmatic/node.js';
import { NumberSchema, StringSchema } from '../../schemas/index.js';
export var Position;
(function (Position) {
Position["START"] = "start";
Position["END"] = "end";
})(Position || (Position = {}));
/**
* This node pads a string to a given length
*/
export default class NodeDefinition extends Node {
static title = 'Pad';
static type = 'studio.tokens.string.pad';
static description = 'Pads a string to a given length';
constructor(props) {
super(props);
this.addInput('string', {
type: StringSchema
});
this.addInput('length', {
type: NumberSchema
});
this.addInput('character', {
type: StringSchema
});
this.addInput('position', {
type: {
...StringSchema,
enum: [Position.START, Position.END],
default: Position.START
}
});
this.addOutput('string', {
type: StringSchema
});
}
execute() {
const { string, length, character, position } = this.getAllInputs();
let paddedString;
if (position === Position.START) {
paddedString = string.padStart(length, character[0]);
}
else {
paddedString = string.padEnd(length, character[0]);
}
this.outputs.string.set(paddedString);
}
}
//# sourceMappingURL=pad.js.map