From c475d39674a13bfc0ba2cd413541090fe7dda5c5 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sat, 22 Nov 2025 12:36:24 +0000 Subject: [PATCH] Iniital Toon node --- parsers/toon/LICENSE | 13 ++++++++ parsers/toon/README.md | 21 +++++++++++++ parsers/toon/icons/parser-toon.png | Bin 0 -> 1310 bytes parsers/toon/package.json | 26 ++++++++++++++++ parsers/toon/toon.html | 43 ++++++++++++++++++++++++++ parsers/toon/toon.js | 47 +++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 parsers/toon/LICENSE create mode 100644 parsers/toon/README.md create mode 100644 parsers/toon/icons/parser-toon.png create mode 100644 parsers/toon/package.json create mode 100644 parsers/toon/toon.html create mode 100644 parsers/toon/toon.js diff --git a/parsers/toon/LICENSE b/parsers/toon/LICENSE new file mode 100644 index 00000000..e025d780 --- /dev/null +++ b/parsers/toon/LICENSE @@ -0,0 +1,13 @@ +Copyright 2025 JS Foundation and other contributors, https://js.foundation/ + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/parsers/toon/README.md b/parsers/toon/README.md new file mode 100644 index 00000000..c0cf4315 --- /dev/null +++ b/parsers/toon/README.md @@ -0,0 +1,21 @@ +node-red-node-toon +==================== + +A Node-RED node to encode and decode objects to TOON format strings. + + +Install +------- + +Run the following command in your Node-RED user directory - typically `~/.node-red` + + npm i node-red-node-toon + +Usage +----- + +A function that converts the `msg.payload` object to and from TOON format. + +If the input is an object it converts it to a TOON encoded string. + +If the input is a TOON encoded string it tries to convert it back to an object. diff --git a/parsers/toon/icons/parser-toon.png b/parsers/toon/icons/parser-toon.png new file mode 100644 index 0000000000000000000000000000000000000000..d32f668b7294d8852a03fd22543e5b3837ef8c1d GIT binary patch literal 1310 zcmV+(1>yRMP)BE1ZQLxAY_vg;$?V;oX(lt{{G@3qJ`_O^!KmPq;Qw2}Cn0L9?Tam?khm;cmfj@-EE=vY<#k5o0f^m&*sM6pBI0EL{uRZtU4R5Z z`^X8`V)zNfJ8YaF;u6EP09P2E5Ad?jnUOMxUqvh^s*L``+lU9}BlcPZ2XpY-jyyG} zttleQMaed+noc9ry@UIIwng1*#M^^UkFzj+6yF25_LnMhmf?pGpH<}CbcnAmX|u%; z|7E#p3GpKUUAw%6atiT2#A8)^yd3Cssj4^8z$>TJnP(8+gLrkpJj%xIMEtceUz`ec zeo~wa<_{hK;NmJRuzL3+9o0iVC08s$)vACv7|KExH6jmbd4gn8^0FkllzkRT6fd|P0n zrwSVAXrbt(XrcJk;OyVRDf#{Yw^VBW$m{6QFhZvPBk<6w!tZERBfJcLd1$M3&)TehHS09YRtkN(Z(GDi^F2;vKBX;HY+Q*UEnTqUvgh@A9J5aYSek}G;8j! zqp=F+X_rylpF&#LEj%b>g+0Q~5^H*5N-?MwSLAe5T{?GXqX;9WfX;*4pXw6&V*io?m|<6;W0GAb4f<-njQ>$>Q>9MPr@ zwU=n+0I+*9IKpp9{{0u*d8K7@p9VPmCp-6AwmA>rtOL;dXv;Q$XXCx^0IWWyc=l3w zC&Xgk0yx!!!@*Zi8qcdA>-AfBZYACT*nGWS|NH%Vee(m<-vGFv{{#Oecnig2*2@3@ z061k>NoGw=04e|g00;m9hiL!=000010000Q0000000N)_00aO40096102H7D00aO4 z0096103HAU007&i%4Prn0EbCLK~zW$?NUJsz%U4F$NvB2tvLjOWR8vw#?XsKZ4BDh z%09P&u8NLfiW&D|S&e=0n}QYbt|U+bOf|$=kJb>st1wP;nCe{(x#bG42K_ic{jvF# zcpPHxX!>i_@% literal 0 HcmV?d00001 diff --git a/parsers/toon/package.json b/parsers/toon/package.json new file mode 100644 index 00000000..8b0558a5 --- /dev/null +++ b/parsers/toon/package.json @@ -0,0 +1,26 @@ +{ + "name" : "node-red-node-toon", + "version" : "1.0.0", + "description" : "A Node-RED node to encode and decode objects to TOON format strings", + "dependencies" : { + "@toon-format/toon": "^1.3.0" + }, + "bundledDependencies": [ "@toon-format/toon" ], + "repository" : { + "type":"git", + "url":"https://github.com/node-red/node-red-nodes.git", + "directory": "/tree/master/parsers/toon" + }, + "license": "Apache-2.0", + "keywords": [ "node-red", "toon" ], + "node-red" : { + "nodes" : { + "toon": "toon.js" + } + }, + "author": { + "name": "Dave Conway-Jones", + "email": "dceejay@gmail.com", + "url": "http://nodered.org" + } +} diff --git a/parsers/toon/toon.html b/parsers/toon/toon.html new file mode 100644 index 00000000..d5b81459 --- /dev/null +++ b/parsers/toon/toon.html @@ -0,0 +1,43 @@ + + + + + + diff --git a/parsers/toon/toon.js b/parsers/toon/toon.js new file mode 100644 index 00000000..24208f12 --- /dev/null +++ b/parsers/toon/toon.js @@ -0,0 +1,47 @@ + +module.exports = function(RED) { + "use strict"; + + const toonlib = require("@toon-format/toon") + + function ToonNode(n) { + RED.nodes.createNode(this,n); + this.property = n.property || "payload"; + var node = this; + + this.on("input", function(msg) { + var value = RED.util.getMessageProperty(msg,node.property); + if (value !== undefined) { + if (typeof(value) !== "string") { + // Take json object and make into a toon string + try { + value = toonlib.encode(value); + RED.util.setMessageProperty(msg,node.property,value); + node.send(msg); + } + catch(err) { + node.error("Failed to encode: "+err.message,msg); + } + } + else if (typeof value === "string") { + // Take toon string and make into json object + try { + value = toonlib.decode(value) + RED.util.setMessageProperty(msg,node.property,value) + node.send(msg) + } + catch(err) { + node.error("Invalid TOON string: "+err.message,msg); + } + } + else { + node.warn("Cannot handle this type of input"); + } + } + else { + node.warn("No property found to process"); + } + }); + } + RED.nodes.registerType("toon",ToonNode); +}