mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-25 03:06:05 +10:00
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import { createNodeModule } from "../../nodeTypes.js";
|
|
|
|
/**
|
|
* Converts values to numbers using tonum.
|
|
*/
|
|
export const stringTonumNode = createNodeModule(
|
|
{
|
|
id: "string_tonum",
|
|
title: "To Number",
|
|
category: "Strings",
|
|
description: "Convert a value to a number with optional format flags.",
|
|
searchTags: ["tonum", "string", "number", "convert"],
|
|
inputs: [
|
|
{ id: "value", name: "Value", direction: "input", kind: "any" },
|
|
{
|
|
id: "flags",
|
|
name: "Flags",
|
|
direction: "input",
|
|
kind: "number",
|
|
description: "Optional format flags bitfield",
|
|
},
|
|
],
|
|
outputs: [
|
|
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
|
],
|
|
properties: [],
|
|
},
|
|
{
|
|
evaluateValue: ({ resolveValueInput }) => {
|
|
const OMIT = "__pg_omit__";
|
|
const value = resolveValueInput("value", "nil");
|
|
const flags = resolveValueInput("flags", OMIT);
|
|
if (flags === OMIT) {
|
|
return `tonum(${value})`;
|
|
}
|
|
return `tonum(${value}, ${flags})`;
|
|
},
|
|
}
|
|
);
|