@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
32 lines • 1.06 kB
JavaScript
import { Node } from '../../programmatic/node.js';
import { NumberSchema, StringSchema } from '../../schemas/index.js';
import valueParser from 'postcss-value-parser-esm';
export default class NodeDefinition extends Node {
static title = 'Parse unit';
static type = 'studio.tokens.typing.parseUnit';
static description = 'Parse unit node allows you to seperate units from a number.';
constructor(props) {
super(props);
this.addInput('value', {
type: StringSchema
});
this.addOutput('unit', {
type: StringSchema
});
this.addOutput('number', {
type: NumberSchema
});
}
execute() {
const { value } = this.getAllInputs();
const x = valueParser.unit(value);
if (!x) {
this.outputs.number.set(0);
this.outputs.unit.set('');
return;
}
this.outputs.number.set(Number.parseFloat(x.number));
this.outputs.unit.set(x.unit);
}
}
//# sourceMappingURL=parseUnit.js.map