mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 10:46:06 +10:00
Initial commit
moved from private version control
This commit is contained in:
48
scripts/nodes/library/strings/sub.js
Normal file
48
scripts/nodes/library/strings/sub.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Extracts substrings using sub.
|
||||
*/
|
||||
export const stringSubNode = createNodeModule(
|
||||
{
|
||||
id: "string_sub",
|
||||
title: "Substring",
|
||||
category: "Strings",
|
||||
description: "Extract a substring using SUB().",
|
||||
searchTags: ["sub", "substring", "string"],
|
||||
inputs: [
|
||||
{ id: "string", name: "String", direction: "input", kind: "string" },
|
||||
{
|
||||
id: "start",
|
||||
name: "Start",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
},
|
||||
{
|
||||
id: "stop",
|
||||
name: "Stop",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional end position or truthy for single character",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const str = resolveValueInput("string", "\"\"");
|
||||
const start = resolveValueInput("start", "1");
|
||||
const stop = resolveValueInput("stop", OMIT);
|
||||
|
||||
if (stop === OMIT) {
|
||||
return `sub(${str}, ${start})`;
|
||||
}
|
||||
|
||||
return `sub(${str}, ${start}, ${stop})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user