[{"data":1,"prerenderedAt":42},["ShallowReactive",2],{"integration-node-red-contrib-string\u002F":3},{"_id":4,"categories":5,"author":8,"description":11,"npmOwners":12,"npmScope":14,"name":4,"ffCertified":15,"downloads":16,"version":18,"updatedAt":19,"maintainers":20,"homepage":23,"bugs":24,"repository":26,"time":29,"lastUpdated":30,"created":31,"license":38,"githubOwner":39,"githubRepo":4,"examples":40,"readme":41},"node-red-contrib-string",[6,7],"catalogue_data-and-analytics","catalogue",{"name":9,"email":10},"Stephen J. Carnam","steveorevo@gmail.com","Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.",[13],"steveorevo",null,false,{"week":17},5850,"1.0.0","2020-10-22T19:55:39.211Z",[21],{"name":13,"email":22},"steve@steveorevo.com","https:\u002F\u002Fgithub.com\u002FSteveorevo\u002Fnode-red-contrib-string#readme",{"url":25},"https:\u002F\u002Fgithub.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fissues",{"type":27,"url":28},"git","git+https:\u002F\u002Fgithub.com\u002FSteveorevo\u002Fnode-red-contrib-string.git",{"modified":30,"created":31,"0.0.1":31,"0.1.1":32,"0.1.2":33,"0.2.0":34,"0.2.1":35,"0.2.2":36,"1.0.0":37},"2022-06-21T20:12:02.834Z","2017-10-02T06:21:27.987Z","2017-10-02T19:36:20.433Z","2017-10-05T06:44:40.664Z","2017-10-20T23:37:18.368Z","2017-12-25T04:48:02.140Z","2018-02-06T17:45:52.906Z","2020-10-22T19:55:37.015Z","MIT","Steveorevo",[],"\u003Ch1 id=\"node-red-contrib-string\">\u003Ca class=\"header-anchor\" href=\"#node-red-contrib-string\">node-red-contrib-string\u003C\u002Fa>\u003C\u002Fh1>\n\u003Cp>Provides a node with native and extended chainable JavaScript string parsing\nand manipulation methods. The node is a high level wrapper for the concise and\nlightweight \u003Ca href=\"http:\u002F\u002Fstringjs.com\">stringjs.com\u003C\u002Fa> object and uses Node-RED's editor UI to create easy\nchaining. Additional string parsing functionality and compatibility have been\nadded from the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FSteveorevo\u002Fstring.js\">fork\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Applies string methods from a given context property and assigns the results\noptionally to the same or another context property. Methods can be chained by\nadding multiple methods sequentially and with parameters that are literal or\nfrom other context properties. The string object always passes along the msg\nobject with (if any) changes applied.\u003C\u002Fp>\n\u003Cp>By default, string \"from\" and \"to\" apply to the \u003Ccode>msg.payload\u003C\u002Fcode> property but may\nbe set to any property of \u003Ccode>global\u003C\u002Fcode>, \u003Ccode>flow\u003C\u002Fcode>, or \u003Ccode>msg\u003C\u002Fcode> contexts.\u003C\u002Fp>\n\u003Ch2 id=\"examples\">\u003Ca class=\"header-anchor\" href=\"#examples\">Examples\u003C\u002Fa>\u003C\u002Fh2>\n\u003Ch4 id=\"data-extraction---get-technical-fax\">\u003Ca class=\"header-anchor\" href=\"#data-extraction---get-technical-fax\">Data Extraction - Get Technical FAX\u003C\u002Fa>\u003C\u002Fh4>\n\u003Cp>Methods can be chained within the UI enabling complex and versatile parsing\nfunctionality. Here we can see how easy it is to extract the technical FAX phone\nnumber WhoIS information:\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fmaster\u002F\u002Fstring\u002Fdemo\u002Fparsed-whois.png?raw=true\" alt=\"Node-RED Example\" title=\"Parse WhoIS for Technical FAX\" \u002F>\u003C\u002Fp>\n\u003Cp>Consider the given WhoIS dump from a command line console (see image below).\nWe will want to obtain the FAX number (outlined in the dashed yellow). The string\nnode will extract the technical FAX phone number by first removing the header,\nfollowed by all data up to the phrase \"Technical:\". This ensures that we don't\naccidentally obtain a FAX number from another section. Lastly, the string node\ngrabs the number from between the markers \"Fax:\" and a carriage return and\ndisplays the output in the Node-RED debug window.\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fmaster\u002F\u002Fstring\u002Fdemo\u002Ftechnical-fax.png?raw=true\" alt=\"WhoIS Commandline Dump\" title=\"Raw Commandline Dump from WhoIS\" \u002F>\u003C\u002Fp>\n\u003Cp>The extraction is performed using JavaScript's unique ability to chain actions on\na given object such as the native String object or the popular jQuery component.\nThis unique contribution to Node-RED furnishes a lightweight and enhanced version\nof string parsing functions. The visual representation in the first image could be\ncoded by hand in JavaScript (after including all the dependencies) as:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>console.log(\n  msg.payload.getRightMost('%')\n             .delLeftMost('Technical:')\n             .between('FAX:', '\\n')\n);\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch4 id=\"validate-phone-number\">\u003Ca class=\"header-anchor\" href=\"#validate-phone-number\">Validate Phone Number\u003C\u002Fa>\u003C\u002Fh4>\n\u003Cp>Furthermore, a single string node could have the properties set to perform data\nvalidation. In this simple example we'll perform some conditional checks to\nsee if the phone number is numeric and furnish a friendly error message if it is\nnot. Consider the following flow:\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fmaster\u002F\u002Fstring\u002Fdemo\u002Fvalidate-phone.png?raw=true\" alt=\"Validate Phone Number\" title=\"Validate Phone Number\" \u002F>\u003C\u002Fp>\n\u003Cp>Let's take a look at the string node titled \"Verify Number\" (see image below).\nThe properties for the node have been configured to use the methods\n\u003Ccode>stripPunctuation\u003C\u002Fcode> and \u003Ccode>isNumeric\u003C\u002Fcode> which will result in a boolean true or false.\nNext, we convert the boolean to a string using \u003Ccode>toString\u003C\u002Fcode>. Lastly, we use the\n\u003Ccode>replaceAll\u003C\u002Fcode> methods to convert the only two boolean possibilities to the\noriginal number as found in property msg.payload or the informative error message\n\u003Cem>\"Error! Not a valid number.\"\u003C\u002Fem>.\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fmaster\u002F\u002Fstring\u002Fdemo\u002Fvalidate-node-properties.png?raw=true\" alt=\"Verify Number Node\" title=\"Verify Number properties\" \u002F>\u003C\u002Fp>\n\u003Ch3 id=\"using-string-in-node-red-function-nodes\">\u003Ca class=\"header-anchor\" href=\"#using-string-in-node-red-function-nodes\">Using String in Node-RED Function Nodes\u003C\u002Fa>\u003C\u002Fh3>\n\u003Cp>You can use the string object's methods inside Node-RED's function nodes. The\ndependency string.js for Node.js will have already been installed if you included\nthe string node in your palette. This would allow you to use the parsing methods\nin JavaScript such as:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>  \u002F\u002F Always change the last word to World\n  var greet = S(\"Hello Mars\");\n  msg.payload = greet.delRightMost(\" \").append(\"World\");\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>There are several easy ways to make the string object's methods available in your\nJavaScript function nodes:\u003C\u002Fp>\n\u003Ch4 id=\"include-string-node-in-flow\">\u003Ca class=\"header-anchor\" href=\"#include-string-node-in-flow\">Include String Node in Flow\u003C\u002Fa>\u003C\u002Fh4>\n\u003Cp>A simple way is to just include the string node in your flow before the Node-RED\nfunction node. The string node will normally return a native JavaScript string\ndatatype; however, if you use the setValue method with no value, a string.js\nobject can be casted into a readily available property. In our example below we\ncast the object into \u003Ccode>msg.string\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002FSteveorevo\u002Fnode-red-contrib-string\u002Fmaster\u002F\u002Fstring\u002Fdemo\u002Fuse-in-function.png?raw=true\" alt=\"Using String in JavaScript\" title=\"Using String in JavaScript\" \u002F>\u003C\u002Fp>\n\u003Cp>The string object returns an instance of itself when using the setValue method.\nYou can then write JavaScript to instantiate a copy of the string object.\u003C\u002Fp>\n\u003Cpre>\u003Ccode>var S = function(x) {\n  return msg.string.setValue(x);\n}\nmsg.payload = S(\"Hello World\");\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch4 id=\"enable-require-in-node-red\">\u003Ca class=\"header-anchor\" href=\"#enable-require-in-node-red\">Enable Require in Node-RED\u003C\u002Fa>\u003C\u002Fh4>\n\u003Cp>An alternative method to use the string object is to enable the require method\nby updating Node-RED's settings.js to enable Node.js' \"require\" ability.\u003C\u002Fp>\n\u003Cp>https:\u002F\u002Fgithub.com\u002Fnode-red\u002Fnode-red\u002Fissues\u002F41#issuecomment-325554335\u003C\u002Fp>\n\u003Cpre>\u003Ccode>functionGlobalContext: {\n    require:require,\n    \u002F\u002F os:require('os'),\n    \u002F\u002F octalbonescript:require('octalbonescript'),\n    \u002F\u002F jfive:require(\"johnny-five\"),\n    \u002F\u002F j5board:require(\"johnny-five\").Board({repl:false})\n},\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>This will essentially give Node-RED's function node the ability to include any\narbitrary Node.js library which you may or may not desire. Likewise, you could\njust update Node-RED's settings.js to just enable the string.js library by\nmodifying the functionGlobalContext to read:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>functionGlobalContext: {\n    string:require(\"string\")\n},\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Your Node-RED's function node could then instantiate a string object like so:\u003C\u002Fp>\n\u003Cpre>\u003Ccode>var S = global.get(\"string\");\nmsg.payload = S(\"Hello World\");\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2 id=\"installation\">\u003Ca class=\"header-anchor\" href=\"#installation\">Installation\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>Run the following command in your Node-RED user directory (typically ~\u002F.node-red):\u003C\u002Fp>\n\u003Cpre>\u003Ccode>npm install node-red-contrib-string\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>The string node will appear in the palette under the function group.\u003C\u002Fp>\n",1784738654992]