[ { "id": "a8a13f84-87cd-47f8-8b63-a311acc773d5", "inputs": { "type": "object", "properties": { "data": { "type": "any", "description": "The input data for the buffer operation. Can be a string, Buffer, or array depending on the operation.", "buildship": { "index": 0, "userPromptHint": "Enter the data to process. For 'concat', provide an array.", "basePrompt": "Data input for buffer operation.", "validationErrorMessage": "Data input is required." }, "title": "data" }, "operation": { "type": "string", "description": "The buffer operation to perform.", "buildship": { "index": 1, "options": [ { "label": "Encode", "value": "encode" }, { "label": "Decode", "value": "decode" }, { "label": "Base64 Encode", "value": "base64encode" }, { "label": "Base64 Decode", "value": "base64decode" }, { "label": "Hex", "value": "hex" }, { "label": "Concat", "value": "concat" } ], "userPromptHint": "Select the buffer operation to perform.", "basePrompt": "Operation type for buffer processing." }, "title": "operation" } }, "required": [ "data" ] }, "label": "Buffer Npm Usage Node", "output": { "title": "Buffer Operation Result", "description": "The result of performing the specified buffer operation on the input data.", "type": "string", "buildship": { "index": 0 } }, "script": "import {\n Buffer\n} from 'buffer';\n\nexport default async function bufferOperations({\n data,\n operation = 'encode'\n}: NodeInputs, {\n logging\n}: NodeScriptOptions) {\n try {\n if (!data) {\n throw new Error('Data input is required');\n }\n\n switch (operation.toLowerCase()) {\n case 'encode':\n // Convert string to Buffer\n return Buffer.from(data);\n\n case 'decode':\n // Convert Buffer to string\n if (Buffer.isBuffer(data)) {\n return data.toString();\n } else if (typeof data === 'string') {\n return Buffer.from(data).toString();\n } else {\n throw new Error('Cannot decode: Input must be a Buffer or string');\n }\n\n case 'base64encode':\n // Convert string to base64\n return Buffer.from(data).toString('base64');\n\n case 'base64decode':\n // Convert base64 to string\n return Buffer.from(data, 'base64').toString();\n\n case 'hex':\n // Convert to hex\n return Buffer.from(data).toString('hex');\n\n case 'concat':\n // Concat multiple buffers\n if (Array.isArray(data)) {\n const buffers = data.map(item =>\n Buffer.isBuffer(item) ? item : Buffer.from(String(item))\n );\n return Buffer.concat(buffers);\n } else {\n throw new Error('Concat operation requires an array input');\n }\n\n default:\n throw new Error(`Unsupported operation: ${operation}`);\n }\n } catch (error) {\n logging.error(`Buffer operation failed: ${error.message}`);\n throw error;\n }\n}", "type": "script", "meta": { "icon": { "type": "URL", "url": null }, "name": "Buffer Npm Usage Node", "id": "buffer-npm-usage-node", "description": "generate a node which uses Buffer npm\n" }, "values": {} } ]